[stgt] [PATCH 10/15 ver2] tgt: os.h: getnameinfo() is different on none-Linux systems
Boaz Harrosh
bharrosh at panasas.com
Mon Mar 2 17:07:01 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 eprints in error cases.
Signed-off-by: Boaz Harrosh <bharrosh at panasas.com>
---
usr/bsd/os.c | 9 +++++++++
usr/iscsi/iscsid.c | 21 ++++++++++++++++-----
usr/linux/os.c | 9 +++++++++
usr/os.h | 4 ++++
4 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/usr/bsd/os.c b/usr/bsd/os.c
index e9c2da8..2693399 100644
--- a/usr/bsd/os.c
+++ b/usr/bsd/os.c
@@ -62,3 +62,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..53b231f 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,31 @@ 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));
+ continue;
+ }
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 ca096b8..1803858 100644
--- a/usr/linux/os.c
+++ b/usr/linux/os.c
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
+#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
@@ -114,3 +115,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 35e8718..e72ce3a 100644
--- a/usr/os.h
+++ b/usr/os.h
@@ -22,4 +22,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