Document the new Copy Profile button.
[obnox/wireshark/wip.git] / epan / addr_resolv.c
index 890ded778b0d60b149cd64a859052d19630df7e5..b152cfef926d6ace024e8383d7d9a13c0276d87d 100644 (file)
 #include <signal.h>
 
 #ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>                /* needed to define AF_ values on UNIX */
+#include <sys/socket.h>     /* needed to define AF_ values on UNIX */
 #endif
 
 #ifdef HAVE_WINSOCK2_H
-#include <winsock2.h>          /* needed to define AF_ values on Windows */
-#endif
-
-#ifdef AVOID_DNS_TIMEOUT
-# include <setjmp.h>
+#include <winsock2.h>       /* needed to define AF_ values on Windows */
 #endif
 
 #ifdef NEED_INET_ATON_H
 #  if defined(inet_aton) && defined(_WIN32)
 #   undef inet_aton
 #  endif
-# endif        /* HAVE_GNU_ADNS */
-#endif /* HAVE_C_ARES */
+# endif /* HAVE_GNU_ADNS */
+#endif  /* HAVE_C_ARES */
 
 
 #include <glib.h>
 #include <epan/prefs.h>
 #include <epan/emem.h>
 
-#define ENAME_HOSTS            "hosts"
-#define ENAME_SUBNETS  "subnets"
-#define ENAME_ETHERS           "ethers"
-#define ENAME_IPXNETS          "ipxnets"
-#define ENAME_MANUF            "manuf"
-#define ENAME_SERVICES "services"
-
-#define MAXMANUFLEN    9       /* max vendor name length with ending '\0' */
-#define HASHETHSIZE    1024
-#define HASHHOSTSIZE   1024
-#define HASHIPXNETSIZE 256
+#define ENAME_HOSTS     "hosts"
+#define ENAME_SUBNETS   "subnets"
+#define ENAME_ETHERS    "ethers"
+#define ENAME_IPXNETS   "ipxnets"
+#define ENAME_MANUF     "manuf"
+#define ENAME_SERVICES  "services"
+
+#define MAXMANUFLEN 9   /* max vendor name length with ending '\0' */
+#define HASHETHSIZE            2048
+#define HASHHOSTSIZE    2048
+#define HASHIPXNETSIZE  256
 #define HASHMANUFSIZE   256
-#define HASHPORTSIZE   256
+#define HASHPORTSIZE    256
 #define SUBNETLENGTHSIZE 32 /*1-32 inc.*/
 
 /* hash table used for IPv4 lookup */
 #define HASH_IPV4_ADDRESS(addr) (g_htonl(addr) & (HASHHOSTSIZE - 1))
 
 typedef struct hashipv4 {
-  guint                                addr;
-  gboolean          is_dummy_entry;    /* name is IPv4 address in dot format */
+  guint             addr;
+  gboolean          is_dummy_entry; /* name is IPv4 address in dot format */
   gboolean          resolve;       /* already tried to resolve it */
-  struct hashipv4      *next;
-  gchar                                ip[16];
-  gchar                        name[MAXNAMELEN];
+  struct hashipv4   *next;
+  gchar             ip[16];
+  gchar             name[MAXNAMELEN];
 } hashipv4_t;
 
 /* hash table used for IPv6 lookup */
 
-#define HASH_IPV6_ADDRESS(addr)        \
-       ((((addr).bytes[14] << 8)|((addr).bytes[15])) & (HASHHOSTSIZE - 1))
+#define HASH_IPV6_ADDRESS(addr) \
+    ((((addr).bytes[14] << 8)|((addr).bytes[15])) & (HASHHOSTSIZE - 1))
 
 typedef struct hashipv6 {
-  struct e_in6_addr    addr;
-  gboolean          is_dummy_entry;    /* name is IPv6 address in colon format */
+  struct e_in6_addr addr;
+  gboolean          is_dummy_entry; /* name is IPv6 address in colon format */
   gboolean          resolve;       /* */
-  struct hashipv6      *next;
+  struct hashipv6   *next;
   gchar             ip6[47];  /* XX */
-  gchar                        name[MAXNAMELEN];
+  gchar             name[MAXNAMELEN];
 } hashipv6_t;
 
 /* Array of entries of subnets of different lengths */
@@ -186,86 +182,86 @@ typedef struct {
 
 /* hash table used for TCP/UDP/SCTP port lookup */
 
-#define HASH_PORT(port)        ((port) & (HASHPORTSIZE - 1))
+#define HASH_PORT(port) ((port) & (HASHPORTSIZE - 1))
 
 typedef struct hashport {
-  guint16              port;
-  struct hashport      *next;
-  gchar                name[MAXNAMELEN];
+  guint16       port;
+  struct hashport   *next;
+  gchar         name[MAXNAMELEN];
 } hashport_t;
 
 /* hash table used for IPX network lookup */
 
 /* XXX - check goodness of hash function */
 
-#define HASH_IPX_NET(net)      ((net) & (HASHIPXNETSIZE - 1))
+#define HASH_IPX_NET(net)   ((net) & (HASHIPXNETSIZE - 1))
 
 typedef struct hashipxnet {
-  guint                        addr;
-  struct hashipxnet    *next;
-  gchar                name[MAXNAMELEN];
+  guint         addr;
+  struct hashipxnet     *next;
+  gchar         name[MAXNAMELEN];
 } hashipxnet_t;
 
 /* hash tables used for ethernet and manufacturer lookup */
 
 #define HASH_ETH_ADDRESS(addr) \
-       (((((addr)[2] << 8) | (addr)[3]) ^ (((addr)[4] << 8) | (addr)[5])) & \
-        (HASHETHSIZE - 1))
+    (((((addr)[2] << 8) | (addr)[3]) ^ (((addr)[4] << 8) | (addr)[5])) & \
+     (HASHETHSIZE - 1))
 
 #define HASH_ETH_MANUF(addr) (((int)(addr)[2]) & (HASHMANUFSIZE - 1))
 
 typedef struct hashmanuf {
-  guint8               addr[3];
-  struct hashmanuf             *next;
-  char                         name[MAXMANUFLEN];
+  guint8        addr[3];
+  struct hashmanuf      *next;
+  char          name[MAXMANUFLEN];
 } hashmanuf_t;
 
 typedef struct hashether {
-  guint8                               addr[6];
-  gboolean                             is_dummy_entry;         /* not a complete entry */
-  gboolean              resolve;                       /* */
-  struct hashether             *next;
+  guint8                addr[6];
+  gboolean              is_dummy_entry;     /* not a complete entry */
+  gboolean              resolve;            /* */
+  struct hashether      *next;
   char                  hexa[6*3];
-  char                                         name[MAXNAMELEN];
+  char                  name[MAXNAMELEN];
 } hashether_t;
 
 /* internal ethernet type */
 
 typedef struct _ether
 {
-  guint8               addr[6];
-  char                         name[MAXNAMELEN];
+  guint8        addr[6];
+  char          name[MAXNAMELEN];
 } ether_t;
 
 /* internal ipxnet type */
 
 typedef struct _ipxnet
 {
-  guint                        addr;
-  char                         name[MAXNAMELEN];
+  guint         addr;
+  char          name[MAXNAMELEN];
 } ipxnet_t;
 
-static hashipv4_t      *ipv4_table[HASHHOSTSIZE];
-static hashipv6_t      *ipv6_table[HASHHOSTSIZE];
+static hashipv4_t   *ipv4_table[HASHHOSTSIZE];
+static hashipv6_t   *ipv6_table[HASHHOSTSIZE];
 
-static hashport_t      **cb_port_table;
-static gchar           *cb_service;
+static hashport_t   **cb_port_table;
+static gchar        *cb_service;
 
-static hashport_t      *udp_port_table[HASHPORTSIZE];
-static hashport_t      *tcp_port_table[HASHPORTSIZE];
-static hashport_t      *sctp_port_table[HASHPORTSIZE];
-static hashport_t      *dccp_port_table[HASHPORTSIZE];
-static hashether_t     *eth_table[HASHETHSIZE];
-static hashmanuf_t     *manuf_table[HASHMANUFSIZE];
-static hashether_t     *(*wka_table[48])[HASHETHSIZE];
-static hashipxnet_t    *ipxnet_table[HASHIPXNETSIZE];
+static hashport_t   *udp_port_table[HASHPORTSIZE];
+static hashport_t   *tcp_port_table[HASHPORTSIZE];
+static hashport_t   *sctp_port_table[HASHPORTSIZE];
+static hashport_t   *dccp_port_table[HASHPORTSIZE];
+static hashether_t  *eth_table[HASHETHSIZE];
+static hashmanuf_t  *manuf_table[HASHMANUFSIZE];
+static hashether_t  *(*wka_table[48])[HASHETHSIZE];
+static hashipxnet_t *ipxnet_table[HASHIPXNETSIZE];
 
 static subnet_length_entry_t subnet_length_entries[SUBNETLENGTHSIZE]; /* Ordered array of entries */
 static gboolean have_subnet_entry = FALSE;
 
-static int             eth_resolution_initialized = 0;
-static int             ipxnet_resolution_initialized = 0;
-static int             service_resolution_initialized = 0;
+static int      eth_resolution_initialized = 0;
+static int      ipxnet_resolution_initialized = 0;
+static int      service_resolution_initialized = 0;
 
 static hashether_t *add_eth_name(const guint8 *addr, const gchar *name);
 static void add_serv_port_cb(guint32 port);
@@ -281,13 +277,13 @@ guint32 g_resolv_flags;
  *  GUI code to change them.
  */
 
-gchar *g_ethers_path  = NULL;          /* global ethers file    */
-gchar *g_pethers_path = NULL;          /* personal ethers file  */
-gchar *g_ipxnets_path  = NULL;         /* global ipxnets file   */
-gchar *g_pipxnets_path = NULL;         /* personal ipxnets file */
-gchar *g_services_path  = NULL;                /* global services file   */
-gchar *g_pservices_path = NULL;                /* personal services file */
-                                       /* first resolving call  */
+gchar *g_ethers_path  = NULL;       /* global ethers file    */
+gchar *g_pethers_path = NULL;       /* personal ethers file  */
+gchar *g_ipxnets_path  = NULL;      /* global ipxnets file   */
+gchar *g_pipxnets_path = NULL;      /* personal ipxnets file */
+gchar *g_services_path  = NULL;     /* global services file   */
+gchar *g_pservices_path = NULL;     /* personal services file */
+                    /* first resolving call  */
 
 /* c-ares */
 #ifdef HAVE_C_ARES
@@ -298,20 +294,17 @@ gchar *g_pservices_path = NULL;           /* personal services file */
  * ares_gethostbyaddr().
  * The callback processes the response, then frees the request.
  */
-
-static gboolean c_ares_initialized = FALSE;
+#define ASYNC_DNS
 ares_channel alchan;
-int c_ares_in_flight = 0;
-GList *c_ares_queue_head = NULL;
 
-typedef struct _c_ares_queue_msg
+typedef struct _async_dns_queue_msg
 {
   union {
     guint32           ip4;
     struct e_in6_addr ip6;
   } addr;
   int                 family;
-} c_ares_queue_msg_t;
+} async_dns_queue_msg_t;
 
 #if ( ( ARES_VERSION_MAJOR < 1 )                                     \
  || ( 1 == ARES_VERSION_MAJOR && ARES_VERSION_MINOR < 5 ) )
