From 31a3aeb0e0167401a7c10f4cba95a72697f907c0 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 2 Aug 2013 14:07:42 +0200 Subject: [PATCH 1/2] fix another aliasing problem scsi_set_uint64 should just use scsi_set_uint32, similar to what scsi_get_uint64 does. This avoids problems on architectures where "uint32_t" requires more alignment than "char", e.g. ARM. Signed-off-by: Paolo Bonzini --- lib/scsi-lowlevel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 0989f0f..1bb03af 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -300,11 +300,11 @@ scsi_set_uint64(unsigned char *c, uint64_t v) uint32_t val; val = (v >> 32) & 0xffffffff; - *(uint32_t *)c = htonl(val); + scsi_set_uint32(c, val); c += 4; val = v & 0xffffffff; - *(uint32_t *)c = htonl(val); + scsi_set_uint32(c, val); } inline void From 73ce7f40c81f7ef2647abe18df8f14c35c086c7e Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 2 Aug 2013 14:19:29 +0200 Subject: [PATCH 2/2] avoid casting struct sockaddr On ARM, this produces a warning. Use a union instead. Signed-off-by: Paolo Bonzini --- lib/socket.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/socket.c b/lib/socket.c index 5d98783..1605065 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -171,6 +171,12 @@ int set_tcp_syncnt(struct iscsi_context *iscsi) return 0; } +union socket_address { + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + struct sockaddr sa; +}; + int iscsi_connect_async(struct iscsi_context *iscsi, const char *portal, iscsi_command_cb cb, void *private_data) @@ -179,6 +185,7 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal, char *str; char *addr, *host; struct addrinfo *ai = NULL; + union socket_address sa; int socksize; ISCSI_LOG(iscsi, 2, "connecting to portal %s",portal); @@ -235,20 +242,23 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal, } iscsi_free(iscsi, addr); + memset(&sa, 0, sizeof(sa)); switch (ai->ai_family) { case AF_INET: socksize = sizeof(struct sockaddr_in); - ((struct sockaddr_in *)(ai->ai_addr))->sin_port = htons(port); + memcpy(&sa.sin, ai->ai_addr, socksize); + sa.sin.sin_port = htons(port); #ifdef HAVE_SOCK_SIN_LEN - ((struct sockaddr_in *)(ai->ai_addr))->sin_len = socksize; + sa.sin.sin_len = socksize; #endif break; #ifdef HAVE_SOCKADDR_IN6 case AF_INET6: socksize = sizeof(struct sockaddr_in6); - ((struct sockaddr_in6 *)(ai->ai_addr))->sin6_port = htons(port); + memcpy(&sa.sin6, ai->ai_addr, socksize); + sa.sin6.sin6_port = htons(port); #ifdef HAVE_SOCK_SIN_LEN - ((struct sockaddr_in6 *)(ai->ai_addr))->sin6_len = socksize; + sa.sin6.sin6_len = socksize; #endif break; #endif @@ -316,7 +326,7 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal, ISCSI_LOG(iscsi,3,"TCP_NODELAY set to 1"); } - if (connect(iscsi->fd, ai->ai_addr, socksize) != 0 + if (connect(iscsi->fd, &sa.sa, socksize) != 0 && errno != EINPROGRESS) { iscsi_set_error(iscsi, "Connect failed with errno : " "%s(%d)", strerror(errno), errno);