diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-08-05 20:08:19 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-08-05 20:08:19 +0000 |
commit | 960a0f0a994ba23480e14ffe5179160194fd9616 (patch) | |
tree | 250494775699fda2f0f543a350b02e89c5a77a03 /src/or/dnsserv.c | |
parent | 750bb795ac1fcb5b76b6488690400c77fbff0a3f (diff) | |
download | tor-960a0f0a994ba23480e14ffe5179160194fd9616.tar.gz tor-960a0f0a994ba23480e14ffe5179160194fd9616.zip |
r17641@31-33-44: nickm | 2008-08-05 16:07:53 -0400
Initial conversion of uint32_t addr to tor_addr_t addr in connection_t and related types. Most of the Tor wire formats using these new types are in, but the code to generate and use it is not. This is a big patch. Let me know what it breaks for you.
svn:r16435
Diffstat (limited to 'src/or/dnsserv.c')
-rw-r--r-- | src/or/dnsserv.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/or/dnsserv.c b/src/or/dnsserv.c index 18623f6a49..5a1c023834 100644 --- a/src/or/dnsserv.c +++ b/src/or/dnsserv.c @@ -25,9 +25,9 @@ evdns_server_callback(struct evdns_server_request *req, void *_data) struct evdns_server_question *q = NULL; struct sockaddr_storage addr; struct sockaddr *sa; - struct sockaddr_in *sin; int addrlen; - uint32_t ipaddr; + tor_addr_t tor_addr; + uint16_t port; int err = DNS_ERR_NONE; char *q_name; @@ -46,22 +46,24 @@ evdns_server_callback(struct evdns_server_request *req, void *_data) } (void) addrlen; sa = (struct sockaddr*) &addr; - if (sa->sa_family != AF_INET) { - /* XXXX_IP6 Handle IPV6 */ - log_warn(LD_APP, "Requesting address wasn't ipv4."); + if (tor_addr_from_sockaddr(&tor_addr, sa)<0) { + log_warn(LD_APP, "Requesting address wasn't recognized."); evdns_server_request_respond(req, DNS_ERR_SERVERFAILED); return; - } else { - sin = (struct sockaddr_in*)&addr; - ipaddr = ntohl(sin->sin_addr.s_addr); } - if (!socks_policy_permits_address(ipaddr)) { + if (!socks_policy_permits_address(&tor_addr)) { log_warn(LD_APP, "Rejecting DNS request from disallowed IP."); evdns_server_request_respond(req, DNS_ERR_REFUSED); return; } + if (sa->sa_family == AF_INET) + port = ((struct sockaddr_in *)sa)->sin_port; + else + port = ((struct sockaddr_in6 *)sa)->sin6_port; + port = ntohs(port); + /* Now, let's find the first actual question of a type we can answer in this * DNS request. It makes us a little noncompliant to act like this; we * should fix that eventually if it turns out to make a difference for @@ -116,9 +118,9 @@ evdns_server_callback(struct evdns_server_request *req, void *_data) conn->_base.state = AP_CONN_STATE_RESOLVE_WAIT; conn->is_dns_request = 1; - TO_CONN(conn)->addr = ntohl(sin->sin_addr.s_addr); - TO_CONN(conn)->port = ntohs(sin->sin_port); - TO_CONN(conn)->address = tor_dup_ip(TO_CONN(conn)->addr); + tor_addr_copy(&TO_CONN(conn)->addr, &tor_addr); + TO_CONN(conn)->port = port; + TO_CONN(conn)->address = tor_dup_addr(&tor_addr); if (q->type == EVDNS_TYPE_A) conn->socks_request->command = SOCKS_COMMAND_RESOLVE; |