diff --git a/src/source/Ice/Network.c b/src/source/Ice/Network.c index a695838da8..b5568bb97b 100644 --- a/src/source/Ice/Network.c +++ b/src/source/Ice/Network.c @@ -35,48 +35,51 @@ STATUS getLocalhostIpAddresses(PKvsIpAddress destIpList, PUINT32 pDestIpListLen, CHK(retWinStatus == ERROR_SUCCESS, STATUS_GET_LOCAL_IP_ADDRESSES_FAILED); for (aa = adapterAddresses; aa != NULL && ipCount < destIpListLen; aa = aa->Next) { - char ifa_name[BUFSIZ]; - memset(ifa_name, 0, BUFSIZ); - WideCharToMultiByte(CP_ACP, 0, aa->FriendlyName, wcslen(aa->FriendlyName), ifa_name, BUFSIZ, NULL, NULL); - - for (ua = aa->FirstUnicastAddress; ua != NULL; ua = ua->Next) { - if (filter != NULL) { - DLOGI("Callback set to allow network interface filtering"); - // The callback evaluates to a FALSE if the application is interested in black listing an interface - if (filter(customData, ifa_name) == FALSE) { - filterSet = FALSE; - } else { - filterSet = TRUE; + // Skip inactive interfaces and loop back interfaces + if (aa->OperStatus == IfOperStatusUp && aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) { + char ifa_name[BUFSIZ]; + memset(ifa_name, 0, BUFSIZ); + WideCharToMultiByte(CP_ACP, 0, aa->FriendlyName, wcslen(aa->FriendlyName), ifa_name, BUFSIZ, NULL, NULL); + + for (ua = aa->FirstUnicastAddress; ua != NULL; ua = ua->Next) { + if (filter != NULL) { + DLOGI("Callback set to allow network interface filtering"); + // The callback evaluates to a FALSE if the application is interested in black listing an interface + if (filter(customData, ifa_name) == FALSE) { + filterSet = FALSE; + } else { + filterSet = TRUE; + } } - } - - // If filter is set, ensure the details are collected for the interface - if (filterSet == TRUE) { - int family = ua->Address.lpSockaddr->sa_family; - - if (family == AF_INET) { - destIpList[ipCount].family = KVS_IP_FAMILY_TYPE_IPV4; - destIpList[ipCount].port = 0; - - pIpv4Addr = (struct sockaddr_in*) (ua->Address.lpSockaddr); - MEMCPY(destIpList[ipCount].address, &pIpv4Addr->sin_addr, IPV4_ADDRESS_LENGTH); - } else { - destIpList[ipCount].family = KVS_IP_FAMILY_TYPE_IPV6; - destIpList[ipCount].port = 0; - pIpv6Addr = (struct sockaddr_in6*) (ua->Address.lpSockaddr); - // Ignore unspecified addres: the other peer can't use this address - // Ignore link local: not very useful and will add work unnecessarily - // Ignore site local: https://tools.ietf.org/html/rfc8445#section-5.1.1.1 - if (IN6_IS_ADDR_UNSPECIFIED(&pIpv6Addr->sin6_addr) || IN6_IS_ADDR_LINKLOCAL(&pIpv6Addr->sin6_addr) || - IN6_IS_ADDR_SITELOCAL(&pIpv6Addr->sin6_addr)) { - continue; + // If filter is set, ensure the details are collected for the interface + if (filterSet == TRUE) { + int family = ua->Address.lpSockaddr->sa_family; + + if (family == AF_INET) { + destIpList[ipCount].family = KVS_IP_FAMILY_TYPE_IPV4; + destIpList[ipCount].port = 0; + + pIpv4Addr = (struct sockaddr_in*) (ua->Address.lpSockaddr); + MEMCPY(destIpList[ipCount].address, &pIpv4Addr->sin_addr, IPV4_ADDRESS_LENGTH); + } else { + destIpList[ipCount].family = KVS_IP_FAMILY_TYPE_IPV6; + destIpList[ipCount].port = 0; + + pIpv6Addr = (struct sockaddr_in6*) (ua->Address.lpSockaddr); + // Ignore unspecified addres: the other peer can't use this address + // Ignore link local: not very useful and will add work unnecessarily + // Ignore site local: https://tools.ietf.org/html/rfc8445#section-5.1.1.1 + if (IN6_IS_ADDR_UNSPECIFIED(&pIpv6Addr->sin6_addr) || IN6_IS_ADDR_LINKLOCAL(&pIpv6Addr->sin6_addr) || + IN6_IS_ADDR_SITELOCAL(&pIpv6Addr->sin6_addr)) { + continue; + } + MEMCPY(destIpList[ipCount].address, &pIpv6Addr->sin6_addr, IPV6_ADDRESS_LENGTH); } - MEMCPY(destIpList[ipCount].address, &pIpv6Addr->sin6_addr, IPV6_ADDRESS_LENGTH); - } - // in case of overfilling destIpList - ipCount++; + // in case of overfilling destIpList + ipCount++; + } } } }