]> sjero.net Git - wget/blobdiff - src/host.c
[svn] Added (currently no-op) -4 and -6.
[wget] / src / host.c
index eb0897cdf20da455c641f8edec9d31085abb6dbc..3e29ad98bb5d9c95db7b10f809055269bb4fc6fa 100644 (file)
@@ -81,13 +81,6 @@ extern int h_errno;
 /* Mapping between known hosts and to lists of their addresses. */
 
 static struct hash_table *host_name_addresses_map;
-
-#ifdef ENABLE_IPV6
-/* The IP family to request when connecting to remote hosts.  This
-   should be moved to an entry in struct options when we implement the
-   --inet4/--inet6 flags.  */
-static int requested_family = AF_UNSPEC;
-#endif
 \f
 /* Lists of addresses.  This should eventually be extended to handle
    IPv6.  */
@@ -201,17 +194,10 @@ address_list_connected_p (const struct address_list *al)
 }
 
 #ifdef ENABLE_IPV6
-/**
-  * address_list_from_addrinfo
-  *
-  * This function transform an addrinfo links list in and address_list.
-  *
-  * Input:
-  * addrinfo*          Linked list of addrinfo
-  *
-  * Output:
-  * address_list*      New allocated address_list
-  */
+
+/* Create an address_list from the addresses in the given struct
+   addrinfo.  */
+
 static struct address_list *
 address_list_from_addrinfo (const struct addrinfo *ai)
 {
@@ -256,7 +242,9 @@ address_list_from_addrinfo (const struct addrinfo *ai)
   assert (ip - al->addresses == cnt);
   return al;
 }
-#else
+
+#else  /* not ENABLE_IPV6 */
+
 /* Create an address_list from a NULL-terminated vector of IPv4
    addresses.  This kind of vector is returned by gethostbyname.  */
 
@@ -284,7 +272,8 @@ address_list_from_ipv4_addresses (char **vec)
 
   return al;
 }
-#endif
+
+#endif /* not ENABLE_IPV6 */
 
 static void
 address_list_delete (struct address_list *al)
@@ -293,6 +282,10 @@ address_list_delete (struct address_list *al)
   xfree (al);
 }
 
+/* Mark the address list as being no longer in use.  This will reduce
+   its reference count which will cause the list to be freed when the
+   count reaches 0.  */
+
 void
 address_list_release (struct address_list *al)
 {
@@ -353,7 +346,7 @@ host_errstr (int error)
       || error == NO_RECOVERY
       || error == NO_DATA
       || error == NO_ADDRESS)
-    return _("Host not found");
+    return _("Unknown host");
   else if (error == TRY_AGAIN)
     /* Message modeled after what gai_strerror returns in similar
        circumstances.  */
@@ -493,12 +486,11 @@ lookup_host (const char *host, int silent)
 {
   struct address_list *al = NULL;
 
-  /* If we're not using getaddrinfo, first check if HOST names a
-     numeric IPv4 address.  This was necessary under old (e.g. Ultrix)
-     implementations of gethostbyname that couldn't handle numeric
-     addresses (!).  This is not done under IPv6 because getaddrinfo
-     always handles numeric addresses.  */
 #ifndef ENABLE_IPV6
+  /* If we're not using getaddrinfo, first check if HOST names a
+     numeric IPv4 address.  gethostbyname is not required to accept
+     dotted-decimal IPv4 addresses, and some older implementations
+     (e.g. the Ultrix one) indeed didn't.  */
   {
     uint32_t addr_ipv4 = (uint32_t)inet_addr (host);
     if (addr_ipv4 != (uint32_t) -1)
@@ -538,7 +530,8 @@ lookup_host (const char *host, int silent)
 
     xzero (hints);
     hints.ai_socktype = SOCK_STREAM;
-    hints.ai_family = requested_family;
+    hints.ai_family = AF_UNSPEC; /* #### should look at opt.ipv4_only
+                                   and opt.ipv6_only */
     hints.ai_flags = 0;
 
     err = getaddrinfo_with_timeout (host, NULL, &hints, &res, opt.dns_timeout);
@@ -551,6 +544,11 @@ lookup_host (const char *host, int silent)
       }
     al = address_list_from_addrinfo (res);
     freeaddrinfo (res);
+    if (!al)
+      {
+       logprintf (LOG_VERBOSE, _("failed: No IPv4/IPv6 addresses.\n"));
+       return NULL;
+      }
   }
 #else
   {
@@ -620,7 +618,8 @@ lookup_host_passive (const char *host)
 
   xzero (hints);
   hints.ai_socktype = SOCK_STREAM;
-  hints.ai_family = requested_family;
+  hints.ai_family = AF_UNSPEC; /* #### should look at opt.ipv4_only
+                                  and opt.ipv6_only */
   hints.ai_flags = AI_PASSIVE;
 
   err = getaddrinfo (host, NULL, &hints, &res);