Published in <sxsn10qrwbj.fsf@florida.arsdigita.de>.
+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>
* ftp-ls.c (ftp_parse_vms_ls): Fix obvious memory leaks.
2001-12-11 Hrvoje Niksic <hniksic@arsdigita.com>
* ftp-ls.c (ftp_parse_vms_ls): Fix obvious memory leaks.
-#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. */
struct address_list {
int count; /* number of adrresses */
struct address_list {
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
work. */
int faulty; /* number of addresses known not to
work. */
-#define ADDR_LOCATION(al, index) ((al)->buffer + index * IP4_ADDRESS_LENGTH)
-
/* Get the bounds of the address list. */
void
/* Get the bounds of the address list. */
void
unsigned char *ip_store)
{
assert (index >= al->faulty && index < al->count);
unsigned char *ip_store)
{
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. */
return 1;
if (al1->count != al2->count)
return 0;
return 1;
if (al1->count != al2->count)
return 0;
- return 0 == memcmp (al1->buffer, al2->buffer,
- al1->count * IP4_ADDRESS_LENGTH);
+ return 0 == memcmp (al1->addresses, al2->addresses,
+ 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
while (h_addr_list[count])
++count;
assert (count > 0);
while (h_addr_list[count])
++count;
assert (count > 0);
- al->count = count;
- al->faulty = 0;
- al->buffer = xmalloc (count * IP4_ADDRESS_LENGTH);
- al->refcount = 1;
+ al->count = count;
+ al->faulty = 0;
+ al->addresses = xmalloc (count * sizeof (ipv4_address));
+ 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));
address_list_new_one (const char *addr)
{
struct address_list *al = xmalloc (sizeof (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);
+ al->count = 1;
+ al->faulty = 0;
+ al->addresses = xmalloc (sizeof (ipv4_address));
+ al->refcount = 1;
+ memcpy (al->addresses, addr, sizeof (ipv4_address));
static void
address_list_delete (struct address_list *al)
{
static void
address_list_delete (struct address_list *al)
{
#including the netinet stuff. */
char *
#including the netinet stuff. */
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);
}
int i;
debug_logprintf ("Caching %s =>", host);
for (i = 0; i < al->count; i++)
int i;
debug_logprintf ("Caching %s =>", host);
for (i = 0; i < al->count; i++)
- debug_logprintf (" %s",
- pretty_print_address (ADDR_LOCATION (al, i)));
+ debug_logprintf (" %s", pretty_print_address (al->addresses + i));
debug_logprintf ("\n");
}
#endif
debug_logprintf ("\n");
}
#endif
we copy the correct four bytes. */
int offset;
#ifdef WORDS_BIGENDIAN
we copy the correct four bytes. */
int offset;
#ifdef WORDS_BIGENDIAN
- offset = sizeof (unsigned long) - IP4_ADDRESS_LENGTH;
+ offset = sizeof (unsigned long) - sizeof (ipv4_address);
/* This was originally going to be a macro, but then every caller
would have to #include the netinet stuff. */
/* This was originally going to be a macro, but then every caller
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 sufmatch PARAMS ((const char **, const char *));
int accept_domain PARAMS ((struct url *));
int sufmatch PARAMS ((const char **, const char *));