@@ -323,7 +316,7 @@ static void c_ares_ghba_cb(void *arg, int status, int timeouts _U_, struct hoste
 #else
 /* GNU ADNS */
 #ifdef HAVE_GNU_ADNS
-
+#define ASYNC_DNS
 /*
  * Submitted queries have to be checked individually using adns_check().
  * Queries are added to adns_queue_head. During processing, the list is
@@ -331,21 +324,42 @@ static void c_ares_ghba_cb(void *arg, int status, int timeouts _U_, struct hoste
  * and once to check the status of each query.
  */
 
-static gboolean gnu_adns_initialized = FALSE;
 adns_state ads;
-int adns_in_flight = 0;
-GList *adns_queue_head = NULL;
 
-typedef struct _adns_queue_msg
+typedef struct _async_dns_queue_msg
 {
   gboolean          submitted;
   guint32           ip4_addr;
   int               type;
   adns_query        query;
-} adns_queue_msg_t;
+} async_dns_queue_msg_t;
 
 #endif /* HAVE_GNU_ADNS */
 #endif /* HAVE_C_ARES */
+#ifdef ASYNC_DNS
+static         gboolean async_dns_initialized = FALSE;
+static  int     async_dns_in_flight = 0;
+static  GList  *async_dns_queue_head = NULL;
+
+/* push a dns request */
+static void
+add_async_dns_ipv4(int type, guint32 addr)
+{
+    async_dns_queue_msg_t *msg;
+
+    msg = g_malloc(sizeof(async_dns_queue_msg_t));
+#ifdef HAVE_C_ARES
+    msg->family = type;
+    msg->addr.ip4 = addr;
+#else
+    msg->type = type;
+    msg->ip4_addr = addr;
+    msg->submitted = FALSE;
+#endif
+    async_dns_queue_head = g_list_append(async_dns_queue_head, (gpointer) msg);
+}
+
+#endif
 
 typedef struct {
     guint32 mask;
@@ -362,25 +376,26 @@ static int fgetline(char **buf, int *size, FILE *fp)
   int len;
   int c;
 
-  if (fp == NULL)
+  if (fp == NULL || buf == NULL)
     return -1;
 
   if (*buf == NULL) {
     if (*size == 0)
       *size = BUFSIZ;
 
-       if ((*buf = g_malloc(*size)) == NULL)
-               return -1;
+     *buf = g_malloc(*size);
   }
 
+  g_assert(*buf);
+  g_assert(*size > 0);
+
   if (feof(fp))
     return -1;
 
   len = 0;
   while ((c = getc(fp)) != EOF && c != '\r' && c != '\n') {
     if (len+1 >= *size) {
-      if ((*buf = g_realloc(*buf, *size += BUFSIZ)) == NULL)
-                 return -1;
+       *buf = g_realloc(*buf, *size += BUFSIZ);
     }
     (*buf)[len++] = c;
   }
@@ -527,7 +542,6 @@ static void parse_services_file(const char * path)
   fclose(serv_p);
 }
 
-
 static void initialize_services(void)
 {
 
@@ -595,12 +609,12 @@ static gchar *serv_name_lookup(guint port, port_type proto)
   } else {
     while(1) {
       if( tp->port == port ) {
-       return tp->name;
+    return tp->name;
       }
       if (tp->next == NULL) {
-       tp->next = (hashport_t *)g_malloc(sizeof(hashport_t));
-       tp = tp->next;
-       break;
+    tp->next = (hashport_t *)g_malloc(sizeof(hashport_t));
+    tp = tp->next;
+    break;
       }
       tp = tp->next;
     }
@@ -623,18 +637,6 @@ static gchar *serv_name_lookup(guint port, port_type proto)
 } /* serv_name_lookup */
 
 
-#ifdef AVOID_DNS_TIMEOUT
-
-#define DNS_TIMEOUT    2       /* max sec per call */
-
-jmp_buf hostname_env;
-
-static void abort_network_query(int sig _U_)
-{
-  longjmp(hostname_env, 1);
-}
-#endif /* AVOID_DNS_TIMEOUT */
-
 /* Fill in an IP4 structure with info from subnets file or just with the
  * string form of the address.
  */
