diff options
Diffstat (limited to 'rpc/rpc-transport/socket/src/name.c')
-rw-r--r-- | rpc/rpc-transport/socket/src/name.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/rpc/rpc-transport/socket/src/name.c b/rpc/rpc-transport/socket/src/name.c index d310b0f8a4a..a9813998e1c 100644 --- a/rpc/rpc-transport/socket/src/name.c +++ b/rpc/rpc-transport/socket/src/name.c @@ -36,6 +36,7 @@ #include "rpc-transport.h" #include "socket.h" +#include "common-utils.h" int32_t gf_resolve_ip6 (const char *hostname, @@ -604,7 +605,7 @@ int32_t fill_inet6_inet_identifiers (rpc_transport_t *this, struct sockaddr_storage *addr, int32_t addr_len, char *identifier) { - struct sockaddr_storage tmpaddr; + union gf_sock_union sock_union; char service[NI_MAXSERV] = {0,}; char host[NI_MAXHOST] = {0,}; @@ -616,26 +617,26 @@ fill_inet6_inet_identifiers (rpc_transport_t *this, struct sockaddr_storage *add int16_t eight_to_ten = 0; int16_t ten_to_twelve = 0; - memset (&tmpaddr, 0, sizeof (tmpaddr)); - tmpaddr = *addr; + memset (&sock_union, 0, sizeof (sock_union)); + sock_union.storage = *addr; tmpaddr_len = addr_len; - if (((struct sockaddr *) &tmpaddr)->sa_family == AF_INET6) { - one_to_four = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr32[0]; - four_to_eight = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr32[1]; + if (sock_union.sa.sa_family == AF_INET6) { + one_to_four = sock_union.sin6.sin6_addr.s6_addr32[0]; + four_to_eight = sock_union.sin6.sin6_addr.s6_addr32[1]; #ifdef GF_SOLARIS_HOST_OS - eight_to_ten = S6_ADDR16(((struct sockaddr_in6 *) &tmpaddr)->sin6_addr)[4]; + eight_to_ten = S6_ADDR16(sock_union.sin6.sin6_addr)[4]; #else - eight_to_ten = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr16[4]; + eight_to_ten = sock_union.sin6.sin6_addr.s6_addr16[4]; #endif #ifdef GF_SOLARIS_HOST_OS - ten_to_twelve = S6_ADDR16(((struct sockaddr_in6 *) &tmpaddr)->sin6_addr)[5]; + ten_to_twelve = S6_ADDR16(sock_union.sin6.sin6_addr)[5]; #else - ten_to_twelve = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr16[5]; + ten_to_twelve = sock_union.sin6.sin6_addr.s6_addr16[5]; #endif - twelve_to_sixteen = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr32[3]; + twelve_to_sixteen = sock_union.sin6.sin6_addr.s6_addr32[3]; /* ipv4 mapped ipv6 address has bits 0-80: 0 @@ -647,8 +648,8 @@ fill_inet6_inet_identifiers (rpc_transport_t *this, struct sockaddr_storage *add four_to_eight == 0 && eight_to_ten == 0 && ten_to_twelve == -1) { - struct sockaddr_in *in_ptr = (struct sockaddr_in *)&tmpaddr; - memset (&tmpaddr, 0, sizeof (tmpaddr)); + struct sockaddr_in *in_ptr = &sock_union.sin; + memset (&sock_union, 0, sizeof (sock_union)); in_ptr->sin_family = AF_INET; in_ptr->sin_port = ((struct sockaddr_in6 *)addr)->sin6_port; @@ -657,7 +658,7 @@ fill_inet6_inet_identifiers (rpc_transport_t *this, struct sockaddr_storage *add } } - ret = getnameinfo ((struct sockaddr *) &tmpaddr, + ret = getnameinfo (&sock_union.sa, tmpaddr_len, host, sizeof (host), service, sizeof (service), |