diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-06-05 01:59:12 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-06-05 01:59:12 +0000 |
commit | b7ca697fafd1120f0257fca27508a6b687f6ab08 (patch) | |
tree | 48c351b81d6a3c24a3aaa2b46d89d16ae7d08b8e /src | |
parent | 3db785ef73d3a7cff0ebc7ba903116e5b3434cb2 (diff) | |
download | tor-b7ca697fafd1120f0257fca27508a6b687f6ab08.tar tor-b7ca697fafd1120f0257fca27508a6b687f6ab08.tar.gz |
More eventdns.c patches: use HAVE_ALLOCA_H; print IP addrs as dotted quads.
svn:r6535
Diffstat (limited to 'src')
-rw-r--r-- | src/or/eventdns.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/or/eventdns.c b/src/or/eventdns.c index c81fd2741..e955e541c 100644 --- a/src/or/eventdns.c +++ b/src/or/eventdns.c @@ -229,7 +229,9 @@ #include <stdlib.h> #include <string.h> #include <errno.h> +#ifdef HAVE_ALLOCA_H #include <alloca.h> +#endif #include <assert.h> #include <netinet/in.h> #include <arpa/inet.h> @@ -385,6 +387,21 @@ error_is_eagain(int sock) #define error_is_eagain(sock) (errno == EAGAIN) #endif +#ifndef NDEBUG +static const char * +debug_ntoa(u32 address) +{ + static char buf[32]; + u32 a = ntohl(address); + sprintf(buf, "%d.%d.%d.%d", + (int)(u8)((a>>24)&0xff), + (int)(u8)((a>>16)&0xff), + (int)(u8)((a>>8 )&0xff), + (int)(u8)((a )&0xff)); + return buf; +} +#endif + // This walks the list of inflight requests to find the // one with a matching transaction id. Returns NULL on // failure @@ -437,7 +454,7 @@ nameserver_failed(struct nameserver *const ns) { // then don't do anything if (!ns->state) return; - log("Nameserver %lx has failed\n", (unsigned long)ns->address); + log("Nameserver %s has failed\n", debug_ntoa(ns->address)); global_good_nameservers--; assert(global_good_nameservers >= 0); if (global_good_nameservers == 0) { @@ -475,7 +492,7 @@ nameserver_failed(struct nameserver *const ns) { static void nameserver_up(struct nameserver *const ns) { if (ns->state) return; - log("Nameserver %lx is back up\n", (unsigned long)ns->address); + log("Nameserver %s is back up\n", debug_ntoa(ns->address)); evtimer_del(&ns->timeout_event); ns->state = 1; ns->failed_times = 0; @@ -941,7 +958,7 @@ eventdns_request_data_build(const char *const name, const int name_len, const u1 APPEND16(0); // no authority APPEND16(0); // no additional - labels = (u8 *) alloca(name_len + 2); + labels = (u8 *) malloc(name_len + 2); labels_len = dnsname_to_labels(labels, name, name_len); if (labels_len < 0) return labels_len; memcpy(buf + j, labels, labels_len); @@ -1056,7 +1073,7 @@ nameserver_send_probe(struct nameserver *const ns) { // here we need to send a probe to a given nameserver // in the hope that it is up now. - log("Sending probe to %lx\n", (unsigned long)ns->address); + log("Sending probe to %s\n", debug_ntoa(ns->address)); req = request_new("www.google.com", DNS_QUERY_NO_SEARCH, nameserver_probe_callback, ns); // we force this into the inflight queue no matter what |