@@ -690,11 +692,11 @@ c_ares_ghba_cb(void *arg, int status, struct hostent *he) {
 #else
 c_ares_ghba_cb(void *arg, int status, int timeouts _U_, struct hostent *he) {
 #endif
-  c_ares_queue_msg_t *caqm = arg;
+  async_dns_queue_msg_t *caqm = arg;
   char **p;
 
   if (!caqm) return;
-  c_ares_in_flight--;
+  async_dns_in_flight--;
 
   if (status == ARES_SUCCESS) {
     for (p = he->h_addr_list; *p != NULL; p++) {
@@ -732,13 +734,6 @@ static hashipv4_t *host_lookup(guint addr, gboolean resolve, gboolean *found)
   int hash_idx;
   hashipv4_t * volatile tp;
   struct hostent *hostp;
-#ifdef HAVE_C_ARES
-  c_ares_queue_msg_t *caqm;
-#else
-#ifdef HAVE_GNU_ADNS
-  adns_queue_msg_t *qmsg;
-#endif /* HAVE_GNU_ADNS */
-#endif /* HAVE_C_ARES */
 
   *found = TRUE;
 
@@ -751,16 +746,16 @@ static hashipv4_t *host_lookup(guint addr, gboolean resolve, gboolean *found)
   } else {
     while(1) {
       if( tp->addr == addr ) {
-                 if (tp->is_dummy_entry && !tp->resolve)
-                         break;
-                 if (tp->is_dummy_entry)
-                         *found = FALSE;
-                 return tp;
+          if (tp->is_dummy_entry && !tp->resolve)
+              break;
+          if (tp->is_dummy_entry)
+              *found = FALSE;
+          return tp;
       }
       if (tp->next == NULL) {
-                 tp->next = new_ipv4(addr);
-                 tp = tp->next;
-                 break;
+          tp->next = new_ipv4(addr);
+          tp = tp->next;
+          break;
       }
       tp = tp->next;
     }
@@ -768,40 +763,18 @@ static hashipv4_t *host_lookup(guint addr, gboolean resolve, gboolean *found)
 
   if (resolve) {
       tp->resolve = TRUE;
-#ifdef HAVE_C_ARES
+#ifdef ASYNC_DNS
   if ((g_resolv_flags & RESOLV_CONCURRENT) &&
       prefs.name_resolve_concurrency > 0 &&
-      c_ares_initialized) {
-    caqm = g_malloc(sizeof(c_ares_queue_msg_t));
-    caqm->family = AF_INET;
-    caqm->addr.ip4 = addr;
-    c_ares_queue_head = g_list_append(c_ares_queue_head, (gpointer) caqm);
-
-    /* XXX found is set to TRUE, which seems a bit odd, but I'm not
-     * going to risk changing the semantics.
-     */
-    fill_dummy_ip4(addr, tp);
-    return tp;
-  }
-#else
-#ifdef HAVE_GNU_ADNS
-  if ((g_resolv_flags & RESOLV_CONCURRENT) &&
-      prefs.name_resolve_concurrency > 0 &&
-      gnu_adns_initialized) {
-    qmsg = g_malloc(sizeof(adns_queue_msg_t));
-    qmsg->type = AF_INET;
-    qmsg->ip4_addr = addr;
-    qmsg->submitted = FALSE;
-    adns_queue_head = g_list_append(adns_queue_head, (gpointer) qmsg);
-
-    /* XXX found is set to TRUE, which seems a bit odd, but I'm not
-     * going to risk changing the semantics.
-     */
-    fill_dummy_ip4(addr, tp);
-    return tp;
+      async_dns_initialized) {
+                 add_async_dns_ipv4(AF_INET, addr);
+                 /* XXX found is set to TRUE, which seems a bit odd, but I'm not
+                  * going to risk changing the semantics.
+                  */
+                 fill_dummy_ip4(addr, tp);
+                 return tp;
   }
-#endif /* HAVE_GNU_ADNS */
-#endif /* HAVE_C_ARES */
+#endif /* ASYNC_DNS */
 
   /*
    * The Windows "gethostbyaddr()" insists on translating 0.0.0.0 to
@@ -814,30 +787,13 @@ static hashipv4_t *host_lookup(guint addr, gboolean resolve, gboolean *found)
    * else call gethostbyaddr and hope for the best
    */
 
-# ifdef AVOID_DNS_TIMEOUT
-
-    /* Quick hack to avoid DNS/YP timeout */
-
-    if (!setjmp(hostname_env)) {
-      signal(SIGALRM, abort_network_query);
-      alarm(DNS_TIMEOUT);
-# endif /* AVOID_DNS_TIMEOUT */
-
       hostp = gethostbyaddr((char *)&addr, 4, AF_INET);
 
-# ifdef AVOID_DNS_TIMEOUT
-      alarm(0);
-# endif /* AVOID_DNS_TIMEOUT */
-
       if (hostp != NULL) {
-                 g_strlcpy(tp->name, hostp->h_name, MAXNAMELEN);
-                 tp->is_dummy_entry = FALSE;
-                 return tp;
+          g_strlcpy(tp->name, hostp->h_name, MAXNAMELEN);
+          tp->is_dummy_entry = FALSE;
+          return tp;
       }
-# ifdef AVOID_DNS_TIMEOUT
-
-    }
-# endif /* AVOID_DNS_TIMEOUT */
   }
 
   /* unknown host or DNS timeout */
@@ -876,10 +832,10 @@ static hashipv6_t *host_lookup6(const struct e_in6_addr *addr, gboolean resolve,
 {
   int hash_idx;
   hashipv6_t * volatile tp;
+#ifdef INET6
 #ifdef HAVE_C_ARES
-  c_ares_queue_msg_t *caqm;
+  async_dns_queue_msg_t *caqm;
 #endif /* HAVE_C_ARES */
-#ifdef INET6
   struct hostent *hostp;
 #endif
 
@@ -894,16 +850,16 @@ static hashipv6_t *host_lookup6(const struct e_in6_addr *addr, gboolean resolve,
   } else {
     while(1) {
       if( memcmp(&tp->addr, addr, sizeof (struct e_in6_addr)) == 0 ) {
-                 if (tp->is_dummy_entry && !tp->resolve)
-                         break;
-                 if (tp->is_dummy_entry)
-                         *found = FALSE;
-                 return tp;
+          if (tp->is_dummy_entry && !tp->resolve)
+              break;
+          if (tp->is_dummy_entry)
+              *found = FALSE;
+          return tp;
       }
       if (tp->next == NULL) {
-                 tp->next = new_ipv6(addr);
-                 tp = tp->next;
-                 break;
+          tp->next = new_ipv6(addr);
+          tp = tp->next;
+          break;
       }
       tp = tp->next;
     }
@@ -916,51 +872,39 @@ static hashipv6_t *host_lookup6(const struct e_in6_addr *addr, gboolean resolve,
 #ifdef HAVE_C_ARES
   if ((g_resolv_flags & RESOLV_CONCURRENT) &&
       prefs.name_resolve_concurrency > 0 &&
-      c_ares_initialized) {
-    caqm = g_malloc(sizeof(c_ares_queue_msg_t));
+      async_dns_initialized) {
+    caqm = g_malloc(sizeof(async_dns_queue_msg_t));
     caqm->family = AF_INET6;
     memcpy(&caqm->addr.ip6, addr, sizeof(caqm->addr.ip6));
-    c_ares_queue_head = g_list_append(c_ares_queue_head, (gpointer) caqm);
+    async_dns_queue_head = g_list_append(async_dns_queue_head, (gpointer) caqm);
 
     /* XXX found is set to TRUE, which seems a bit odd, but I'm not
      * going to risk changing the semantics.
      */
-       if (!tp->is_dummy_entry) {
-               ip6_to_str_buf(addr, tp->name);
-               tp->is_dummy_entry = TRUE;
-       }
-       return tp;
+    if (!tp->is_dummy_entry) {
+               strcpy(tp->name, tp->ip6);
+        ip6_to_str_buf(addr, tp->name);
+        tp->is_dummy_entry = TRUE;
+    }
+    return tp;
   }
 #endif /* HAVE_C_ARES */
 
     /* Quick hack to avoid DNS/YP timeout */
-
-#ifdef AVOID_DNS_TIMEOUT
-    if (!setjmp(hostname_env)) {
-      signal(SIGALRM, abort_network_query);
-      alarm(DNS_TIMEOUT);
-#endif /* AVOID_DNS_TIMEOUT */
       hostp = gethostbyaddr((char *)addr, sizeof(*addr), AF_INET6);
-#ifdef AVOID_DNS_TIMEOUT
-      alarm(0);
-# endif /* AVOID_DNS_TIMEOUT */
 
       if (hostp != NULL) {
-                 g_strlcpy(tp->name, hostp->h_name, MAXNAMELEN);
-                 tp->is_dummy_entry = FALSE;
-                 return tp;
+          g_strlcpy(tp->name, hostp->h_name, MAXNAMELEN);
+          tp->is_dummy_entry = FALSE;
+          return tp;
       }
-
-#ifdef AVOID_DNS_TIMEOUT
-    }
-# endif /* AVOID_DNS_TIMEOUT */
 #endif /* INET6 */
   }
 
   /* unknown host or DNS timeout */
   if (!tp->is_dummy_entry) {
-       tp->is_dummy_entry = TRUE;
-       strcpy(tp->name, tp->ip6);
+    tp->is_dummy_entry = TRUE;
+    strcpy(tp->name, tp->ip6);
   }
   *found = FALSE;
   return tp;
@@ -976,24 +920,24 @@ static gchar *host_name_lookup6(struct e_in6_addr *addr, gboolean *found)
 }
 #endif
 
-/* --------------------------- */
-static const gchar *solve_address_to_name(address *addr)
+static const gchar *solve_address_to_name(const address *addr)
 {
-  guint32 ipv4_addr;
-  struct e_in6_addr ipv6_addr;
-
   switch (addr->type) {
 
   case AT_ETHER:
     return get_ether_name(addr->data);
 
-  case AT_IPv4:
+  case AT_IPv4: {
+    guint32 ipv4_addr;
     memcpy(&ipv4_addr, addr->data, sizeof ipv4_addr);
     return get_hostname(ipv4_addr);
+  }
 
-  case AT_IPv6:
+  case AT_IPv6: {
+    struct e_in6_addr ipv6_addr;
     memcpy(&ipv6_addr.bytes, addr->data, sizeof ipv6_addr.bytes);
     return get_hostname6(&ipv6_addr);
+  }
 
   case AT_STRINGZ:
     return addr->data;
@@ -1001,8 +945,34 @@ static const gchar *solve_address_to_name(address *addr)
   default:
     return NULL;
   }
-} /* solve_address_to_name */
+}
+
+static const gchar *se_solve_address_to_name(const address *addr)
+{
+  switch (addr->type) {
 
+  case AT_ETHER:
+    return get_ether_name(addr->data);
+
+  case AT_IPv4: {
+    guint32 ipv4_addr;
+    memcpy(&ipv4_addr, addr->data, sizeof ipv4_addr);
+    return get_hostname(ipv4_addr);
+  }
+
+  case AT_IPv6: {
+    struct e_in6_addr ipv6_addr;
+    memcpy(&ipv6_addr.bytes, addr->data, sizeof ipv6_addr.bytes);
+    return get_hostname6(&ipv6_addr);
+  }
+
+  case AT_STRINGZ:
+    return se_strdup(addr->data);
+
+  default:
+    return NULL;
+  }
+}
 
 /*
  * Ethernet / manufacturer resolution
@@ -1049,64 +1019,64 @@ parse_ether_address(const char *cp, ether_t *eth, unsigned int *mask,
       return FALSE;
     num = strtoul(cp, &p, 16);
     if (p == cp)
-      return FALSE;    /* failed */
+      return FALSE; /* failed */
     if (num > 0xFF)
-      return FALSE;    /* not a valid octet */
+      return FALSE; /* not a valid octet */
     eth->addr[i] = (guint8) num;
-    cp = p;            /* skip past the number */
+    cp = p;     /* skip past the number */
 
     /* OK, what character terminated the octet? */
     if (*cp == '/') {
       /* "/" - this has a mask. */
       if (!manuf_file) {
-       /* Entries with masks are allowed only in the "manuf" files. */
-       return FALSE;
+        /* Entries with masks are allowed only in the "manuf" files. */
+    return FALSE;
       }
-      cp++;    /* skip past the '/' to get to the mask */
+      cp++; /* skip past the '/' to get to the mask */
       if (!isdigit((unsigned char)*cp))
-       return FALSE;   /* no sign allowed */
+    return FALSE;   /* no sign allowed */
       num = strtoul(cp, &p, 10);
       if (p == cp)
-       return FALSE;   /* failed */
-      cp = p;  /* skip past the number */
+    return FALSE;   /* failed */
+      cp = p;   /* skip past the number */
       if (*cp != '\0' && !isspace((unsigned char)*cp))
-       return FALSE;   /* bogus terminator */
+    return FALSE;   /* bogus terminator */
       if (num == 0 || num >= 48)
-       return FALSE;   /* bogus mask */
+    return FALSE;   /* bogus mask */
       /* Mask out the bits not covered by the mask */
       *mask = num;
       for (i = 0; num >= 8; i++, num -= 8)
-       ;       /* skip octets entirely covered by the mask */
+    ;   /* skip octets entirely covered by the mask */
       /* Mask out the first masked octet */
       eth->addr[i] &= (0xFF << (8 - num));
       i++;
       /* Mask out completely-masked-out octets */
       for (; i < 6; i++)
-       eth->addr[i] = 0;
+    eth->addr[i] = 0;
       return TRUE;
     }
     if (*cp == '\0') {
       /* We're at the end of the address, and there's no mask. */
       if (i == 2) {
-       /* We got 3 bytes, so this is a manufacturer ID. */
-       if (!manuf_file) {
-         /* Manufacturer IDs are only allowed in the "manuf"
-            files. */
-         return FALSE;
-       }
-       /* Indicate that this is a manufacturer ID (0 is not allowed
-          as a mask). */
-       *mask = 0;
-       return TRUE;
+    /* We got 3 bytes, so this is a manufacturer ID. */
+    if (!manuf_file) {
+      /* Manufacturer IDs are only allowed in the "manuf"
+         files. */
+      return FALSE;
+    }
+    /* Indicate that this is a manufacturer ID (0 is not allowed
+       as a mask). */
+    *mask = 0;
+    return TRUE;
       }
 
       if (i == 5) {
-       /* We got 6 bytes, so this is a MAC address.
-          If we're reading one of the "manuf" files, indicate that
-          this is a MAC address (48 is not allowed as a mask). */
-       if (manuf_file)
-         *mask = 48;
-       return TRUE;
+    /* We got 6 bytes, so this is a MAC address.
+       If we're reading one of the "manuf" files, indicate that
+       this is a MAC address (48 is not allowed as a mask). */
+    if (manuf_file)
+      *mask = 48;
+    return TRUE;
       }
 
       /* We didn't get 3 or 6 bytes, and there's no mask; this is
@@ -1114,11 +1084,11 @@ parse_ether_address(const char *cp, ether_t *eth, unsigned int *mask,
       return FALSE;
     } else {
       if (sep == '\0') {
-       /* We don't know the separator used in this number; it can either
-          be ':', '-', or '.'. */
-       if (*cp != ':' && *cp != '-' && *cp != '.')
-         return FALSE;
-       sep = *cp;      /* subsequent separators must be the same */
+    /* We don't know the separator used in this number; it can either
+       be ':', '-', or '.'. */
+    if (*cp != ':' && *cp != '-' && *cp != '.')
+      return FALSE;
+    sep = *cp;  /* subsequent separators must be the same */
       } else {
           /* It has to be the same as the first separator */
           if (*cp != sep)
@@ -1132,7 +1102,7 @@ parse_ether_address(const char *cp, ether_t *eth, unsigned int *mask,
 }
 
 static int parse_ether_line(char *line, ether_t *eth, unsigned int *mask,
-                           gboolean manuf_file)
+                gboolean manuf_file)
 {
   /*
    *  See the ethers(4) or ethers(5) man page for ethers file format
@@ -1271,14 +1241,14 @@ static int hash_eth_wka(const guint8 *addr, unsigned int mask)
     /* All but the topmost 4 bytes are masked out */
     return ((((addr[0] << 8) | addr[1]) ^
              ((addr[2] << 8) | (addr[3] & (0xFF << (8 - mask)))))) &
-        (HASHETHSIZE - 1);
+     (HASHETHSIZE - 1);
   }
   mask -= 8;
   if (mask <= 8) {
     /* All but the topmost 5 bytes are masked out */
     return ((((addr[1] << 8) | addr[2]) ^
              ((addr[3] << 8) | (addr[4] & (0xFF << (8 - mask)))))) &
-        (HASHETHSIZE - 1);
+     (HASHETHSIZE - 1);
   }
   mask -= 8;
   /* No bytes are fully masked out */
@@ -1311,12 +1281,12 @@ static void add_manuf_name(guint8 *addr, unsigned int mask, gchar *name)
       tp = manuf_table[hash_idx] = (hashmanuf_t *)g_malloc(sizeof(hashmanuf_t));
     } else {
       while(1) {
-       if (tp->next == NULL) {
-         tp->next = (hashmanuf_t *)g_malloc(sizeof(hashmanuf_t));
-         tp = tp->next;
-         break;
-       }
-       tp = tp->next;
+    if (tp->next == NULL) {
+      tp->next = (hashmanuf_t *)g_malloc(sizeof(hashmanuf_t));
+      tp = tp->next;
+      break;
+    }
+    tp = tp->next;
       }
     }
 
@@ -1341,13 +1311,13 @@ static void add_manuf_name(guint8 *addr, unsigned int mask, gchar *name)
   } else {
     while(1) {
       if (memcmp(etp->addr, addr, sizeof(etp->addr)) == 0) {
-       /* address already known */
-       return;
+    /* address already known */
+    return;
       }
       if (etp->next == NULL) {
-       etp->next = (hashether_t *)g_malloc(sizeof(hashether_t));
-       etp = etp->next;
-       break;
+    etp->next = (hashether_t *)g_malloc(sizeof(hashether_t));
+    etp = etp->next;
+    break;
       }
       etp = etp->next;
     }
@@ -1415,7 +1385,7 @@ static hashether_t *wka_name_lookup(const guint8 *addr, unsigned int mask)
 
   /* Get the part of the address covered by the mask. */
   for (i = 0, num = mask; num >= 8; i++, num -= 8)
-    masked_addr[i] = addr[i];  /* copy octets entirely covered by the mask */
+    masked_addr[i] = addr[i];   /* copy octets entirely covered by the mask */
   /* Mask out the first masked octet */
   masked_addr[i] = addr[i] & (0xFF << (8 - num));
   i++;
@@ -1447,7 +1417,7 @@ static void initialize_ethers(void)
   /* Compute the pathname of the ethers file. */
   if (g_ethers_path == NULL) {
     g_ethers_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
-           get_systemfile_dir(), ENAME_ETHERS);
+        get_systemfile_dir(), ENAME_ETHERS);
   }
 
   /* Set g_pethers_path here, but don't actually do anything
@@ -1489,19 +1459,19 @@ static hashether_t *add_eth_name(const guint8 *addr, const gchar *name)
   } else {
     while(1) {
       if (memcmp(tp->addr, addr, sizeof(tp->addr)) == 0) {
-       /* address already known */
-       if (!tp->is_dummy_entry) {
-         return tp;
-       } else {
-         /* replace this dummy (manuf) entry with a real name */
-         new_one = FALSE;
-         break;
-       }
+    /* address already known */
+    if (!tp->is_dummy_entry) {
+      return tp;
+    } else {
+      /* replace this dummy (manuf) entry with a real name */
+      new_one = FALSE;
+      break;
+    }
       }
       if (tp->next == NULL) {
-       tp->next = (hashether_t *)g_malloc(sizeof(hashether_t));
-       tp = tp->next;
-       break;
+    tp->next = (hashether_t *)g_malloc(sizeof(hashether_t));
+    tp = tp->next;
+    break;
       }
       tp = tp->next;
     }
