From bd65937bf3d891db901137f88079d6d648b4573b Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Wed, 3 Jul 2013 21:41:36 +0000 Subject: [PATCH] If we enable ipv6, we resolve a hosts addresses and check them all against our local interfaces to determine if the given host is us. However, if we don't enable ipv6, we only checked the first address returned. This can cause us to incorrectly identify a hostname as "not us". Make -disable-ipv6 behave the same as --enable-ipv6 by checking all the returned addresses. This commit was SVN r28716. --- opal/util/if.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/opal/util/if.c b/opal/util/if.c index ca967a017f..bbf00e9e39 100644 --- a/opal/util/if.c +++ b/opal/util/if.c @@ -195,6 +195,7 @@ int opal_ifaddrtoname(const char* if_addr, char* if_name, int length) int error; struct addrinfo hints, *res = NULL, *r; #else + int i; in_addr_t inaddr; struct hostent *h; #endif @@ -253,22 +254,20 @@ int opal_ifaddrtoname(const char* if_addr, char* if_name, int length) freeaddrinfo (res); } #else - inaddr = inet_addr(if_addr); - - if (INADDR_NONE == inaddr) { - h = gethostbyname(if_addr); - if (0 == h) { - return OPAL_ERR_NOT_FOUND; - } - memcpy(&inaddr, h->h_addr, sizeof(inaddr)); + h = gethostbyname(if_addr); + if (0 == h) { + return OPAL_ERR_NOT_FOUND; } - for (intf = (opal_if_t*)opal_list_get_first(&opal_if_list); - intf != (opal_if_t*)opal_list_get_end(&opal_if_list); - intf = (opal_if_t*)opal_list_get_next(intf)) { - if (((struct sockaddr_in*) &intf->if_addr)->sin_addr.s_addr == inaddr) { - strncpy(if_name, intf->if_name, length); - return OPAL_SUCCESS; + for (i=0; NULL != h->h_addr_list[i]; i++) { + memcpy(&inaddr, h->h_addr_list[i], sizeof(inaddr)); + for (intf = (opal_if_t*)opal_list_get_first(&opal_if_list); + intf != (opal_if_t*)opal_list_get_end(&opal_if_list); + intf = (opal_if_t*)opal_list_get_next(intf)) { + if (((struct sockaddr_in*) &intf->if_addr)->sin_addr.s_addr == inaddr) { + strncpy(if_name, intf->if_name, length); + return OPAL_SUCCESS; + } } } #endif