]> sjero.net Git - wget/blobdiff - src/host.c
[svn] Generalize connect_with_timeout into run_with_timeout.
[wget] / src / host.c
index e9df830d68585b351e078495826a5a458a3279cd..45455bf023559e1ecf038840d74fd402d37901bb 100644 (file)
@@ -18,7 +18,10 @@ along with Wget; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include <config.h>
+
+#ifndef WINDOWS
 #include <netdb.h>
+#endif
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -101,7 +104,7 @@ address_list_get_bounds (struct address_list *al, int *start, int *end)
 void
 address_list_copy_one (struct address_list *al, int index, ip_address *ip_store)
 {
-  assert (index >= al->faulty && index < al->count && ip_store!=NULL );
+  assert (index >= al->faulty && index < al->count);
   memcpy (ip_store, al->addresses + index, sizeof (ip_address));
 }
 
@@ -173,7 +176,7 @@ address_list_from_addrinfo (struct addrinfo *ai)
   for (i = 0, ai = ai_head; ai; ai = ai->ai_next)
     if (ai->ai_family == AF_INET6) 
       {
-       struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)ai->ai_addr;
+       struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)ai->ai_addr;
        memcpy (al->addresses + i, &sin6->sin6_addr, 16);
        ++i;
       } 
@@ -205,7 +208,7 @@ address_list_new (char **h_addr_list)
   al->refcount  = 1;
 
   for (i = 0; i < count; i++)
-    memcpy (al->addresses + i, h_addr_list[i], sizeof (ip_address));
+    map_ipv4_to_ip ((ip4_address *)h_addr_list[i], al->addresses + i);
 
   return al;
 }
@@ -270,9 +273,15 @@ wget_sockaddr_set_address (wget_sockaddr *sa,
       sa->sin.sin_family = ip_family;
       sa->sin.sin_port = htons (port);
       if (addr == NULL) 
-       memset ((unsigned char*)&sa->sin.sin_addr, 0,    sizeof(ip_address));
-      else      
-       memcpy ((unsigned char*)&sa->sin.sin_addr, addr, sizeof(ip_address));
+       memset (&sa->sin.sin_addr, 0,      sizeof(ip4_address));
+      else
+       {
+         ip4_address addr4;
+         if (!map_ip_to_ipv4 (addr, &addr4))
+           /* should the callers have prevented this? */
+           abort ();
+         memcpy (&sa->sin.sin_addr, &addr4, sizeof(ip4_address));
+       }
       return;
     }
 #ifdef INET6
@@ -281,9 +290,9 @@ wget_sockaddr_set_address (wget_sockaddr *sa,
       sa->sin6.sin6_family = ip_family;
       sa->sin6.sin6_port = htons (port);
       if (addr == NULL) 
-       memset (&sa->sin6.sin6_addr, 0   , sizeof(ip_address));
+       memset (&sa->sin6.sin6_addr, 0   , 16);
       else          
-       memcpy (&sa->sin6.sin6_addr, addr, sizeof(ip_address));
+       memcpy (&sa->sin6.sin6_addr, addr, 16);
       return;
     }
 #endif  
@@ -521,7 +530,7 @@ lookup_host (const char *host, int silent)
         we copy the correct four bytes.  */
       int offset = 0;
 #ifdef WORDS_BIGENDIAN
-      offset = sizeof (unsigned long) - sizeof (ip_address);
+      offset = sizeof (unsigned long) - sizeof (ip4_address);
 #endif
       map_ipv4_to_ip ((ip4_address *)((char *)&addr_ipv4 + offset), &addr);
       return address_list_new_one (&addr);
@@ -542,13 +551,20 @@ lookup_host (const char *host, int silent)
   if (!silent)
     logprintf (LOG_VERBOSE, _("Resolving %s... "), host);
 
+  /* Host name lookup goes on below.  #### We should implement
+     getaddrinfo_with_timeout and gethostbyname_with_timeout the same
+     way connect.c implements connect_with_timeout.  */
+
 #ifdef INET6
   {
     struct addrinfo hints, *ai;
     int err;
 
     memset (&hints, 0, sizeof (hints));
-    hints.ai_family   = PF_UNSPEC;
+    if (ip_default_family == AF_INET)
+      hints.ai_family   = AF_INET;
+    else
+      hints.ai_family   = PF_UNSPEC;
     hints.ai_socktype = SOCK_STREAM;
     err = getaddrinfo (host, NULL, &hints, &ai);