diff options
-rw-r--r-- | src/common/compat.h | 13 | ||||
-rw-r--r-- | src/or/or.h | 13 | ||||
-rw-r--r-- | src/tools/tor-resolve.c | 34 |
3 files changed, 45 insertions, 15 deletions
diff --git a/src/common/compat.h b/src/common/compat.h index f21a208ed3..311818cb77 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -391,6 +391,19 @@ const char *tor_socket_strerror(int e); #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); diff --git a/src/or/or.h b/src/or/or.h index ce73d7719e..ab7e98d883 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -718,19 +718,6 @@ typedef enum { /** 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] diff --git a/src/tools/tor-resolve.c b/src/tools/tor-resolve.c index a73fe1503f..3c72a25a1e 100644 --- a/src/tools/tor-resolve.c +++ b/src/tools/tor-resolve.c @@ -137,6 +137,34 @@ parse_socks4a_resolve_response(const char *response, size_t len, 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 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport, 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) { |