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.

58 lines
2.0 KiB

From 179f6b33d43f26cbca133ff03fa1bacc7e8a6120 Mon Sep 17 00:00:00 2001
From: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Date: Sun, 8 Jan 2017 12:57:12 -0800
Subject: [PATCH] Fix IPV6
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
diff --git a/lib/socket.c b/lib/socket.c
index 926e474..41b68c0 100644
--- a/lib/socket.c
+++ b/lib/socket.c
@@ -188,6 +188,20 @@ static int iscsi_tcp_connect(struct iscsi_context *iscsi, union socket_address *
int socksize;
+ switch (ai_family) {
+ case AF_INET:
+ socksize = sizeof(struct sockaddr_in);
+ break;
+ case AF_INET6:
+ socksize = sizeof(struct sockaddr_in6);
+ break;
+ default:
+ iscsi_set_error(iscsi, "Unknown address family :%d. "
+ "Only IPv4/IPv6 supported so far.",
+ ai_family);
+ return -1;
+ }
+
iscsi->fd = socket(ai_family, SOCK_STREAM, 0);
if (iscsi->fd == -1) {
iscsi_set_error(iscsi, "Failed to open iscsi socket. "
@@ -246,8 +260,6 @@ static int iscsi_tcp_connect(struct iscsi_context *iscsi, union socket_address *
ISCSI_LOG(iscsi,3,"TCP_NODELAY set to 1");
}
- socksize = sizeof(struct sockaddr_in); // Work-around for now, need to fix it
-
if (connect(iscsi->fd, &sa->sa, socksize) != 0
&& errno != EINPROGRESS) {
iscsi_set_error(iscsi, "Connect failed with errno : "
@@ -332,6 +344,7 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
case AF_INET:
socksize = sizeof(struct sockaddr_in);
memcpy(&sa.sin, ai->ai_addr, socksize);
+ sa.sin.sin_family = AF_INET;
sa.sin.sin_port = htons(port);
#ifdef HAVE_SOCK_SIN_LEN
sa.sin.sin_len = socksize;
@@ -341,6 +354,7 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
case AF_INET6:
socksize = sizeof(struct sockaddr_in6);
memcpy(&sa.sin6, ai->ai_addr, socksize);
+ sa.sin6.sin6_family = AF_INET6;
sa.sin6.sin6_port = htons(port);
#ifdef HAVE_SOCK_SIN_LEN
sa.sin6.sin6_len = socksize;