changeset 447:ba84335ff775

- Made the DNS resolver report in numeric address notation.
author jcid
date Sun, 09 Nov 2008 14:09:09 +0100
parents 1b0dabe4afa2
children cea1e7304278
files ChangeLog src/dns.c src/dns.h
diffstat 3 files changed, 35 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Nov 09 13:17:56 2008 +0100
+++ b/ChangeLog	Sun Nov 09 14:09:09 2008 +0100
@@ -23,6 +23,8 @@
 +- Allowed compilation with older machines by removing a few C99isms.
  - Added use of inttypes.h when stdint.h isn't found.
    Patches: Dan Fandrich
++- Made the DNS resolver report in numeric address notation.
+   Patch: Justus Winter
 +- Reduced warnings with gcc-4.3.
    Patch: Thomas Orgis
 +- Added the "middle_click_drags_page" dillorc option.
--- a/src/dns.c	Sun Nov 09 13:17:56 2008 +0100
+++ b/src/dns.c	Sun Nov 09 14:09:09 2008 +0100
@@ -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 @@
    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 @@
    }
 
    /* 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 @@
    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");
+      }
+   }
+}
--- a/src/dns.h	Sun Nov 09 13:17:56 2008 +0100
+++ b/src/dns.h	Sun Nov 09 14:09:09 2008 +0100
@@ -22,7 +22,7 @@
   int alen;
   char data[DILLO_ADDR_MAX];
 } DilloHost;
-
+void a_Dns_dillohost_to_string(DilloHost *host, char *dst, size_t size);
 
 #ifdef __cplusplus
 }