ares.h: there is no ares_free_soa function
[platform/upstream/c-ares.git] / ares_gethostbyname.c
index 5339fee..2b27b2e 100644 (file)
@@ -1,5 +1,5 @@
 
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* Copyright 1998, 2011, 2013 by the Massachusetts Institute of Technology.
  *
  * Permission to use, copy, modify, and distribute this
  * software and its documentation for any purpose and without
@@ -16,9 +16,6 @@
 
 #include "ares_setup.h"
 
-#ifdef HAVE_SYS_SOCKET_H
-#  include <sys/socket.h>
-#endif
 #ifdef HAVE_NETINET_IN_H
 #  include <netinet/in.h>
 #endif
 #  include <arpa/nameser_compat.h>
 #endif
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
 #ifdef HAVE_STRINGS_H
 #include <strings.h>
 #endif
 
 #include "ares.h"
-#include "inet_net_pton.h"
+#include "ares_inet_net_pton.h"
 #include "bitncmp.h"
 #include "ares_platform.h"
+#include "ares_nowarn.h"
 #include "ares_private.h"
 
 #ifdef WATT32
@@ -194,11 +188,11 @@ static void host_callback(void *arg, int status, int timeouts,
       else if (hquery->sent_family == AF_INET6)
         {
           status = ares_parse_aaaa_reply(abuf, alen, &host, NULL, NULL);
-          if (status == ARES_ENODATA || status == ARES_EBADRESP) {
+          if ((status == ARES_ENODATA || status == ARES_EBADRESP) &&
+               hquery->want_family == AF_UNSPEC) {
             /* The query returned something but either there were no AAAA
                records (e.g. just CNAME) or the response was malformed.  Try
-               looking up A instead.  We should possibly limit this
-               attempt-next logic to AF_UNSPEC lookups only. */
+               looking up A instead. */
             hquery->sent_family = AF_INET;
             ares_search(hquery->channel, hquery->name, C_IN, T_A,
                         host_callback, hquery);
@@ -210,11 +204,10 @@ static void host_callback(void *arg, int status, int timeouts,
       end_hquery(hquery, status, host);
     }
   else if ((status == ARES_ENODATA || status == ARES_EBADRESP ||
-            status == ARES_ETIMEOUT) && hquery->sent_family == AF_INET6)
+            status == ARES_ETIMEOUT) && (hquery->sent_family == AF_INET6 &&
+            hquery->want_family == AF_UNSPEC))
     {
-      /* The AAAA query yielded no useful result.  Now look up an A instead.
-         We should possibly limit this attempt-next logic to AF_UNSPEC lookups
-         only. */
+      /* The AAAA query yielded no useful result.  Now look up an A instead. */
       hquery->sent_family = AF_INET;
       ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback,
                   hquery);
@@ -301,7 +294,7 @@ static int fake_hostent(const char *name, int family,
   /* Fill in the rest of the host structure and terminate the query. */
   addrs[1] = NULL;
   hostent.h_aliases = aliases;
-  hostent.h_addrtype = family;
+  hostent.h_addrtype = aresx_sitoss(family);
   hostent.h_addr_list = addrs;
   callback(arg, ARES_SUCCESS, 0, &hostent);
 
@@ -349,7 +342,7 @@ static int file_lookup(const char *name, int family, struct hostent **host)
 
   PATH_HOSTS[0] = '\0';
 
-  platform = getplatform();
+  platform = ares__getplatform();
 
   if (platform == WIN_NT) {
     char tmp[MAX_PATH];
@@ -467,8 +460,8 @@ static int get_address_index(const struct in_addr *addr,
         }
       else
         {
-          if (!ares_bitncmp(&addr->s_addr, &sortlist[i].addrV4.s_addr,
-                            sortlist[i].mask.bits))
+          if (!ares__bitncmp(&addr->s_addr, &sortlist[i].addrV4.s_addr,
+                             sortlist[i].mask.bits))
             break;
         }
     }
@@ -515,10 +508,8 @@ static int get6_address_index(const struct ares_in6_addr *addr,
     {
       if (sortlist[i].family != AF_INET6)
         continue;
-        if (!ares_bitncmp(addr,
-                          &sortlist[i].addrV6,
-                          sortlist[i].mask.bits))
-          break;
+      if (!ares__bitncmp(addr, &sortlist[i].addrV6, sortlist[i].mask.bits))
+        break;
     }
   return i;
 }