1
1

no need to call gethostname twice to determine if a process is local

This commit was SVN r15742.
Этот коммит содержится в:
Brian Barrett 2007-08-02 16:25:25 +00:00
родитель d3f008492f
Коммит 951755f9fb

Просмотреть файл

@ -933,8 +933,6 @@ int opal_ifaddrtoname(const char* if_addr, char* if_name, int length)
error = getaddrinfo(if_addr, NULL, &hints, &res); error = getaddrinfo(if_addr, NULL, &hints, &res);
if (error) { if (error) {
opal_output (0, "opal_ifaddrtoname: unable to resolve %s [Error: %s]\n",
if_addr, gai_strerror (error));
freeaddrinfo (res); freeaddrinfo (res);
return OPAL_ERR_NOT_FOUND; return OPAL_ERR_NOT_FOUND;
} }
@ -971,7 +969,6 @@ int opal_ifaddrtoname(const char* if_addr, char* if_name, int length)
if(INADDR_NONE == inaddr) { if(INADDR_NONE == inaddr) {
h = gethostbyname(if_addr); h = gethostbyname(if_addr);
if(0 == h) { if(0 == h) {
opal_output(0,"opal_ifaddrtoname: unable to resolve %s\n", if_addr);
return OPAL_ERR_NOT_FOUND; return OPAL_ERR_NOT_FOUND;
} }
memcpy(&inaddr, h->h_addr, sizeof(inaddr)); memcpy(&inaddr, h->h_addr, sizeof(inaddr));
@ -1179,35 +1176,13 @@ opal_ifislocal(const char *hostname)
#if OPAL_WANT_IPV6 #if OPAL_WANT_IPV6
char addrname[NI_MAXHOST]; /* should be larger than ADDRLEN, but I think char addrname[NI_MAXHOST]; /* should be larger than ADDRLEN, but I think
they really mean IFNAMESIZE */ they really mean IFNAMESIZE */
struct addrinfo hints, *res = NULL;
int error;
#else #else
char addrname[ADDRLEN + 1]; char addrname[ADDRLEN + 1];
struct hostent *h;
#endif #endif
/* opal_ifaddrtoname will complain (rightly) if hostname is not
resolveable. check to make sure it's resolveable. If not,
definitely not local... */
#if OPAL_WANT_IPV6
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(hostname, NULL, &hints, &res);
if (NULL != res) {
freeaddrinfo (res);
}
if (error) {
return false;
}
#else
h = gethostbyname(hostname);
if (NULL == h) return false;
#endif
ret = opal_ifaddrtoname(hostname, addrname, ADDRLEN); ret = opal_ifaddrtoname(hostname, addrname, ADDRLEN);
if (OPAL_SUCCESS == ret) return true;
return false; return (OPAL_SUCCESS == ret) ? true : false;
} }