[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,60 +66,40 @@ 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)
{
case IPV4_ADDRESS:
{ {
struct sockaddr_in *sin = (struct sockaddr_in *)sa; struct sockaddr_in *sin = (struct sockaddr_in *)sa;
sin->sin_family = AF_INET; sin->sin_family = AF_INET;
sin->sin_port = htons (port); sin->sin_port = htons (port);
if (addr == NULL) sin->sin_addr = ADDRESS_IPV4_IN_ADDR (ip);
sin->sin_addr.s_addr = INADDR_ANY; break;
else
sin->sin_addr = ADDRESS_IPV4_IN_ADDR (addr);
} }
#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
you're not interested in one or the other information, pass NULL as you're not interested in one or the other information, pass NULL as
@ -128,7 +108,9 @@ 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)
{
case AF_INET:
{ {
struct sockaddr_in *sin = (struct sockaddr_in *)sa; struct sockaddr_in *sin = (struct sockaddr_in *)sa;
if (ip) if (ip)
@ -138,9 +120,10 @@ sockaddr_get_data (const struct sockaddr *sa, ip_address *ip, int *port)
} }
if (port) if (port)
*port = ntohs (sin->sin_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)
@ -153,11 +136,13 @@ sockaddr_get_data (const struct sockaddr *sa, ip_address *ip, int *port)
} }
if (port) if (port)
*port = ntohs (sin6->sin6_port); *port = ntohs (sin6->sin6_port);
break;
} }
#endif #endif
else default:
abort (); abort ();
} }
}
/* Return the size of the sockaddr structure depending on its /* Return the size of the sockaddr structure depending on its
family. */ family. */