[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> 2003-10-31 Hrvoje Niksic <hniksic@xemacs.org>
* host.c (address_list_from_single): Removed. * host.c (address_list_from_single): Removed.

View File

@ -66,59 +66,39 @@ extern int errno;
#endif #endif
/** /* Fill SA as per the data in IP and PORT. SA shoult point to struct
* sockaddr_set_data sockaddr_storage if ENABLE_IPV6 is defined, to struct sockaddr_in
* otherwise. */
* 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.
*/
static void 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; case IPV4_ADDRESS:
sin->sin_family = AF_INET; {
sin->sin_port = htons (port); struct sockaddr_in *sin = (struct sockaddr_in *)sa;
if (addr == NULL) sin->sin_family = AF_INET;
sin->sin_addr.s_addr = INADDR_ANY; sin->sin_port = htons (port);
else sin->sin_addr = ADDRESS_IPV4_IN_ADDR (ip);
sin->sin_addr = ADDRESS_IPV4_IN_ADDR (addr); break;
} }
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
else if (addr->type == IPV6_ADDRESS) case IPV6_ADDRESS:
{ {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
sin6->sin6_family = AF_INET6; sin6->sin6_family = AF_INET6;
sin6->sin6_port = htons (port); sin6->sin6_port = htons (port);
/* #### How can ADDR be NULL? We have dereferenced it above by sin6->sin6_addr = ADDRESS_IPV6_IN6_ADDR (ip);
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);
#ifdef HAVE_SOCKADDR_IN6_SCOPE_ID #ifdef HAVE_SOCKADDR_IN6_SCOPE_ID
sin6->sin6_scope_id = ADDRESS_IPV6_SCOPE (addr); sin6->sin6_scope_id = ADDRESS_IPV6_SCOPE (ip);
#endif #endif
} break;
} }
#endif /* ENABLE_IPV6 */ #endif /* ENABLE_IPV6 */
else default:
abort (); abort ();
}
} }
/* Get the data of SA, specifically the IP address and the port. If /* 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 void
sockaddr_get_data (const struct sockaddr *sa, ip_address *ip, int *port) 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; case AF_INET:
if (ip) {
{ struct sockaddr_in *sin = (struct sockaddr_in *)sa;
ip->type = IPV4_ADDRESS; if (ip)
ADDRESS_IPV4_IN_ADDR (ip) = sin->sin_addr; {
} ip->type = IPV4_ADDRESS;
if (port) ADDRESS_IPV4_IN_ADDR (ip) = sin->sin_addr;
*port = ntohs (sin->sin_port); }
} if (port)
*port = ntohs (sin->sin_port);
break;
}
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
else if (sa->sa_family == AF_INET6) case AF_INET6:
{ {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
if (ip) if (ip)
{ {
ip->type = IPV6_ADDRESS; ip->type = IPV6_ADDRESS;
ADDRESS_IPV6_IN6_ADDR (ip) = sin6->sin6_addr; ADDRESS_IPV6_IN6_ADDR (ip) = sin6->sin6_addr;
#ifdef HAVE_SOCKADDR_IN6_SCOPE_ID #ifdef HAVE_SOCKADDR_IN6_SCOPE_ID
ADDRESS_IPV6_SCOPE (ip) = sin6->sin6_scope_id; ADDRESS_IPV6_SCOPE (ip) = sin6->sin6_scope_id;
#endif #endif
} }
if (port) if (port)
*port = ntohs (sin6->sin6_port); *port = ntohs (sin6->sin6_port);
break;
}
#endif
default:
abort ();
} }
#endif
else
abort ();
} }
/* Return the size of the sockaddr structure depending on its /* Return the size of the sockaddr structure depending on its