]> sjero.net Git - wget/commitdiff
[svn] Use address_list_new_one.
authorhniksic <devnull@localhost>
Mon, 3 Dec 2001 17:48:12 +0000 (09:48 -0800)
committerhniksic <devnull@localhost>
Mon, 3 Dec 2001 17:48:12 +0000 (09:48 -0800)
Published in <sxsbshgyz71.fsf@florida.arsdigita.de>.

src/ChangeLog
src/host.c

index 39a9a87ad56eefee813575e32bee39b9d550dd08..9096035b0dd1f0a74abcfd844fafd16265549b22 100644 (file)
@@ -1,3 +1,8 @@
+2001-12-03  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * host.c (address_list_new_one): New function.
+       (lookup_host): Use it.
+
 2001-12-03  Andre Majorel  <amajorel@teaser.fr>
 
        * host.c (lookup_host): Don't initialize TMPSTORE directly because
index 7285cfb6a5b713181bcf149ac8ff4e229aa8c649..9fecb5d4081daf8fd48762d7f5ea157aba136bd4 100644 (file)
@@ -157,6 +157,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)
 {
@@ -223,9 +238,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[2];
-
       /* 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
@@ -237,10 +249,7 @@ lookup_host (const char *host, int silent)
 #else
       offset = 0;
 #endif
-      memcpy (tmpstore, (char *)&addr + offset, IP4_ADDRESS_LENGTH);
-      lst[0] = tmpstore;
-      lst[1] = NULL;
-      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
@@ -270,6 +279,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. */