[or-cvs] r16657: {tor} commit jake's patch to include strings with socks5 error num (in tor/trunk/src: common or tools)

arma at seul.org arma at seul.org
Mon Aug 25 21:02:22 UTC 2008


Author: arma
Date: 2008-08-25 17:02:22 -0400 (Mon, 25 Aug 2008)
New Revision: 16657

Modified:
   tor/trunk/src/common/compat.h
   tor/trunk/src/or/or.h
   tor/trunk/src/tools/tor-resolve.c
Log:
commit jake's patch to include strings with socks5 error numbers


Modified: tor/trunk/src/common/compat.h
===================================================================
--- tor/trunk/src/common/compat.h	2008-08-25 16:21:28 UTC (rev 16656)
+++ tor/trunk/src/common/compat.h	2008-08-25 21:02:22 UTC (rev 16657)
@@ -391,6 +391,19 @@
 #define tor_socket_strerror(e)       strerror(e)
 #endif
 
+/** Specified SOCKS5 status codes. */
+typedef enum {
+  SOCKS5_SUCCEEDED                  = 0x00,
+  SOCKS5_GENERAL_ERROR              = 0x01,
+  SOCKS5_NOT_ALLOWED                = 0x02,
+  SOCKS5_NET_UNREACHABLE            = 0x03,
+  SOCKS5_HOST_UNREACHABLE           = 0x04,
+  SOCKS5_CONNECTION_REFUSED         = 0x05,
+  SOCKS5_TTL_EXPIRED                = 0x06,
+  SOCKS5_COMMAND_NOT_SUPPORTED      = 0x07,
+  SOCKS5_ADDRESS_TYPE_NOT_SUPPORTED = 0x08,
+} socks5_reply_status_t;
+
 /* ===== OS compatibility */
 const char *get_uname(void);
 

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2008-08-25 16:21:28 UTC (rev 16656)
+++ tor/trunk/src/or/or.h	2008-08-25 21:02:22 UTC (rev 16657)
@@ -718,19 +718,6 @@
 /** Number of bytes in a SOCKS4 header. */
 #define SOCKS4_NETWORK_LEN 8
 
-/** Specified SOCKS5 status codes. */
-typedef enum {
-  SOCKS5_SUCCEEDED                  = 0x00,
-  SOCKS5_GENERAL_ERROR              = 0x01,
-  SOCKS5_NOT_ALLOWED                = 0x02,
-  SOCKS5_NET_UNREACHABLE            = 0x03,
-  SOCKS5_HOST_UNREACHABLE           = 0x04,
-  SOCKS5_CONNECTION_REFUSED         = 0x05,
-  SOCKS5_TTL_EXPIRED                = 0x06,
-  SOCKS5_COMMAND_NOT_SUPPORTED      = 0x07,
-  SOCKS5_ADDRESS_TYPE_NOT_SUPPORTED = 0x08,
-} socks5_reply_status_t;
-
 /*
  * Relay payload:
  *         Relay command           [1 byte]

Modified: tor/trunk/src/tools/tor-resolve.c
===================================================================
--- tor/trunk/src/tools/tor-resolve.c	2008-08-25 16:21:28 UTC (rev 16656)
+++ tor/trunk/src/tools/tor-resolve.c	2008-08-25 21:02:22 UTC (rev 16657)
@@ -137,6 +137,34 @@
   return 0;
 }
 
+/* It would be nice to let someone know what SOCKS5 issue a user may have */
+const char *
+socks5_reason_to_string(char reason)
+{
+    switch(reason){
+      case SOCKS5_SUCCEEDED:
+        return "succeeded";
+      case SOCKS5_GENERAL_ERROR:
+        return "general error";
+      case SOCKS5_NOT_ALLOWED:
+        return "not allowed";
+      case SOCKS5_NET_UNREACHABLE:
+        return "network is unreachable";
+      case SOCKS5_HOST_UNREACHABLE:
+        return "host is unreachable";
+      case SOCKS5_CONNECTION_REFUSED:
+        return "connection refused";
+      case SOCKS5_TTL_EXPIRED:
+        return "ttl explired";
+      case SOCKS5_COMMAND_NOT_SUPPORTED:
+        return "command not supported";
+      case SOCKS5_ADDRESS_TYPE_NOT_SUPPORTED:
+        return "address type not supported";
+      default:
+        return "unknown SOCKS5 code.";
+    }
+}
+
 /** Send a resolve request for <b>hostname</b> to the Tor listening on
  * <b>sockshost</b>:<b>socksport</b>.  Store the resulting IPv4
  * address (in host order) into *<b>result_addr</b>.
@@ -228,9 +256,11 @@
       log_err(LD_NET, "Bad SOCKS5 reply version.");
       return -1;
     }
+    /* Give a user some useful feedback about SOCKS5 errors */
     if (reply_buf[1] != 0) {
-      log_warn(LD_NET,"Got status response '%u': SOCKS5 request failed.",
-               (unsigned)reply_buf[1]);
+      log_warn(LD_NET,"Got SOCKS5 status response '%u': %s",
+               (unsigned)reply_buf[1],
+               socks5_reason_to_string(reply_buf[1]));
       return -1;
     }
     if (reply_buf[3] == 1) {



More information about the tor-commits mailing list