diff options
author | Amar Tumballi <amar@gluster.com> | 2011-06-08 23:37:46 +0000 |
---|---|---|
committer | Anand Avati <avati@gluster.com> | 2011-06-16 09:15:33 -0700 |
commit | a7a2b8218958579006778b1200a0e40125291e0f (patch) | |
tree | 61218fc536f77f8d68afa12874b5b47fee208397 /rpc/rpc-transport/socket/src | |
parent | e719518e561033af0ffd07d0c8ad7d777715fe89 (diff) |
build warning fixes
mainly fixes all the sockaddr related 'strict aliasing' warnings
Signed-off-by: Amar Tumballi <amar@gluster.com>
Signed-off-by: Anand Avati <avati@gluster.com>
BUG: 2550 (build warnings)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2550
Diffstat (limited to 'rpc/rpc-transport/socket/src')
-rw-r--r-- | rpc/rpc-transport/socket/src/name.c | 29 | ||||
-rw-r--r-- | rpc/rpc-transport/socket/src/socket.c | 13 |
2 files changed, 22 insertions, 20 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), diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c index 2948621fcca..681064d7989 100644 --- a/rpc/rpc-transport/socket/src/socket.c +++ b/rpc/rpc-transport/socket/src/socket.c @@ -1945,10 +1945,10 @@ socket_connect (rpc_transport_t *this, int port) int ret = -1; int sock = -1; socket_private_t *priv = NULL; - struct sockaddr_storage sockaddr = {0, }; socklen_t sockaddr_len = 0; glusterfs_ctx_t *ctx = NULL; sa_family_t sa_family = {0, }; + union gf_sock_union sock_union; GF_VALIDATE_OR_GOTO ("socket", this, err); GF_VALIDATE_OR_GOTO ("socket", this->private, err); @@ -1976,16 +1976,16 @@ socket_connect (rpc_transport_t *this, int port) goto err; } - ret = socket_client_get_remote_sockaddr (this, SA (&sockaddr), + ret = socket_client_get_remote_sockaddr (this, &sock_union.sa, &sockaddr_len, &sa_family); if (ret == -1) { /* logged inside client_get_remote_sockaddr */ goto err; } - if (port > 0) - ((struct sockaddr_in *) (&sockaddr))->sin_port = htons (port); - + if (port > 0) { + sock_union.sin.sin_port = htons (port); + } pthread_mutex_lock (&priv->lock); { if (priv->sock != -1) { @@ -1994,7 +1994,8 @@ socket_connect (rpc_transport_t *this, int port) goto unlock; } - memcpy (&this->peerinfo.sockaddr, &sockaddr, sockaddr_len); + memcpy (&this->peerinfo.sockaddr, &sock_union.storage, + sockaddr_len); this->peerinfo.sockaddr_len = sockaddr_len; priv->sock = socket (sa_family, SOCK_STREAM, 0); |