diff mbox

[2/7] windows: new version of getlocalipaddr not portable

Message ID 54347E5A035A054EAE9D05927FB467F9481A87D3@ORSMSX101.amr.corp.intel.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Arlin Davis July 5, 2012, 4:38 p.m. UTC
revert to the original getaddrinfo method for windows

Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>

---
 dapl/openib_common/util.c |  144 +++++++++++++++++++++++++++++++++------------
 1 files changed, 105 insertions(+), 39 deletions(-)

-- 
1.7.3
diff mbox

Patch

diff --git a/dapl/openib_common/util.c b/dapl/openib_common/util.c
index 06a6f3d..33629b8 100644
--- a/dapl/openib_common/util.c
+++ b/dapl/openib_common/util.c
@@ -75,6 +75,69 @@  release:
 	return hr;
 }
 
+DAT_RETURN getlocalipaddr(char *addr, int addr_len)
+{
+	struct sockaddr_in *sin;
+	struct addrinfo *res, hint, *ai;
+	int ret;
+	char hostname[256];
+	char *netdev = getenv("DAPL_SCM_NETDEV");
+
+retry:
+	/* use provided netdev instead of default hostname */
+	if (netdev != NULL) {
+		ret = getipaddr_netdev(netdev, addr, addr_len);
+		if (ret) {
+			dapl_log(DAPL_DBG_TYPE_ERR,
+				 " getlocalipaddr: NETDEV = %s"
+				 " but not configured on system? ERR = %s\n",
+				 netdev, strerror(ret));
+			return dapl_convert_errno(ret, "getlocalipaddr");
+		} else
+			return DAT_SUCCESS;
+	}
+
+	if (addr_len < sizeof(*sin)) {
+		return DAT_INTERNAL_ERROR;
+	}
+
+	ret = gethostname(hostname, 256);
+	if (ret)
+		return dapl_convert_errno(ret, "gethostname");
+
+	memset(&hint, 0, sizeof hint);
+	hint.ai_flags = AI_PASSIVE;
+	hint.ai_family = AF_INET;
+	hint.ai_socktype = SOCK_STREAM;
+	hint.ai_protocol = IPPROTO_TCP;
+
+	ret = getaddrinfo(hostname, NULL, &hint, &res);
+	if (ret) {
+		dapl_log(DAPL_DBG_TYPE_ERR,
+			 " getaddrinfo ERR: %d %s\n", ret, gai_strerror(ret));
+		return DAT_INVALID_ADDRESS;
+	}
+
+	ret = DAT_INVALID_ADDRESS;
+	for (ai = res; ai; ai = ai->ai_next) {
+		sin = (struct sockaddr_in *)ai->ai_addr;
+		if (*((uint32_t *) & sin->sin_addr) != htonl(0x7f000001)) {
+			*((struct sockaddr_in *)addr) = *sin;
+			ret = DAT_SUCCESS;
+			break;
+		}
+	}
+
+	freeaddrinfo(res);
+
+	/* only loopback found, retry netdev eth0 */
+	if (ret == DAT_INVALID_ADDRESS) {
+		netdev = "eth0";
+		goto retry;
+	}
+
+	return ret;
+}
 #else				// _WIN64 || WIN32
 
 /* Get IP address using network device name */
@@ -114,43 +177,6 @@  int getipaddr_netdev(char *name, char *addr, int addr_len)
 	close(skfd);
 	return ret;
 }
-#endif
-
-enum ibv_mtu dapl_ib_mtu(int mtu)
-{
-	switch (mtu) {
-	case 256:
-		return IBV_MTU_256;
-	case 512:
-		return IBV_MTU_512;
-	case 1024:
-		return IBV_MTU_1024;
-	case 2048:
-		return IBV_MTU_2048;
-	case 4096:
-		return IBV_MTU_4096;
-	default:
-		return IBV_MTU_1024;
-	}
-}
-
-char *dapl_ib_mtu_str(enum ibv_mtu mtu)
-{
-	switch (mtu) {
-	case IBV_MTU_256:
-		return "256";
-	case IBV_MTU_512:
-		return "512";
-	case IBV_MTU_1024:
-		return "1024";
-	case IBV_MTU_2048:
-		return "2048";
-	case IBV_MTU_4096:
-		return "4096";
-	default:
-		return "1024";
-	}
-}
 
 DAT_RETURN getlocalipaddr(char *addr, int addr_len)
 {
@@ -163,13 +189,13 @@  DAT_RETURN getlocalipaddr(char *addr, int addr_len)
 	/* use provided netdev instead of default hostname */
 	if (netdev != NULL) {
 		ret = getipaddr_netdev(netdev, addr, addr_len);
-		if (ret) {			
+		if (ret) {
 			dapl_log(DAPL_DBG_TYPE_ERR,
 				 " getlocalipaddr: NETDEV = %s"
 				 " but not configured on system? ERR = %s\n",
 				 netdev, strerror(ret));
 			return dapl_convert_errno(ret, "getlocalipaddr");
-		} else 
+		} else
 			return DAT_SUCCESS;
 	}
 
@@ -197,6 +223,46 @@  bail:
 	return dapl_convert_errno(ret, "getlocalipaddr");
 }
 
+#endif
+
+enum ibv_mtu dapl_ib_mtu(int mtu)
+{
+	switch (mtu) {
+	case 256:
+		return IBV_MTU_256;
+	case 512:
+		return IBV_MTU_512;
+	case 1024:
+		return IBV_MTU_1024;
+	case 2048:
+		return IBV_MTU_2048;
+	case 4096:
+		return IBV_MTU_4096;
+	default:
+		return IBV_MTU_1024;
+	}
+}
+
+char *dapl_ib_mtu_str(enum ibv_mtu mtu)
+{
+	switch (mtu) {
+	case IBV_MTU_256:
+		return "256";
+	case IBV_MTU_512:
+		return "512";
+	case IBV_MTU_1024:
+		return "1024";
+	case IBV_MTU_2048:
+		return "2048";
+	case IBV_MTU_4096:
+		return "4096";
+	default:
+		return "1024";
+	}
+}
+
+
+
 /*
  * dapls_ib_query_hca
  *