aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dns.c34
-rw-r--r--src/dns.h2
2 files changed, 33 insertions, 3 deletions
diff --git a/src/dns.c b/src/dns.c
index 4ff2cb76..5c47aee5 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -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");
+ }
+ }
+}
diff --git a/src/dns.h b/src/dns.h
index 1749044f..fca28727 100644
--- a/src/dns.h
+++ b/src/dns.h
@@ -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
}