diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-05-02 20:18:21 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-05-02 20:18:21 +0000 |
commit | af08c4f878827928109a59a257cd6681bca7d68c (patch) | |
tree | 3ecdfa0edc8799499efe0ba6d03f9e3c469f2b2f /src/common | |
parent | a187d3e0b6329bd70b9823bd2d5489c8aaccf08e (diff) | |
download | tor-af08c4f878827928109a59a257cd6681bca7d68c.tar.gz tor-af08c4f878827928109a59a257cd6681bca7d68c.zip |
Working strerror for windows socket errors, plus some snide comments.
svn:r1775
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/tortls.c | 2 | ||||
-rw-r--r-- | src/common/util.c | 75 | ||||
-rw-r--r-- | src/common/util.h | 2 |
3 files changed, 77 insertions, 2 deletions
diff --git a/src/common/tortls.c b/src/common/tortls.c index e480f79e77..f4a81ed306 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -121,7 +121,7 @@ tor_tls_get_error(tor_tls *tls, int r, int extra, else { int e = tor_socket_errno(tls->socket); log(severity, "TLS error: <syscall error while %s> (errno=%d: %s)", - doing, e, strerror(e)); + doing, e, tor_socket_strerror(e)); } tls_log_errors(severity, doing); return TOR_TLS_ERROR; diff --git a/src/common/util.c b/src/common/util.c index f2c6cf7ad9..3ab2a9ae1c 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1111,6 +1111,79 @@ int tor_socket_errno(int sock) } #endif +/* There does not seem to be a strerror equivalent for winsock errors. + * Naturally, we have to roll our own. + */ +#ifdef MS_WINDOWS +#define E(code, s) { code, (s " [" #code " ]") } +struct { int code; char *msg; } windows_socket_errors = { + E(WSAEINTR, "Interrupted function call"), + E(WSAEACCES, "Permission denied"), + E(WSAEFAULT, "Bad address"), + E(WSAEINVAL, "Invalid argument"), + E(WSAEMFILE, "Too many open files"), + E(WSAEWOULDBLOCK, "Resource temporarily unavailable"), + E(WSAEINPROGRESS, "Operation now in progress"), + E(WSAEALREADY, "Operation already in progress"), + E(WSAENOTSOCK, "Socket operation on nonsocket"), + E(WSAEDESTADDRREQ, "Destination address required"), + E(WSAEMSGSIZE, "Message too long"), + E(WASEPROTOTYPE, "Protocol wrong for socket"), + E(WSAENOPROTOOPT, "Bad protocol option"), + E(WSAEPROTONOSUPPORT, "Protocol not supported"), + E(WSAESOCKTNOSUPPORT, "Socket type not supported"), + /* What's the difference between NOTSUPP and NOSUPPORT? :) */ + E(WASEOPNOTSUPP, "Operation not supported"), + E(WSAEPFNOSUPPORT, "Protocol family not supported"), + E(WSAEAFNOSUPPORT, "Address family not supported by protocol family"), + E(WSAEADDRINUSE, "Address already in use"), + E(WSAEADDRNOTAVAIL, "Cannot assign requested address"), + E(WSAENETDOWN, "Network is down"), + E(WSAENETUNREACH, "Network is unreachable"), + E(WSAENETRESET, "Network dropped connection on reset") + E(WSAECONNABORTED, "Software caused connection abort"), + E(WSAECONNRESET, "Connection reset by peer"), + E(WSAENOBUFS, "No buffer space avaialable"), + E(WSAEISCONN, "Socket is already connected"), + E(WSAENOTCONN, "Socket is not connected"), + E(WSAESHUTDOWN, "Cannot send after socket shutdown"), + E(WSAETIMEDOUT, "Connection timed out"), + E(WSAECONNREFUSED, "Connection refused"), + E(WSAEHOSTDOWN, "Host is down"), + E(WSAEHOSTUNREACH, "No route to host"), + E(WSAEPROCLIM, "Too many processes"), + /* Yes, some of these start with WSA, not WSAE. No, I don't know why. */ + E(WSASYSNOTREADY, "Network subsystem is unavailable"), + E(WSAVERNOTSUPPORTED, "Winsock.dll out of range"), + E(WSANOTINITIALISED, "Successful WSAStartup not yet performed"), + E(WSAEDISCONN, "Graceful shutdown no in progress"), + E(WSATYPE_NOT_FOUND, "Class type not found"), + E(WSAHOST_NOT_FOUND, "Host not found"), + E(WSATRY_AGAIN, "Nonauthoritative host not found"), + E(WSANO_RECOVERY, "This is a nonrecoverable error"), + E(WSANO_DATA, "Valid name, no data record of requested type)"), + + /* There are some more error codes whose numeric values are marked + * 'OS dependent'. They start with WSA_, apparently for the same + * reason that practitioners of some craft traditions deliberately + * introduce imperfections into their baskets and rugs "to allow the + * evil spirits to escape." If we catch them, then our binaries + * might not report consistent results across versions of Windows. + * Thus, I'm going to let them all fall through. + */ + { -1, NULL }, +}; +const char *tor_socket_strerror(int e) +{ + int i; + for (i=0; windows_socket_errors[i].code >= 0; ++i) { + if (e == windows_socket_errors[i].code) + return windows_socket_errors[i].msg; + } + return strerror(e); +} +#endif + /* * Filesystem operations. */ @@ -1476,7 +1549,7 @@ void write_pidfile(char *filename) { FILE *pidfile; if ((pidfile = fopen(filename, "w")) == NULL) { - log_fn(LOG_WARN, "unable to open %s for writing: %s", filename, + log_fn(LOG_WARN, "Unable to open %s for writing: %s", filename, strerror(errno)); } else { fprintf(pidfile, "%d\n", (int)getpid()); diff --git a/src/common/util.h b/src/common/util.h index 708c87fd28..1976e6ad54 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -250,11 +250,13 @@ int tor_lookup_hostname(const char *name, uint32_t *addr); #define ERRNO_IS_EINPROGRESS(e) ((e) == WSAEINPROGRESS) #define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == WSAEINPROGRESS || (e)== WSAEINVAL) int tor_socket_errno(int sock); +const char *tor_socket_strerror(int e); #else #define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN) #define ERRNO_IS_EINPROGRESS(e) ((e) == EINPROGRESS) #define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == EINPROGRESS) #define tor_socket_errno(sock) (errno) +#define tor_socket_strerror(e) strerror(e) #endif #endif |