Skip to content

Commit a52071a

Browse files
author
Ralph Castain
committed
Add a function to return the aliases (based on IP addrs) for the current node
This commit was SVN r27618.
1 parent 657225f commit a52071a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

opal/util/if.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,41 @@ int opal_ifmatches(int idx, char **nets)
659659
return OPAL_ERR_NOT_FOUND;
660660
}
661661

662+
void opal_ifgetaliases(char ***aliases)
663+
{
664+
opal_if_t* intf;
665+
char ipv4[INET_ADDRSTRLEN];
666+
struct sockaddr_in *addr;
667+
#if OPAL_ENABLE_IPV6
668+
char ipv6[INET6_ADDRSTRLEN];
669+
struct sockaddr_in6 *addr6;
670+
#endif
671+
672+
if (OPAL_SUCCESS != opal_if_base_open()) {
673+
return;
674+
}
675+
676+
for (intf = (opal_if_t*)opal_list_get_first(&opal_if_list);
677+
intf != (opal_if_t*)opal_list_get_end(&opal_if_list);
678+
intf = (opal_if_t*)opal_list_get_next(intf)) {
679+
addr = (struct sockaddr_in*) &intf->if_addr;
680+
/* ignore purely loopback interfaces */
681+
if ((intf->if_flags & IFF_LOOPBACK) != 0) {
682+
continue;
683+
}
684+
if (addr->sin_family == AF_INET) {
685+
inet_ntop(AF_INET, &(addr->sin_addr.s_addr), ipv4, INET_ADDRSTRLEN);
686+
opal_argv_append_nosize(aliases, ipv4);
687+
}
688+
#if OPAL_ENABLE_IPV6
689+
else {
690+
addr6 = (struct sockaddr_in6*) &intf->if_addr;
691+
inet_ntop(AF_INET6, &(addr6->sin6_addr), ipv6, INET6_ADDRSTRLEN);
692+
opal_argv_append_nosize(aliases, ipv6);
693+
}
694+
#endif
695+
}
696+
}
662697

663698
#else /* HAVE_STRUCT_SOCKADDR_IN */
664699

@@ -756,5 +791,9 @@ int opal_ifmatches(int idx, char **nets)
756791
return OPAL_ERR_NOT_SUPPORTED;
757792
}
758793

794+
void opal_ifgetaliases(char ***aliases)
795+
{
796+
}
797+
759798
#endif /* HAVE_STRUCT_SOCKADDR_IN */
760799

opal/util/if.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ OPAL_DECLSPEC bool opal_ifisloopback(int if_index);
193193
*/
194194
OPAL_DECLSPEC int opal_ifmatches(int idx, char **nets);
195195

196+
/*
197+
* Provide a list of strings that contain all known aliases for this node
198+
*/
199+
OPAL_DECLSPEC void opal_ifgetaliases(char ***aliases);
200+
196201
END_C_DECLS
197202

198203
#endif

0 commit comments

Comments
 (0)