diff options
author | jcid <devnull@localhost> | 2008-11-09 14:09:09 +0100 |
---|---|---|
committer | jcid <devnull@localhost> | 2008-11-09 14:09:09 +0100 |
commit | 1685afb2c6fc9570dc841ff5f5099cec9124252b (patch) | |
tree | ac688482819a8f0b14e7c14ae93bf358c6cae28c /src | |
parent | 7ae4abd9c6779fd721fc5a012cddb94493ea97d9 (diff) |
- Made the DNS resolver report in numeric address notation.
Diffstat (limited to 'src')
-rw-r--r-- | src/dns.c | 34 | ||||
-rw-r--r-- | src/dns.h | 2 |
2 files changed, 33 insertions, 3 deletions
@@ -18,6 +18,7 @@ #include <netdb.h> #include <sys/types.h> #include <sys/socket.h> +#include <arpa/inet.h> #include <netinet/in.h> #include <errno.h> #include <unistd.h> @@ -268,6 +269,8 @@ static void *Dns_server(void *data) struct addrinfo hints, *res0; int error; Dlist *hosts; + size_t length, i; + char addr_string[40]; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; @@ -307,8 +310,18 @@ static void *Dns_server(void *data) } /* tell our findings */ - MSG("Dns_server [%d]: %s is %p\n", channel, - dns_server[channel].hostname, hosts); + MSG("Dns_server [%d]: %s is", channel, + dns_server[channel].hostname); + if ((length = dList_length(hosts))) { + for (i = 0; i < length; i++) { + a_Dns_dillohost_to_string(dList_nth_data(hosts, i), + addr_string, sizeof(addr_string)); + MSG(" %s", addr_string); + } + MSG("\n"); + } else { + MSG(" (nil)\n"); + } dns_server[channel].addr_list = hosts; dns_server[channel].ip_ready = TRUE; @@ -482,3 +495,20 @@ void a_Dns_freeall(void) dFree(dns_cache); } +/* + * Writes a string representation of the given DilloHost + * into dst. dst will be \0 terminated. + * Please note that dst must be at least 40 bytes long for IPv6 + * addresses. + */ +void a_Dns_dillohost_to_string(DilloHost *host, char *dst, size_t size) +{ + if (!inet_ntop(host->af, host->data, dst, size)) { + switch (errno) { + case EAFNOSUPPORT: + snprintf(dst, size, "Unknown address family"); + case ENOSPC: + snprintf(dst, size, "Buffer too small"); + } + } +} @@ -22,7 +22,7 @@ typedef struct _DilloHost int alen; char data[DILLO_ADDR_MAX]; } DilloHost; - +void a_Dns_dillohost_to_string(DilloHost *host, char *dst, size_t size); #ifdef __cplusplus } |