summaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2011-06-08 23:37:46 +0000
committerAnand Avati <avati@gluster.com>2011-06-16 09:15:33 -0700
commita7a2b8218958579006778b1200a0e40125291e0f (patch)
tree61218fc536f77f8d68afa12874b5b47fee208397 /rpc
parente719518e561033af0ffd07d0c8ad7d777715fe89 (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')
-rw-r--r--rpc/rpc-transport/rdma/src/name.c35
-rw-r--r--rpc/rpc-transport/rdma/src/rdma.c28
-rw-r--r--rpc/rpc-transport/socket/src/name.c29
-rw-r--r--rpc/rpc-transport/socket/src/socket.c13
4 files changed, 48 insertions, 57 deletions
diff --git a/rpc/rpc-transport/rdma/src/name.c b/rpc/rpc-transport/rdma/src/name.c
index bc9b97e90..53c8db9b1 100644
--- a/rpc/rpc-transport/rdma/src/name.c
+++ b/rpc/rpc-transport/rdma/src/name.c
@@ -577,40 +577,33 @@ fill_inet6_inet_identifiers (rpc_transport_t *this, struct sockaddr_storage *add
{
int32_t ret = 0, tmpaddr_len = 0;
char service[NI_MAXSERV], host[NI_MAXHOST];
- struct sockaddr_storage tmpaddr;
+ union gf_sock_union sock_union;
- 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) {
+ if (sock_union.sa.sa_family == AF_INET6) {
int32_t one_to_four, four_to_eight, twelve_to_sixteen;
int16_t eight_to_ten, ten_to_twelve;
one_to_four = four_to_eight = twelve_to_sixteen = 0;
eight_to_ten = ten_to_twelve = 0;
- one_to_four = ((struct sockaddr_in6 *)
- &tmpaddr)->sin6_addr.s6_addr32[0];
- four_to_eight = ((struct sockaddr_in6 *)
- &tmpaddr)->sin6_addr.s6_addr32[1];
+ 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
@@ -622,8 +615,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;
@@ -632,7 +625,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/rdma/src/rdma.c b/rpc/rpc-transport/rdma/src/rdma.c
index d27beaf1c..c0b7e7bf2 100644
--- a/rpc/rpc-transport/rdma/src/rdma.c
+++ b/rpc/rpc-transport/rdma/src/rdma.c
@@ -4501,7 +4501,7 @@ rdma_connect (struct rpc_transport *this, int port)
int32_t ret = 0;
gf_boolean_t non_blocking = 1;
- struct sockaddr_storage sockaddr;
+ union gf_sock_union sock_union;
socklen_t sockaddr_len = 0;
if (dict_get (options, "non-blocking-io")) {
@@ -4517,7 +4517,7 @@ rdma_connect (struct rpc_transport *this, int port)
}
ret = gf_rdma_client_get_remote_sockaddr (this,
- (struct sockaddr *)&sockaddr,
+ &sock_union.sa,
&sockaddr_len, port);
if (ret != 0) {
gf_log (this->name, GF_LOG_DEBUG,
@@ -4532,8 +4532,7 @@ rdma_connect (struct rpc_transport *this, int port)
goto unlock;
}
- priv->sock = socket (((struct sockaddr *)&sockaddr)->sa_family,
- SOCK_STREAM, 0);
+ priv->sock = socket (sock_union.sa.sa_family, SOCK_STREAM, 0);
if (priv->sock == -1) {
gf_log (this->name, GF_LOG_ERROR,
@@ -4545,12 +4544,12 @@ rdma_connect (struct rpc_transport *this, int port)
gf_log (this->name, GF_LOG_TRACE,
"socket fd = %d", priv->sock);
- memcpy (&this->peerinfo.sockaddr, &sockaddr, sockaddr_len);
+ memcpy (&this->peerinfo.sockaddr, &sock_union.storage,
+ sockaddr_len);
this->peerinfo.sockaddr_len = sockaddr_len;
if (port > 0)
- ((struct sockaddr_in *) (&sockaddr))->sin_port
- = htons (port);
+ sock_union.sin.sin_port = htons (port);
((struct sockaddr *) &this->myinfo.sockaddr)->sa_family =
((struct sockaddr *)&this->peerinfo.sockaddr)->sa_family;
@@ -4713,15 +4712,15 @@ rdma_server_event_handler (int fd, int idx, void *data,
static int32_t
rdma_listen (rpc_transport_t *this)
{
- struct sockaddr_storage sockaddr;
+ union gf_sock_union sock_union;
socklen_t sockaddr_len;
rdma_private_t *priv = this->private;
int opt = 1, ret = 0;
char service[NI_MAXSERV], host[NI_MAXHOST];
- memset (&sockaddr, 0, sizeof (sockaddr));
+ memset (&sock_union, 0, sizeof (sock_union));
ret = gf_rdma_server_get_local_sockaddr (this,
- (struct sockaddr *)&sockaddr,
+ &sock_union.sa,
&sockaddr_len);
if (ret != 0) {
gf_log (this->name, GF_LOG_DEBUG,
@@ -4729,8 +4728,7 @@ rdma_listen (rpc_transport_t *this)
goto err;
}
- priv->sock = socket (((struct sockaddr *)&sockaddr)->sa_family,
- SOCK_STREAM, 0);
+ priv->sock = socket (sock_union.sa.sa_family, SOCK_STREAM, 0);
if (priv->sock == -1) {
gf_log ("rdma/server", GF_LOG_CRITICAL,
"init: failed to create socket, error: %s",
@@ -4740,7 +4738,7 @@ rdma_listen (rpc_transport_t *this)
goto err;
}
- memcpy (&this->myinfo.sockaddr, &sockaddr, sockaddr_len);
+ memcpy (&this->myinfo.sockaddr, &sock_union.storage, sockaddr_len);
this->myinfo.sockaddr_len = sockaddr_len;
ret = getnameinfo ((struct sockaddr *)&this->myinfo.sockaddr,
@@ -4756,9 +4754,7 @@ rdma_listen (rpc_transport_t *this)
sprintf (this->myinfo.identifier, "%s:%s", host, service);
setsockopt (priv->sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt));
- if (bind (priv->sock,
- (struct sockaddr *)&sockaddr,
- sockaddr_len) != 0) {
+ if (bind (priv->sock, &sock_union.sa, sockaddr_len) != 0) {
ret = -1;
gf_log ("rdma/server", GF_LOG_ERROR,
"init: failed to bind to socket for %s (%s)",
diff --git a/rpc/rpc-transport/socket/src/name.c b/rpc/rpc-transport/socket/src/name.c
index d310b0f8a..a9813998e 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 2948621fc..681064d79 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);