diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-11-14 22:20:18 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-11-14 23:16:57 -0500 |
commit | 053f2cb7c89a4f6b52fa601f83f798d45ab8eca4 (patch) | |
tree | 5119094fee91221235e99fcd777e327a392ca3fc | |
parent | 50af1087c4e92dfb4a30ddce4f6046970d6108e2 (diff) | |
download | tor-053f2cb7c89a4f6b52fa601f83f798d45ab8eca4.tar.gz tor-053f2cb7c89a4f6b52fa601f83f798d45ab8eca4.zip |
Let tor-resolve generate PTR requests for IPv6 addresses
-rw-r--r-- | src/or/dnsserv.c | 1 | ||||
-rw-r--r-- | src/tools/tor-resolve.c | 16 |
2 files changed, 12 insertions, 5 deletions
diff --git a/src/or/dnsserv.c b/src/or/dnsserv.c index 5875d96b8b..f5d430bf38 100644 --- a/src/or/dnsserv.c +++ b/src/or/dnsserv.c @@ -89,6 +89,7 @@ evdns_server_callback(struct evdns_server_request *req, void *data_) continue; switch (req->questions[i]->type) { case EVDNS_TYPE_A: + case EVDNS_TYPE_AAAA: case EVDNS_TYPE_PTR: q = req->questions[i]; default: diff --git a/src/tools/tor-resolve.c b/src/tools/tor-resolve.c index 19a67fc0d6..cae5fbbbb4 100644 --- a/src/tools/tor-resolve.c +++ b/src/tools/tor-resolve.c @@ -74,23 +74,29 @@ build_socks_resolve_request(char **out, memcpy((*out)+8+strlen(username)+1, hostname, strlen(hostname)+1); } else if (version == 5) { int is_ip_address; - struct in_addr in; + tor_addr_t addr; size_t addrlen; - is_ip_address = tor_inet_aton(hostname, &in); + int ipv6; + is_ip_address = tor_addr_parse(&addr, hostname) != -1; if (!is_ip_address && reverse) { log_err(LD_GENERAL, "Tried to do a reverse lookup on a non-IP!"); return -1; } - addrlen = reverse ? 4 : 1 + strlen(hostname); + ipv6 = reverse && tor_addr_family(&addr) == AF_INET6; + addrlen = reverse ? (ipv6 ? 16 : 4) : 1 + strlen(hostname); len = 6 + addrlen; *out = tor_malloc(len); (*out)[0] = 5; /* SOCKS version 5 */ (*out)[1] = reverse ? '\xF1' : '\xF0'; /* RESOLVE_PTR or RESOLVE */ (*out)[2] = 0; /* reserved. */ - (*out)[3] = reverse ? 1 : 3; if (reverse) { - set_uint32((*out)+4, in.s_addr); + (*out)[3] = ipv6 ? 4 : 1; + if (ipv6) + memcpy((*out)+4, tor_addr_to_in6_addr8(&addr), 16); + else + set_uint32((*out)+4, tor_addr_to_ipv4n(&addr)); } else { + (*out)[3] = 3; (*out)[4] = (char)(uint8_t)(addrlen - 1); memcpy((*out)+5, hostname, addrlen - 1); } |