]> sjero.net Git - wget/blobdiff - src/host.c
[svn] Minor fixes prompted by `lint'.
[wget] / src / host.c
index 691022b0115ec68c8316aea97d274394ed9c7349..e27383d6f44867ccf8c268fdd2456805579703c5 100644 (file)
@@ -1,5 +1,5 @@
-/* Dealing with host names.
-   Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
+/* Host name resolution and matching.
+   Copyright (C) 1995, 1996, 1997, 2000, 2001 Free Software Foundation, Inc.
 
 This file is part of GNU Wget.
 
@@ -59,11 +59,17 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 extern int errno;
 #endif
 
+#ifndef h_errno
+# ifndef __CYGWIN__
+extern int h_errno;
+# endif
+#endif
+
 #define IP4_ADDRESS_LENGTH 4
 
 /* Mapping between known hosts and to lists of their addresses. */
 
-struct hash_table *host_name_addresses_map;
+static struct hash_table *host_name_addresses_map;
 \f
 /* Lists of addresses.  This should eventually be extended to handle
    IPv6.  */
@@ -118,6 +124,13 @@ address_list_match_all (struct address_list *al1, struct address_list *al2)
 void
 address_list_set_faulty (struct address_list *al, int index)
 {
+#if 0
+  /* Warning: INDEX is unused, so this assumes that the address list
+     is traversed in order.  In the next release, either enable this
+     assert, or use INDEX.  */
+  assert (index == al->faulty);
+#endif
+
   ++al->faulty;
   if (al->faulty >= al->count)
     /* All addresses have been proven faulty.  Since there's not much
@@ -151,6 +164,21 @@ address_list_new (char **h_addr_list)
   return al;
 }
 
+/* Like address_list_new, but initialized with only one address. */
+
+static struct address_list *
+address_list_new_one (const char *addr)
+{
+  struct address_list *al = xmalloc (sizeof (struct address_list));
+  al->count    = 1;
+  al->faulty   = 0;
+  al->buffer   = xmalloc (IP4_ADDRESS_LENGTH);
+  al->refcount = 1;
+  memcpy (ADDR_LOCATION (al, 0), addr, IP4_ADDRESS_LENGTH);
+
+  return al;
+}
+
 static void
 address_list_delete (struct address_list *al)
 {
@@ -217,9 +245,6 @@ lookup_host (const char *host, int silent)
   addr = (unsigned long)inet_addr (host);
   if ((int)addr != -1)
     {
-      char tmpstore[IP4_ADDRESS_LENGTH];
-      char *lst[] = { tmpstore, NULL };
-
       /* ADDR is defined to be in network byte order, which is what
         this returns, so we can just copy it to STORE_IP.  However,
         on big endian 64-bit architectures the value will be stored
@@ -231,8 +256,7 @@ lookup_host (const char *host, int silent)
 #else
       offset = 0;
 #endif
-      memcpy (tmpstore, (char *)&addr + offset, IP4_ADDRESS_LENGTH);
-      return address_list_new (lst);
+      return address_list_new_one ((char *)&addr + offset);
     }
 
   /* By now we know that the host name we got is not of the form
@@ -250,9 +274,7 @@ lookup_host (const char *host, int silent)
   if (!silent)
     logprintf (LOG_VERBOSE, _("Resolving %s... "), host);
 
-  /* Look up the host using gethostbyname().  Note that we use
-     gethostbyname() rather than ngethostbyname(), because we already
-     know that the address is not numerical.  */
+  /* Look up the host using gethostbyname().  */
   hptr = gethostbyname (host);
   if (!hptr)
     {
@@ -264,6 +286,8 @@ lookup_host (const char *host, int silent)
   if (!silent)
     logprintf (LOG_VERBOSE, _("done.\n"));
 
+  /* Do all systems have h_addr_list, or is it a newer thing?  If the
+     latter, use address_list_new_one.  */
   al = address_list_new (hptr->h_addr_list);
 
   /* Cache the lookup information. */