aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-05-02 20:18:21 +0000
committerNick Mathewson <nickm@torproject.org>2004-05-02 20:18:21 +0000
commitaf08c4f878827928109a59a257cd6681bca7d68c (patch)
tree3ecdfa0edc8799499efe0ba6d03f9e3c469f2b2f
parenta187d3e0b6329bd70b9823bd2d5489c8aaccf08e (diff)
downloadtor-af08c4f878827928109a59a257cd6681bca7d68c.tar.gz
tor-af08c4f878827928109a59a257cd6681bca7d68c.zip
Working strerror for windows socket errors, plus some snide comments.
svn:r1775
-rw-r--r--src/common/tortls.c2
-rw-r--r--src/common/util.c75
-rw-r--r--src/common/util.h2
-rw-r--r--src/or/connection.c6
-rw-r--r--src/or/connection_edge.c3
-rw-r--r--src/or/cpuworker.c3
-rw-r--r--src/or/dns.c3
-rw-r--r--src/or/main.c3
8 files changed, 88 insertions, 9 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
diff --git a/src/or/connection.c b/src/or/connection.c
index 6f69799cd2..9b3100e0f4 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -279,13 +279,13 @@ int connection_create_listener(char *bindaddress, uint16_t bindport, int type) {
if(bind(s,(struct sockaddr *)&bindaddr,sizeof(bindaddr)) < 0) {
log_fn(LOG_WARN,"Could not bind to port %u: %s",bindport,
- strerror(tor_socket_errno(s)));
+ tor_socket_strerror(tor_socket_errno(s)));
return -1;
}
if(listen(s,SOMAXCONN) < 0) {
log_fn(LOG_WARN,"Could not listen on port %u: %s",bindport,
- strerror(tor_socket_errno(s)));
+ tor_socket_strerror(tor_socket_errno(s)));
return -1;
}
@@ -392,7 +392,7 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_
if(!ERRNO_IS_CONN_EINPROGRESS(tor_socket_errno(s))) {
/* yuck. kill it. */
log_fn(LOG_INFO,"Connect() to %s:%u failed: %s",address,port,
- strerror(tor_socket_errno(s)));
+ tor_socket_strerror(tor_socket_errno(s)));
tor_close_socket(s);
return -1;
} else {
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 7a9bdfd0a3..d4dd2d42ea 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -1067,7 +1067,8 @@ int connection_ap_make_bridge(char *address, uint16_t port) {
log_fn(LOG_INFO,"Making AP bridge to %s:%d ...",address,port);
if(tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
- log(LOG_WARN, "Couldn't construct socketpair (%s). Network down? Delaying.", strerror(errno));
+ log(LOG_WARN,"Couldn't construct socketpair (%s). Network down? Delaying.",
+ tor_socket_strerror(tor_socket_errno(-1)));
return -1;
}
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index fb5a9d85a7..92a0ed8881 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -214,7 +214,8 @@ static int spawn_cpuworker(void) {
connection_t *conn;
if(tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
- log(LOG_ERR, "Couldn't construct socketpair: %s", strerror(errno));
+ log(LOG_ERR, "Couldn't construct socketpair: %s",
+ tor_socket_strerror(tor_socket_errno(-1)));
exit(1);
}
diff --git a/src/or/dns.c b/src/or/dns.c
index 2cb4cb6182..18cfea3248 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -503,7 +503,8 @@ static int spawn_dnsworker(void) {
connection_t *conn;
if(tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
- log(LOG_ERR, "Couldn't construct socketpair: %s", strerror(errno));
+ log(LOG_ERR, "Couldn't construct socketpair: %s",
+ tor_socket_strerror(tor_socket_errno(-1)));
exit(1);
}
diff --git a/src/or/main.c b/src/or/main.c
index 836f4d665b..cc3789e85c 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -656,7 +656,8 @@ static int do_main_loop(void) {
/* let the program survive things like ^z */
if(tor_socket_errno(-1) != EINTR) {
log_fn(LOG_ERR,"poll failed: %s [%d]",
- strerror(tor_socket_errno(-1)), tor_socket_errno(-1));
+ tor_socket_strerror(tor_socket_errno(-1)),
+ tor_socket_errno(-1));
return -1;
} else {
log_fn(LOG_DEBUG,"poll interrupted.");