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

[svn] Retired broken code that checked for NULL ip_address in sockaddr_set_data.

This commit is contained in:
hniksic 2003-10-31 04:20:14 -08:00
parent dbe01ae695
commit 83e7fe2ca8
2 changed files with 60 additions and 70 deletions

View File

@ -1,3 +1,8 @@
2003-10-31 Hrvoje Niksic <hniksic@xemacs.org>
* connect.c (sockaddr_set_data): Remove the broken code that
checked for NULL address.
2003-10-31 Hrvoje Niksic <hniksic@xemacs.org>
* host.c (address_list_from_single): Removed.

View File

@ -66,59 +66,39 @@ extern int errno;
#endif
/**
* sockaddr_set_data
*
* This function takes a sockaddr struct and fills in the protocol
* type, the port number and the address. If ENABLE_IPV6 is defined,
* SA should really point to struct sockaddr_storage; otherwise, it
* should point to struct sockaddr_in.
*
* Input:
* struct sockaddr* The space to be filled
* const ip_address The IP address
* int The port
*
* Return:
* - Only modifies 1st parameter.
*/
/* Fill SA as per the data in IP and PORT. SA shoult point to struct
sockaddr_storage if ENABLE_IPV6 is defined, to struct sockaddr_in
otherwise. */
static void
sockaddr_set_data (struct sockaddr *sa, const ip_address *addr, int port)
sockaddr_set_data (struct sockaddr *sa, const ip_address *ip, int port)
{
if (addr->type == IPV4_ADDRESS)
switch (ip->type)
{
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
sin->sin_family = AF_INET;
sin->sin_port = htons (port);
if (addr == NULL)
sin->sin_addr.s_addr = INADDR_ANY;
else
sin->sin_addr = ADDRESS_IPV4_IN_ADDR (addr);
}
case IPV4_ADDRESS:
{
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
sin->sin_family = AF_INET;
sin->sin_port = htons (port);
sin->sin_addr = ADDRESS_IPV4_IN_ADDR (ip);
break;
}
#ifdef ENABLE_IPV6
else if (addr->type == IPV6_ADDRESS)
{
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
sin6->sin6_family = AF_INET6;
sin6->sin6_port = htons (port);
/* #### How can ADDR be NULL? We have dereferenced it above by
accessing addr->type! */
if (addr == NULL)
{
sin6->sin6_addr = in6addr_any;
/* #### Should we set the scope_id here? */
}
else
{
sin6->sin6_addr = ADDRESS_IPV6_IN6_ADDR (addr);
case IPV6_ADDRESS:
{
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
sin6->sin6_family = AF_INET6;
sin6->sin6_port = htons (port);
sin6->sin6_addr = ADDRESS_IPV6_IN6_ADDR (ip);
#ifdef HAVE_SOCKADDR_IN6_SCOPE_ID
sin6->sin6_scope_id = ADDRESS_IPV6_SCOPE (addr);
sin6->sin6_scope_id = ADDRESS_IPV6_SCOPE (ip);
#endif
}
}
break;
}
#endif /* ENABLE_IPV6 */
else
abort ();
default:
abort ();
}
}
/* Get the data of SA, specifically the IP address and the port. If
@ -128,35 +108,40 @@ sockaddr_set_data (struct sockaddr *sa, const ip_address *addr, int port)
void
sockaddr_get_data (const struct sockaddr *sa, ip_address *ip, int *port)
{
if (sa->sa_family == AF_INET)
switch (sa->sa_family)
{
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
if (ip)
{
ip->type = IPV4_ADDRESS;
ADDRESS_IPV4_IN_ADDR (ip) = sin->sin_addr;
}
if (port)
*port = ntohs (sin->sin_port);
}
case AF_INET:
{
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
if (ip)
{
ip->type = IPV4_ADDRESS;
ADDRESS_IPV4_IN_ADDR (ip) = sin->sin_addr;
}
if (port)
*port = ntohs (sin->sin_port);
break;
}
#ifdef ENABLE_IPV6
else if (sa->sa_family == AF_INET6)
{
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
if (ip)
{
ip->type = IPV6_ADDRESS;
ADDRESS_IPV6_IN6_ADDR (ip) = sin6->sin6_addr;
case AF_INET6:
{
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
if (ip)
{
ip->type = IPV6_ADDRESS;
ADDRESS_IPV6_IN6_ADDR (ip) = sin6->sin6_addr;
#ifdef HAVE_SOCKADDR_IN6_SCOPE_ID
ADDRESS_IPV6_SCOPE (ip) = sin6->sin6_scope_id;
ADDRESS_IPV6_SCOPE (ip) = sin6->sin6_scope_id;
#endif
}
if (port)
*port = ntohs (sin6->sin6_port);
}
if (port)
*port = ntohs (sin6->sin6_port);
break;
}
#endif
default:
abort ();
}
#endif
else
abort ();
}
/* Return the size of the sockaddr structure depending on its