@@ -1538,12 +1508,12 @@ static hashether_t *eth_name_lookup(const guint8 *addr, gboolean resolve)
   } else {
     while(1) {
       if (memcmp(tp->addr, addr, sizeof(tp->addr)) == 0) {
-       return tp;
+    return tp;
       }
       if (tp->next == NULL) {
-       tp->next = (hashether_t *)g_malloc(sizeof(hashether_t));
-       tp = tp->next;
-       break;
+    tp->next = (hashether_t *)g_malloc(sizeof(hashether_t));
+    tp = tp->next;
+    break;
       }
       tp = tp->next;
     }
@@ -1566,10 +1536,10 @@ static hashether_t *eth_name_lookup(const guint8 *addr, gboolean resolve)
     for (;;) {
       /* Only the topmost 5 bytes participate fully */
       if ((etp = wka_name_lookup(addr, mask+40)) != NULL) {
-       g_snprintf(tp->name, MAXNAMELEN, "%s_%02x",
-             etp->name, addr[5] & (0xFF >> mask));
-       tp->is_dummy_entry = TRUE;
-       return tp;
+    g_snprintf(tp->name, MAXNAMELEN, "%s_%02x",
+          etp->name, addr[5] & (0xFF >> mask));
+    tp->is_dummy_entry = TRUE;
+    return tp;
       }
       if (mask == 0)
         break;
@@ -1580,10 +1550,10 @@ static hashether_t *eth_name_lookup(const guint8 *addr, gboolean resolve)
     for (;;) {
       /* Only the topmost 4 bytes participate fully */
       if ((etp = wka_name_lookup(addr, mask+32)) != NULL) {
-       g_snprintf(tp->name, MAXNAMELEN, "%s_%02x:%02x",
-             etp->name, addr[4] & (0xFF >> mask), addr[5]);
-       tp->is_dummy_entry = TRUE;
-       return tp;
+    g_snprintf(tp->name, MAXNAMELEN, "%s_%02x:%02x",
+          etp->name, addr[4] & (0xFF >> mask), addr[5]);
+    tp->is_dummy_entry = TRUE;
+    return tp;
       }
       if (mask == 0)
         break;
@@ -1594,10 +1564,10 @@ static hashether_t *eth_name_lookup(const guint8 *addr, gboolean resolve)
     for (;;) {
       /* Only the topmost 3 bytes participate fully */
       if ((etp = wka_name_lookup(addr, mask+24)) != NULL) {
-       g_snprintf(tp->name, MAXNAMELEN, "%s_%02x:%02x:%02x",
-             etp->name, addr[3] & (0xFF >> mask), addr[4], addr[5]);
-       tp->is_dummy_entry = TRUE;
-       return tp;
+    g_snprintf(tp->name, MAXNAMELEN, "%s_%02x:%02x:%02x",
+          etp->name, addr[3] & (0xFF >> mask), addr[4], addr[5]);
+    tp->is_dummy_entry = TRUE;
+    return tp;
       }
       if (mask == 0)
         break;
@@ -1607,7 +1577,7 @@ static hashether_t *eth_name_lookup(const guint8 *addr, gboolean resolve)
     /* Now try looking in the manufacturer table. */
     if ((manufp = manuf_name_lookup(addr)) != NULL) {
       g_snprintf(tp->name, MAXNAMELEN, "%s_%02x:%02x:%02x",
-             manufp->name, addr[3], addr[4], addr[5]);
+          manufp->name, addr[3], addr[4], addr[5]);
       tp->is_dummy_entry = TRUE;
       return tp;
     }
@@ -1618,11 +1588,11 @@ static hashether_t *eth_name_lookup(const guint8 *addr, gboolean resolve)
     for (;;) {
       /* Only the topmost 2 bytes participate fully */
       if ((etp = wka_name_lookup(addr, mask+16)) != NULL) {
-       g_snprintf(tp->name, MAXNAMELEN, "%s_%02x:%02x:%02x:%02x",
-             etp->name, addr[2] & (0xFF >> mask), addr[3], addr[4],
-             addr[5]);
-       tp->is_dummy_entry = TRUE;
-       return tp;
+    g_snprintf(tp->name, MAXNAMELEN, "%s_%02x:%02x:%02x:%02x",
+          etp->name, addr[2] & (0xFF >> mask), addr[3], addr[4],
+          addr[5]);
+    tp->is_dummy_entry = TRUE;
+    return tp;
       }
       if (mask == 0)
         break;
@@ -1633,11 +1603,11 @@ static hashether_t *eth_name_lookup(const guint8 *addr, gboolean resolve)
     for (;;) {
       /* Only the topmost byte participates fully */
       if ((etp = wka_name_lookup(addr, mask+8)) != NULL) {
-       g_snprintf(tp->name, MAXNAMELEN, "%s_%02x:%02x:%02x:%02x:%02x",
-             etp->name, addr[1] & (0xFF >> mask), addr[2], addr[3],
-             addr[4], addr[5]);
-       tp->is_dummy_entry = TRUE;
-       return tp;
+    g_snprintf(tp->name, MAXNAMELEN, "%s_%02x:%02x:%02x:%02x:%02x",
+          etp->name, addr[1] & (0xFF >> mask), addr[2], addr[3],
+          addr[4], addr[5]);
+    tp->is_dummy_entry = TRUE;
+    return tp;
       }
       if (mask == 0)
         break;
@@ -1647,11 +1617,11 @@ static hashether_t *eth_name_lookup(const guint8 *addr, gboolean resolve)
     for (mask = 7; mask > 0; mask--) {
       /* Not even the topmost byte participates fully */
       if ((etp = wka_name_lookup(addr, mask)) != NULL) {
-       g_snprintf(tp->name, MAXNAMELEN, "%s_%02x:%02x:%02x:%02x:%02x:%02x",
-             etp->name, addr[0] & (0xFF >> mask), addr[1], addr[2],
-             addr[3], addr[4], addr[5]);
-       tp->is_dummy_entry = TRUE;
-       return tp;
+    g_snprintf(tp->name, MAXNAMELEN, "%s_%02x:%02x:%02x:%02x:%02x:%02x",
+          etp->name, addr[0] & (0xFF >> mask), addr[1], addr[2],
+          addr[3], addr[4], addr[5]);
+    tp->is_dummy_entry = TRUE;
+    return tp;
       }
     }
 
@@ -1680,7 +1650,7 @@ static guint8 *eth_addr_lookup(const gchar *name)
     tp = table[i];
     while (tp) {
       if (strcmp(tp->name, name) == 0)
-       return tp->addr;
+    return tp->addr;
       tp = tp->next;
     }
   }
@@ -1707,9 +1677,9 @@ static int parse_ipxnets_line(char *line, ipxnet_t *ipxnet)
    *  as well as no separators
    */
 
-  gchar                *cp;
-  guint32      a, a0, a1, a2, a3;
-  gboolean     found_single_number = FALSE;
+  gchar     *cp;
+  guint32   a, a0, a1, a2, a3;
+  gboolean  found_single_number = FALSE;
 
   if ((cp = strchr(line, '#')))
     *cp = '\0';
@@ -1725,11 +1695,11 @@ static int parse_ipxnets_line(char *line, ipxnet_t *ipxnet)
     if (sscanf(cp, "%x-%x-%x-%x", &a0, &a1, &a2, &a3) != 4) {
       if (sscanf(cp, "%x.%x.%x.%x", &a0, &a1, &a2, &a3) != 4) {
         if (sscanf(cp, "%x", &a) == 1) {
-         found_single_number = TRUE;
-       }
-       else {
-         return -1;
-       }
+      found_single_number = TRUE;
+    }
+    else {
+      return -1;
+    }
       }
     }
   }
@@ -1738,10 +1708,10 @@ static int parse_ipxnets_line(char *line, ipxnet_t *ipxnet)
     return -1;
 
   if (found_single_number) {
-       ipxnet->addr = a;
+    ipxnet->addr = a;
   }
   else {
-       ipxnet->addr = (a0 << 24) | (a1 << 16) | (a2 << 8) | a3;
+    ipxnet->addr = (a0 << 24) | (a1 << 16) | (a2 << 8) | a3;
   }
 
   g_strlcpy(ipxnet->name, cp, MAXNAMELEN);
@@ -1846,8 +1816,8 @@ static void initialize_ipxnets(void)
    * directory as well?
    */
   if (g_ipxnets_path == NULL) {
-       g_ipxnets_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
-           get_systemfile_dir(), ENAME_IPXNETS);
+    g_ipxnets_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
+        get_systemfile_dir(), ENAME_IPXNETS);
   }
 
   /* Set g_pipxnets_path here, but don't actually do anything
@@ -1872,9 +1842,9 @@ static hashipxnet_t *add_ipxnet_name(guint addr, const gchar *name)
   } else {
     while(1) {
       if (tp->next == NULL) {
-       tp->next = (hashipxnet_t *)g_malloc(sizeof(hashipxnet_t));
-       tp = tp->next;
-       break;
+    tp->next = (hashipxnet_t *)g_malloc(sizeof(hashipxnet_t));
+    tp = tp->next;
+    break;
       }
       tp = tp->next;
     }
@@ -1903,12 +1873,12 @@ static gchar *ipxnet_name_lookup(const guint addr)
   } else {
     while(1) {
       if (tp->addr == addr) {
-       return tp->name;
+    return tp->name;
       }
       if (tp->next == NULL) {
-       tp->next = (hashipxnet_t *)g_malloc(sizeof(hashipxnet_t));
-       tp = tp->next;
-       break;
+    tp->next = (hashipxnet_t *)g_malloc(sizeof(hashipxnet_t));
+    tp = tp->next;
+    break;
       }
       tp = tp->next;
     }
@@ -1944,7 +1914,7 @@ static guint ipxnet_addr_lookup(const gchar *name, gboolean *success)
     while (tp) {
       if (strcmp(tp->name, name) == 0) {
         *success = TRUE;
-       return tp->addr;
+    return tp->addr;
       }
       tp = tp->next;
     }
@@ -2309,9 +2279,15 @@ host_name_lookup_init(void) {
   g_free(hostspath);
 
 #ifdef HAVE_C_ARES
+#ifdef CARES_HAVE_ARES_LIBRARY_INIT
+  if (ares_library_init(ARES_LIB_INIT_ALL) == ARES_SUCCESS) {
+#endif
   if (ares_init(&alchan) == ARES_SUCCESS) {
-    c_ares_initialized = TRUE;
+    async_dns_initialized = TRUE;
+  }
+#ifdef CARES_HAVE_ARES_LIBRARY_INIT
   }
+#endif
 #else
 #ifdef HAVE_GNU_ADNS
   /*
@@ -2356,8 +2332,8 @@ host_name_lookup_init(void) {
      */
     return;
   }
