From 29a338cc58d672efc5450e66a140f26b791d3538 Mon Sep 17 00:00:00 2001 From: hniksic Date: Mon, 3 Dec 2001 09:48:12 -0800 Subject: [PATCH] [svn] Use address_list_new_one. Published in . --- src/ChangeLog | 5 +++++ src/host.c | 25 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 39a9a87a..9096035b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2001-12-03 Hrvoje Niksic + + * host.c (address_list_new_one): New function. + (lookup_host): Use it. + 2001-12-03 Andre Majorel * host.c (lookup_host): Don't initialize TMPSTORE directly because diff --git a/src/host.c b/src/host.c index 7285cfb6..9fecb5d4 100644 --- a/src/host.c +++ b/src/host.c @@ -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. */