[stgt] [PATCH 10/15] tgt: os.h: getnameinfo() is different on none-Linux systems

Boaz Harrosh bharrosh at panasas.com
Sun Mar 1 17:52:26 CET 2009


Systems other then Linux are more picky with the addr length
passed to getnameinfo. They expect it to be set from the
returned length of the call to getsockname. Use an
os_getsockname_ss, that is implemented diffrently for BSD
or Linux.

Both getsockname and getnameinfo might fail check for
errors.

Also added a couple of dprints in error cases.

Signed-off-by: Boaz Harrosh <bharrosh at panasas.com>
---
 usr/bsd/os.c       |    9 +++++++++
 usr/iscsi/iscsid.c |   22 +++++++++++++++++-----
 usr/linux/os.c     |    9 +++++++++
 usr/os.h           |    4 ++++
 4 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/usr/bsd/os.c b/usr/bsd/os.c
index d2dfdab..12d2ec4 100644
--- a/usr/bsd/os.c
+++ b/usr/bsd/os.c
@@ -53,3 +53,12 @@ int os_bind_ipc(int fd, struct sockaddr_un *addr, const char *ipc_name_space)
 
 	return bind(fd, (struct sockaddr *)addr, addr->sun_len);
 }
+
+int os_getnameinfo_ss(struct sockaddr_storage *ss, char *host, size_t hostlen,
+                      char *serv, size_t servlen, int flags)
+{
+	size_t slen = ((struct sockaddr *)&ss)->sa_len;
+
+	return getnameinfo((struct sockaddr *)ss, slen, host, hostlen,
+			   serv, servlen, flags);
+}
diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index bfaec87..3d0a976 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -39,6 +39,7 @@
 #include "driver.h"
 #include "scsi.h"
 #include "crc32c.h"
+#include "os.h"
 
 #define MAX_QUEUE_CMD	128
 
@@ -743,6 +744,7 @@ static void text_scan_text(struct iscsi_connection *conn)
 {
 	char *key, *value, *data;
 	int datasize;
+	int ret;
 
 	data = conn->req.data;
 	datasize = conn->req.datasize;
@@ -760,22 +762,32 @@ static void text_scan_text(struct iscsi_connection *conn)
 			blen = sizeof(buf);
 
 			slen = sizeof(ss);
-			conn->tp->ep_getsockname(conn, (struct sockaddr *) &ss,
-						 &slen);
+			ret = conn->tp->ep_getsockname(conn,
+						(struct sockaddr *) &ss, &slen);
+			if (ret)
+				eprintf("getsockname Faild=>%d\n", ret);
+
 			if (ss.ss_family == AF_INET6) {
 				*p++ = '[';
 				blen--;
 			}
 
-			slen = sizeof(ss);
-			getnameinfo((struct sockaddr *) &ss, slen, p, blen,
-				    NULL, 0, NI_NUMERICHOST);
+			ret = os_getnameinfo_ss(&ss, p, blen, NULL, 0,
+						NI_NUMERICHOST);
+			if (ret) {
+				eprintf("getnameinfo Faild=>%d: %s\n",
+					ret, gai_strerror(ret));
+				/* Let failure show in target traces */
+				strcpy(p, "getnameinfo_Faild");
+			}
 
 			p = buf + strlen(buf);
 
 			if (ss.ss_family == AF_INET6)
 				 *p++ = ']';
 
+			dprintf("getnameinfo => %s\n", buf);
+
 			sprintf(p, ":%d,1", ISCSI_LISTEN_PORT);
 			target_list_build(conn, buf,
 					  strcmp(value, "All") ? value : NULL);
diff --git a/usr/linux/os.c b/usr/linux/os.c
index 5b50aff..3392637 100644
--- a/usr/linux/os.c
+++ b/usr/linux/os.c
@@ -14,6 +14,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <inttypes.h>
+#include <netdb.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
@@ -105,3 +106,11 @@ int os_bind_ipc(int fd, struct sockaddr_un *addr, const char *ipc_name_space)
 
 	return bind(fd, (struct sockaddr *)addr, sizeof(*addr));
 }
+
+
+int os_getnameinfo_ss(struct sockaddr_storage *ss, char *host, size_t hostlen,
+                      char *serv, size_t servlen, int flags)
+{
+	return getnameinfo((struct sockaddr *)ss, sizeof(*ss), host, hostlen,
+			   serv, servlen, flags);
+}
diff --git a/usr/os.h b/usr/os.h
index 7c0c538..9908bb5 100644
--- a/usr/os.h
+++ b/usr/os.h
@@ -18,4 +18,8 @@ int os_blockdev_size(int fd, uint64_t *size);
 struct sockaddr_un;
 int os_bind_ipc(int fd, struct sockaddr_un *addr, const char *ipc_name_space);
 
+struct sockaddr_storage;
+int os_getnameinfo_ss(struct sockaddr_storage *ss, char *host, size_t hostlen,
+                      char *serv, size_t servlen, int flags);
+
 #endif /* ndef __TGT_OS_H__*/
-- 
1.6.0.6

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list