-  gnu_adns_initialized = TRUE;
-  adns_in_flight = 0;
+  async_dns_initialized = TRUE;
+  async_dns_in_flight = 0;
 #endif /* HAVE_GNU_ADNS */
 #endif /* HAVE_C_ARES */
 
@@ -2367,28 +2343,28 @@ host_name_lookup_init(void) {
 #ifdef HAVE_C_ARES
 gboolean
 host_name_lookup_process(gpointer data _U_) {
-  c_ares_queue_msg_t *caqm;
+  async_dns_queue_msg_t *caqm;
   struct timeval tv = { 0, 0 };
   int nfds;
   fd_set rfds, wfds;
 
-  if (!c_ares_initialized)
+  if (!async_dns_initialized)
     /* c-ares not initialized. Bail out and cancel timers. */
     return FALSE;
 
-  c_ares_queue_head = g_list_first(c_ares_queue_head);
+  async_dns_queue_head = g_list_first(async_dns_queue_head);
 
-  while (c_ares_queue_head && c_ares_in_flight <= prefs.name_resolve_concurrency) {
-    caqm = (c_ares_queue_msg_t *) c_ares_queue_head->data;
-    c_ares_queue_head = g_list_remove(c_ares_queue_head, (void *) caqm);
+  while (async_dns_queue_head && async_dns_in_flight <= prefs.name_resolve_concurrency) {
+    caqm = (async_dns_queue_msg_t *) async_dns_queue_head->data;
+    async_dns_queue_head = g_list_remove(async_dns_queue_head, (void *) caqm);
     if (caqm->family == AF_INET) {
       ares_gethostbyaddr(alchan, &caqm->addr.ip4, sizeof(guint32), AF_INET,
         c_ares_ghba_cb, caqm);
-      c_ares_in_flight++;
+      async_dns_in_flight++;
     } else if (caqm->family == AF_INET6) {
       ares_gethostbyaddr(alchan, &caqm->addr.ip6, sizeof(struct e_in6_addr),
-        AF_INET, c_ares_ghba_cb, caqm);
-      c_ares_in_flight++;
+        AF_INET6, c_ares_ghba_cb, caqm);
+      async_dns_in_flight++;
     }
   }
 
@@ -2408,17 +2384,21 @@ void
 host_name_lookup_cleanup(void) {
   GList *cur;
 
-  cur = g_list_first(c_ares_queue_head);
+  cur = g_list_first(async_dns_queue_head);
   while (cur) {
     g_free(cur->data);
     cur = g_list_next (cur);
   }
 
-  g_list_free(c_ares_queue_head);
+  g_list_free(async_dns_queue_head);
 
-  if (c_ares_initialized)
+  if (async_dns_initialized) {
     ares_destroy(alchan);
-  c_ares_initialized = FALSE;
+  }
+#ifdef CARES_HAVE_ARES_LIBRARY_INIT
+  ares_library_cleanup();
+#endif
+  async_dns_initialized = FALSE;
 }
 
 #elif defined(HAVE_GNU_ADNS)
@@ -2428,7 +2408,7 @@ host_name_lookup_cleanup(void) {
  */
 gboolean
 host_name_lookup_process(gpointer data _U_) {
-  adns_queue_msg_t *almsg;
+  async_dns_queue_msg_t *almsg;
   GList *cur;
   char addr_str[] = "111.222.333.444.in-addr.arpa.";
   guint8 *addr_bytes;
@@ -2436,11 +2416,11 @@ host_name_lookup_process(gpointer data _U_) {
   int ret;
   gboolean dequeue;
 
-  adns_queue_head = g_list_first(adns_queue_head);
+  async_dns_queue_head = g_list_first(async_dns_queue_head);
 
-  cur = adns_queue_head;
-  while (cur && adns_in_flight <= prefs.name_resolve_concurrency) {
-    almsg = (adns_queue_msg_t *) cur->data;
+  cur = async_dns_queue_head;
+  while (cur &&  async_dns_in_flight <= prefs.name_resolve_concurrency) {
+    almsg = (async_dns_queue_msg_t *) cur->data;
     if (! almsg->submitted && almsg->type == AF_INET) {
       addr_bytes = (guint8 *) &almsg->ip4_addr;
       g_snprintf(addr_str, sizeof addr_str, "%u.%u.%u.%u.in-addr.arpa.", addr_bytes[3],
@@ -2448,29 +2428,29 @@ host_name_lookup_process(gpointer data _U_) {
       /* XXX - what if it fails? */
       adns_submit (ads, addr_str, adns_r_ptr, 0, NULL, &almsg->query);
       almsg->submitted = TRUE;
-      adns_in_flight++;
+       async_dns_in_flight++;
     }
     cur = cur->next;
   }
 
-  cur = adns_queue_head;
+  cur = async_dns_queue_head;
   while (cur) {
     dequeue = FALSE;
-    almsg = (adns_queue_msg_t *) cur->data;
+    almsg = (async_dns_queue_msg_t *) cur->data;
     if (almsg->submitted) {
       ret = adns_check(ads, &almsg->query, &ans, NULL);
       if (ret == 0) {
-       if (ans->status == adns_s_ok) {
-         add_ipv4_name(almsg->ip4_addr, *ans->rrs.str);
-       }
-       dequeue = TRUE;
+    if (ans->status == adns_s_ok) {
+      add_ipv4_name(almsg->ip4_addr, *ans->rrs.str);
+    }
+    dequeue = TRUE;
       }
     }
     cur = cur->next;
     if (dequeue) {
-      adns_queue_head = g_list_remove(adns_queue_head, (void *) almsg);
+      async_dns_queue_head = g_list_remove(async_dns_queue_head, (void *) almsg);
       g_free(almsg);
-      adns_in_flight--;
+       async_dns_in_flight--;
     }
   }
 
@@ -2482,16 +2462,16 @@ void
 host_name_lookup_cleanup(void) {
   void *qdata;
 
-  adns_queue_head = g_list_first(adns_queue_head);
-  while (adns_queue_head) {
-    qdata = adns_queue_head->data;
-    adns_queue_head = g_list_remove(adns_queue_head, qdata);
+  async_dns_queue_head = g_list_first(async_dns_queue_head);
+  while (async_dns_queue_head) {
+    qdata = async_dns_queue_head->data;
+    async_dns_queue_head = g_list_remove(async_dns_queue_head, qdata);
     g_free(qdata);
   }
 
-  if (gnu_adns_initialized)
+  if (async_dns_initialized)
     adns_finish(ads);
-  gnu_adns_initialized = FALSE;
+   async_dns_initialized = FALSE;
 }
 
 #else /* HAVE_GNU_ADNS */
@@ -2520,14 +2500,6 @@ extern const gchar *get_hostname(guint addr)
   return tp->name;
 }
 
-extern gchar *get_hostip(guint addr)
-{
-  gboolean found;
-  hashipv4_t *tp = host_lookup(addr, FALSE, &found);
-
-  return tp->ip;
-}
-
 /* -------------------------- */
 
 extern const gchar *get_hostname6(struct e_in6_addr *addr)
@@ -2541,14 +2513,6 @@ extern const gchar *get_hostname6(struct e_in6_addr *addr)
   return tp->name;
 }
 
-extern gchar *get_hostip6(const struct e_in6_addr *addr)
-{
-  gboolean found;
-  hashipv6_t *tp = host_lookup6(addr, FALSE, &found);
-
-  return tp->ip6;
-}
-
 /* -------------------------- */
 extern void add_ipv4_name(guint addr, const gchar *name)
 {
@@ -2564,18 +2528,18 @@ extern void add_ipv4_name(guint addr, const gchar *name)
   } else {
     while(1) {
       if (tp->addr == addr) {
-       /* address already known */
-       if (!tp->is_dummy_entry) {
-         return;
-       } else {
-               /* replace this dummy entry with the new one */
-         break;
-       }
+    /* address already known */
+    if (!tp->is_dummy_entry) {
+      return;
+    } else {
+        /* replace this dummy entry with the new one */
+      break;
+    }
       }
       if (tp->next == NULL) {
-                 tp->next = new_ipv4(addr);
-                 tp = tp->next;
-                 break;
+          tp->next = new_ipv4(addr);
+          tp = tp->next;
+          break;
       }
       tp = tp->next;
     }
@@ -2599,18 +2563,18 @@ extern void add_ipv6_name(struct e_in6_addr *addrp, const gchar *name)
   } else {
     while(1) {
       if (memcmp(&tp->addr, addrp, sizeof (struct e_in6_addr)) == 0) {
-       /* address already known */
-       if (!tp->is_dummy_entry) {
-         return;
-       } else {
-         /* replace this dummy entry with the new one */
-         break;
-       }
+    /* address already known */
+    if (!tp->is_dummy_entry) {
+      return;
+    } else {
+      /* replace this dummy entry with the new one */
+      break;
+    }
       }
       if (tp->next == NULL) {
-                 tp->next = new_ipv6(addrp);
-                 tp = tp->next;
-                 break;
+          tp->next = new_ipv6(addrp);
+          tp = tp->next;
+          break;
       }
       tp = tp->next;
     }
@@ -2683,27 +2647,45 @@ extern gchar *get_sctp_port(guint port)
 
 } /* get_sctp_port */
 
-
-const gchar *get_addr_name(address *addr)
+const gchar *get_addr_name(const address *addr)
 {
   const gchar *result;
 
   result = solve_address_to_name(addr);
 
-  if (result!=NULL){
-         return result;
-  }
+  if (result != NULL)
+      return result;
 
   /* if it gets here, either it is of type AT_NONE, */
-  /* or it should be solvable in address_to_str -unless addr->type is wrongly defined- */
+  /* or it should be solvable in address_to_str -unless addr->type is wrongly defined */
 
   if (addr->type == AT_NONE){
-         return "NONE";
+      return "NONE";
   }
 
-  return(address_to_str(addr));
-} /* get_addr_name */
+  /* We need an ephemeral allocated string */
+  return ep_address_to_str(addr);
+}
+
+const gchar *se_get_addr_name(const address *addr)
+{
+  const gchar *result;
+
+  result = se_solve_address_to_name(addr);
+
+  if (result != NULL)
+      return result;
+
+  /* if it gets here, either it is of type AT_NONE, */
+  /* or it should be solvable in se_address_to_str -unless addr->type is wrongly defined */
+
+  if (addr->type == AT_NONE){
+      return "NONE";
+  }
 
+  /* We need a "permanently" allocated string */
+  return se_address_to_str(addr);
+}
 
 void get_addr_name_buf(address *addr, gchar *buf, gsize size)
 {
@@ -2713,7 +2695,7 @@ void get_addr_name_buf(address *addr, gchar *buf, gsize size)
 } /* get_addr_name_buf */
 
 
-extern gchar *get_ether_name(const guint8 *addr)
+gchar *get_ether_name(const guint8 *addr)
 {
   hashether_t *tp;
   gboolean resolve = g_resolv_flags & RESOLV_MAC;
@@ -2722,7 +2704,7 @@ extern gchar *get_ether_name(const guint8 *addr)
     return ether_to_str(addr);
 #endif
   if (resolve && !eth_resolution_initialized) {
-       initialize_ethers();
+    initialize_ethers();
     eth_resolution_initialized = 1;
   }
 
@@ -2730,14 +2712,6 @@ extern gchar *get_ether_name(const guint8 *addr)
   return tp->name;
 } /* get_ether_name */
 
-/* ---------------------- */
-extern gchar *get_ether_hexa(const guint8 *addr)
-{
-  hashether_t *tp;
-  tp = eth_name_lookup(addr, FALSE);
-  return tp->hexa;
-}
-
 
 /* Look for an ether name in the hash, and return it if found.
  * If it's not found, simply return NULL. We DO NOT make a new
@@ -2763,32 +2737,32 @@ gchar *get_ether_name_if_known(const guint8 *addr)
   tp = eth_table[hash_idx];
 
   if( tp == NULL ) {
-         /* Hash key not found in table.
-          * Force a lookup (and a hash entry) for addr, then call
-          * myself. I plan on not getting into an infinite loop because
-          * eth_name_lookup() is guaranteed to make a hashtable entry,
-          * so when I call myself again, I can never get into this
-          * block of code again. Knock on wood...
-          */
-         (void) eth_name_lookup(addr, TRUE);
-         return get_ether_name_if_known(addr); /* a well-placed goto would suffice */
+      /* Hash key not found in table.
+       * Force a lookup (and a hash entry) for addr, then call
+       * myself. I plan on not getting into an infinite loop because
+       * eth_name_lookup() is guaranteed to make a hashtable entry,
+       * so when I call myself again, I can never get into this
+       * block of code again. Knock on wood...
+       */
+      (void) eth_name_lookup(addr, TRUE);
+      return get_ether_name_if_known(addr); /* a well-placed goto would suffice */
   }
   else {
     while(1) {
       if (memcmp(tp->addr, addr, sizeof(tp->addr)) == 0) {
-             if (!tp->is_dummy_entry) {
-               /* A name was found, and its origin is an ethers file */
-               return tp->name;
-             }
-             else {
-               /* A name was found, but it was created, not found in a file */
-               return NULL;
-             }
+          if (!tp->is_dummy_entry) {
+        /* A name was found, and its origin is an ethers file */
+        return tp->name;
+          }
+          else {
+        /* A name was found, but it was created, not found in a file */
+        return NULL;
+          }
       }
       if (tp->next == NULL) {
-         /* Read my reason above for why I'm sure I can't get into an infinite loop */
-         (void) eth_name_lookup(addr, TRUE);
-         return get_ether_name_if_known(addr); /* a well-placed goto would suffice */
+      /* Read my reason above for why I'm sure I can't get into an infinite loop */
+      (void) eth_name_lookup(addr, TRUE);
+      return get_ether_name_if_known(addr); /* a well-placed goto would suffice */
       }
       tp = tp->next;
     }
@@ -2836,7 +2810,7 @@ extern const gchar *get_ipxnet_name(const guint32 addr)
 {
 
   if (!(g_resolv_flags & RESOLV_NETWORK)) {
-         return ipxnet_to_str_punct(addr, '\0');
+      return ipxnet_to_str_punct(addr, '\0');
   }
 
   if (!ipxnet_resolution_initialized) {
@@ -2912,41 +2886,41 @@ const gchar *get_manuf_name_if_known(const guint8 *addr)
  * Used more in the dfilter parser rather than in packet dissectors */
 gboolean get_host_ipaddr(const char *host, guint32 *addrp)
 {
-       struct in_addr          ipaddr;
-       struct hostent          *hp;
-
-       /*
-        * don't change it to inet_pton(AF_INET), they are not 100% compatible.
-        * inet_pton(AF_INET) does not support hexadecimal notation nor
-        * less-than-4 octet notation.
-        */
-       if (!inet_aton(host, &ipaddr)) {
-               /* It's not a valid dotted-quad IP address; is it a valid
-                * host name? */
-               hp = gethostbyname(host);
-               if (hp == NULL) {
-                       /* No. */
-                       return FALSE;
-                       /* Apparently, some versions of gethostbyaddr can
-                        * return IPv6 addresses. */
-               } else if (hp->h_length <= (int) sizeof (struct in_addr)) {
-                       memcpy(&ipaddr, hp->h_addr, hp->h_length);
-               } else {
-                       return FALSE;
-               }
-       } else {
-               /* Does the string really contain dotted-quad IP?
-                * Check against inet_atons that accept strings such as
-                * "130.230" as valid addresses and try to convert them
-                * to some form of a classful (host.net) notation.
-                */
-               unsigned int a0, a1, a2, a3;
-               if (sscanf(host, "%u.%u.%u.%u", &a0, &a1, &a2, &a3) != 4)
-                       return FALSE;
-       }
-
-       *addrp = g_ntohl(ipaddr.s_addr);
-       return TRUE;
+    struct in_addr      ipaddr;
+    struct hostent      *hp;
+
+    /*
+     * don't change it to inet_pton(AF_INET), they are not 100% compatible.
+     * inet_pton(AF_INET) does not support hexadecimal notation nor
+     * less-than-4 octet notation.
+     */
+    if (!inet_aton(host, &ipaddr)) {
+        /* It's not a valid dotted-quad IP address; is it a valid
+         * host name? */
+        hp = gethostbyname(host);
+        if (hp == NULL) {
+            /* No. */
+            return FALSE;
+            /* Apparently, some versions of gethostbyaddr can
+             * return IPv6 addresses. */
+        } else if (hp->h_length <= (int) sizeof (struct in_addr)) {
+            memcpy(&ipaddr, hp->h_addr, hp->h_length);
+        } else {
+            return FALSE;
+        }
+    } else {
+        /* Does the string really contain dotted-quad IP?
+         * Check against inet_atons that accept strings such as
+         * "130.230" as valid addresses and try to convert them
+         * to some form of a classful (host.net) notation.
+         */
+        unsigned int a0, a1, a2, a3;
+        if (sscanf(host, "%u.%u.%u.%u", &a0, &a1, &a2, &a3) != 4)
+            return FALSE;
+    }
+
+    *addrp = g_ntohl(ipaddr.s_addr);
+    return TRUE;
 }
 
 /*
@@ -2956,23 +2930,23 @@ gboolean get_host_ipaddr(const char *host, guint32 *addrp)
  */
 gboolean get_host_ipaddr6(const char *host, struct e_in6_addr *addrp)
 {
-       struct hostent *hp;
+    struct hostent *hp;
 
-       if (inet_pton(AF_INET6, host, addrp) == 1)
-               return TRUE;
+    if (inet_pton(AF_INET6, host, addrp) == 1)
+        return TRUE;
 
-       /* try FQDN */
+    /* try FQDN */
 #ifdef HAVE_GETHOSTBYNAME2
-       hp = gethostbyname2(host, AF_INET6);
+    hp = gethostbyname2(host, AF_INET6);
 #else
-       hp = NULL;
+    hp = NULL;
 #endif
-       if (hp != NULL && hp->h_length == sizeof(struct e_in6_addr)) {
-               memcpy(addrp, hp->h_addr, hp->h_length);
-               return TRUE;
-       }
+    if (hp != NULL && hp->h_length == sizeof(struct e_in6_addr)) {
+        memcpy(addrp, hp->h_addr, hp->h_length);
+        return TRUE;
+    }
 
-       return FALSE;
+    return FALSE;
 }
 
 /*
@@ -2987,9 +2961,9 @@ _U_
 )
 {
 #ifdef HAVE_GETHOSTBYNAME2
-       struct hostent *h;
-       return (h = gethostbyname2(host, AF_INET6)) && h->h_addrtype == AF_INET6 ? "ip6" : "ip";
+    struct hostent *h;
+    return (h = gethostbyname2(host, AF_INET6)) && h->h_addrtype == AF_INET6 ? "ip6" : "ip";
 #else
-       return "ip";
+    return "ip";
 #endif
 }