1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Use a typedef for IPv4 address.

Published in <sxsn10qrwbj.fsf@florida.arsdigita.de>.
This commit is contained in:
hniksic 2001-12-11 00:32:58 -08:00
parent 5eb068a46a
commit 1dee527a56
3 changed files with 28 additions and 23 deletions

View File

@ -1,3 +1,10 @@
2001-12-11 Hrvoje Niksic <hniksic@arsdigita.com>
* host.c: New type ipv4_address. Use it consistently instead of
`unsigned char[4]' and `unsigned char *'.
(pretty_print_address): Accept a `const void *', to require even
less casting.
2001-12-11 Hrvoje Niksic <hniksic@arsdigita.com> 2001-12-11 Hrvoje Niksic <hniksic@arsdigita.com>
* ftp-ls.c (ftp_parse_vms_ls): Fix obvious memory leaks. * ftp-ls.c (ftp_parse_vms_ls): Fix obvious memory leaks.

View File

@ -65,7 +65,8 @@ extern int h_errno;
# endif # endif
#endif #endif
#define IP4_ADDRESS_LENGTH 4 /* An IPv4 address is simply a 4-byte quantity. */
typedef unsigned char ipv4_address[4];
/* Mapping between known hosts and to lists of their addresses. */ /* Mapping between known hosts and to lists of their addresses. */
@ -76,7 +77,7 @@ static struct hash_table *host_name_addresses_map;
struct address_list { struct address_list {
int count; /* number of adrresses */ int count; /* number of adrresses */
unsigned char *buffer; /* buffer which holds all of them. */ ipv4_address *addresses; /* pointer to the string of addresses */
int faulty; /* number of addresses known not to int faulty; /* number of addresses known not to
work. */ work. */
@ -84,8 +85,6 @@ struct address_list {
not. */ not. */
}; };
#define ADDR_LOCATION(al, index) ((al)->buffer + index * IP4_ADDRESS_LENGTH)
/* Get the bounds of the address list. */ /* Get the bounds of the address list. */
void void
@ -102,7 +101,7 @@ address_list_copy_one (struct address_list *al, int index,
unsigned char *ip_store) unsigned char *ip_store)
{ {
assert (index >= al->faulty && index < al->count); assert (index >= al->faulty && index < al->count);
memcpy (ip_store, ADDR_LOCATION (al, index), IP4_ADDRESS_LENGTH); memcpy (ip_store, al->addresses + index, sizeof (ipv4_address));
} }
/* Check whether two address lists have all their IPs in common. */ /* Check whether two address lists have all their IPs in common. */
@ -114,8 +113,8 @@ address_list_match_all (struct address_list *al1, struct address_list *al2)
return 1; return 1;
if (al1->count != al2->count) if (al1->count != al2->count)
return 0; return 0;
return 0 == memcmp (al1->buffer, al2->buffer, return 0 == memcmp (al1->addresses, al2->addresses,
al1->count * IP4_ADDRESS_LENGTH); al1->count * sizeof (ipv4_address));
} }
/* Mark the INDEXth element of AL as faulty, so that the next time /* Mark the INDEXth element of AL as faulty, so that the next time
@ -151,13 +150,13 @@ address_list_new (char **h_addr_list)
while (h_addr_list[count]) while (h_addr_list[count])
++count; ++count;
assert (count > 0); assert (count > 0);
al->count = count; al->count = count;
al->faulty = 0; al->faulty = 0;
al->buffer = xmalloc (count * IP4_ADDRESS_LENGTH); al->addresses = xmalloc (count * sizeof (ipv4_address));
al->refcount = 1; al->refcount = 1;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
memcpy (ADDR_LOCATION (al, i), h_addr_list[i], IP4_ADDRESS_LENGTH); memcpy (al->addresses + i, h_addr_list[i], sizeof (ipv4_address));
return al; return al;
} }
@ -168,11 +167,11 @@ static struct address_list *
address_list_new_one (const char *addr) address_list_new_one (const char *addr)
{ {
struct address_list *al = xmalloc (sizeof (struct address_list)); struct address_list *al = xmalloc (sizeof (struct address_list));
al->count = 1; al->count = 1;
al->faulty = 0; al->faulty = 0;
al->buffer = xmalloc (IP4_ADDRESS_LENGTH); al->addresses = xmalloc (sizeof (ipv4_address));
al->refcount = 1; al->refcount = 1;
memcpy (ADDR_LOCATION (al, 0), addr, IP4_ADDRESS_LENGTH); memcpy (al->addresses, addr, sizeof (ipv4_address));
return al; return al;
} }
@ -180,7 +179,7 @@ address_list_new_one (const char *addr)
static void static void
address_list_delete (struct address_list *al) address_list_delete (struct address_list *al)
{ {
xfree (al->buffer); xfree (al->addresses);
xfree (al); xfree (al);
} }
@ -200,7 +199,7 @@ address_list_release (struct address_list *al)
#including the netinet stuff. */ #including the netinet stuff. */
char * char *
pretty_print_address (const unsigned char *addr) pretty_print_address (const void *addr)
{ {
return inet_ntoa (*(struct in_addr *)addr); return inet_ntoa (*(struct in_addr *)addr);
} }
@ -224,8 +223,7 @@ cache_host_lookup (const char *host, struct address_list *al)
int i; int i;
debug_logprintf ("Caching %s =>", host); debug_logprintf ("Caching %s =>", host);
for (i = 0; i < al->count; i++) for (i = 0; i < al->count; i++)
debug_logprintf (" %s", debug_logprintf (" %s", pretty_print_address (al->addresses + i));
pretty_print_address (ADDR_LOCATION (al, i)));
debug_logprintf ("\n"); debug_logprintf ("\n");
} }
#endif #endif
@ -250,7 +248,7 @@ lookup_host (const char *host, int silent)
we copy the correct four bytes. */ we copy the correct four bytes. */
int offset; int offset;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
offset = sizeof (unsigned long) - IP4_ADDRESS_LENGTH; offset = sizeof (unsigned long) - sizeof (ipv4_address);
#else #else
offset = 0; offset = 0;
#endif #endif

View File

@ -37,7 +37,7 @@ void address_list_release PARAMS ((struct address_list *));
/* This was originally going to be a macro, but then every caller /* This was originally going to be a macro, but then every caller
would have to #include the netinet stuff. */ would have to #include the netinet stuff. */
char *pretty_print_address PARAMS ((const unsigned char *)); char *pretty_print_address PARAMS ((const void *));
int accept_domain PARAMS ((struct url *)); int accept_domain PARAMS ((struct url *));
int sufmatch PARAMS ((const char **, const char *)); int sufmatch PARAMS ((const char **, const char *));