You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

78 lines
2.4 KiB

From 73ce7f40c81f7ef2647abe18df8f14c35c086c7e Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <pbonzini@redhat.com>
Date: Fri, 2 Aug 2013 14:19:29 +0200
Subject: [RHEL7 libiscsi PATCH 16/18] avoid casting struct sockaddr
On ARM, this produces a warning. Use a union instead.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry-picked from upstream commit 73ce7f40c81f7ef2647abe18df8f14c35c086c7e)
---
lib/socket.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/lib/socket.c b/lib/socket.c
index 5d98783..2c65a4a 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);
@@ -238,19 +245,22 @@ 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;
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;
default:
@@ -316,7 +325,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);
--
1.8.1.4