static bool test_ifaddrtoname(char *addr) { int ret; char addrname[100]; int len = 99; ret = opal_ifaddrtoname(addr, addrname, len); if (ret == OPAL_SUCCESS) { return true; } else { return false; } }
bool opal_ifislocal(const char *hostname) { #if OPAL_ENABLE_IPV6 char addrname[NI_MAXHOST]; /* should be larger than ADDRLEN, but I think they really mean IFNAMESIZE */ #else char addrname[ADDRLEN + 1]; #endif if (OPAL_SUCCESS == opal_ifaddrtoname(hostname, addrname, ADDRLEN)) { return true; } return false; }
/* * Find and assign system netmask for the address of the uDAPL BTL * module, but only if udapl_if_mask has not been set by the "--mca * btl_udapl_if_mask" parameter. This routine will either find * the system netmask or set the value to 0. * * @param udapl_btl (IN) BTL module * * @return OMPI_SUCCESS or OMPI_ERROR */ static int mca_btl_udapl_assign_netmask(mca_btl_udapl_module_t* udapl_btl) { struct sockaddr *saddr; struct sockaddr_in *btl_addr; char btl_addr_string[INET_ADDRSTRLEN]; char btl_ifname[INET_ADDRSTRLEN]; /* Setting if_mask to 0 informs future steps to assume all * addresses are reachable. */ udapl_btl->udapl_if_mask = 0; if (mca_btl_udapl_component.udapl_compare_subnet) { /* go get system netmask value */ /* use generic address to find address family */ saddr = (struct sockaddr *)&(udapl_btl->udapl_addr.addr); if (saddr->sa_family == AF_INET) { btl_addr = (struct sockaddr_in *)saddr; /* * Retrieve the netmask of the udapl btl address. To * accomplish this requires 4 steps and the use of an opal * utility. This same utility is used by the tcp oob. * Steps: * 1. Get string value of known udapl btl module address. * 2. Use string value to find the interface name of address. * 3. Use interface name to find its index. * 4. From the index get the netmask. */ /* retrieve string value of udapl btl address */ inet_ntop(AF_INET, (void *) &btl_addr->sin_addr, btl_addr_string, INET_ADDRSTRLEN); /* use address string to retrieve associated interface name */ if (OPAL_SUCCESS != opal_ifaddrtoname(btl_addr_string, btl_ifname, INET_ADDRSTRLEN)) { BTL_UDAPL_VERBOSE_HELP(VERBOSE_SHOW_HELP, ("help-mpi-btl-udapl.txt", "interface not found", true, ompi_process_info.nodename, btl_addr_string)); return OMPI_ERROR; } /* use interface name to retrieve index; then * use index to retrieve udapl btl address netmask */ if (OPAL_SUCCESS != opal_ifindextomask(opal_ifnametoindex(btl_ifname), &(udapl_btl->udapl_if_mask), sizeof(udapl_btl->udapl_if_mask))) { BTL_UDAPL_VERBOSE_HELP(VERBOSE_SHOW_HELP, ("help-mpi-btl-udapl.txt", "netmask not found", true, ompi_process_info.nodename, btl_addr_string)); return OMPI_ERROR; } /* report if_mask used by address */ BTL_UDAPL_VERBOSE_OUTPUT(VERBOSE_INFORM, ("uDAPL BTL address %s : if_mask = %d", btl_addr_string, udapl_btl->udapl_if_mask)); } else { /* current uDAPL BTL does not support IPv6 */ BTL_UDAPL_VERBOSE_HELP(VERBOSE_SHOW_HELP, ("help-mpi-btl-udapl.txt", "IPv4 only", true, ompi_process_info.nodename)); return OMPI_ERROR; } } return OMPI_SUCCESS; }