avoid casting struct sockaddr
On ARM, this produces a warning. Use a union instead. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
+15
-5
@@ -171,6 +171,12 @@ int set_tcp_syncnt(struct iscsi_context *iscsi)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
union socket_address {
|
||||||
|
struct sockaddr_in sin;
|
||||||
|
struct sockaddr_in6 sin6;
|
||||||
|
struct sockaddr sa;
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
||||||
iscsi_command_cb cb, void *private_data)
|
iscsi_command_cb cb, void *private_data)
|
||||||
@@ -179,6 +185,7 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
|||||||
char *str;
|
char *str;
|
||||||
char *addr, *host;
|
char *addr, *host;
|
||||||
struct addrinfo *ai = NULL;
|
struct addrinfo *ai = NULL;
|
||||||
|
union socket_address sa;
|
||||||
int socksize;
|
int socksize;
|
||||||
|
|
||||||
ISCSI_LOG(iscsi, 2, "connecting to portal %s",portal);
|
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);
|
iscsi_free(iscsi, addr);
|
||||||
|
|
||||||
|
memset(&sa, 0, sizeof(sa));
|
||||||
switch (ai->ai_family) {
|
switch (ai->ai_family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
socksize = sizeof(struct sockaddr_in);
|
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
|
#ifdef HAVE_SOCK_SIN_LEN
|
||||||
((struct sockaddr_in *)(ai->ai_addr))->sin_len = socksize;
|
sa.sin.sin_len = socksize;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_SOCKADDR_IN6
|
#ifdef HAVE_SOCKADDR_IN6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
socksize = sizeof(struct sockaddr_in6);
|
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
|
#ifdef HAVE_SOCK_SIN_LEN
|
||||||
((struct sockaddr_in6 *)(ai->ai_addr))->sin6_len = socksize;
|
sa.sin6.sin6_len = socksize;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
@@ -316,7 +326,7 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
|||||||
ISCSI_LOG(iscsi,3,"TCP_NODELAY set to 1");
|
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) {
|
&& errno != EINPROGRESS) {
|
||||||
iscsi_set_error(iscsi, "Connect failed with errno : "
|
iscsi_set_error(iscsi, "Connect failed with errno : "
|
||||||
"%s(%d)", strerror(errno), errno);
|
"%s(%d)", strerror(errno), errno);
|
||||||
|
|||||||
Reference in New Issue
Block a user