- add extra nic checking for windows
This commit is contained in:
parent
44aaf88598
commit
e3e7d93944
|
@ -799,6 +799,60 @@ std::vector<std::string> Socket::getLocalIPAddressList() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
ULONG outBufLen = 0;
|
||||||
|
GetAdaptersAddresses(AF_INET, 0, NULL, NULL, &outBufLen);
|
||||||
|
|
||||||
|
PIP_ADAPTER_ADDRESSES pAddresses = (IP_ADAPTER_ADDRESSES*)malloc(outBufLen);
|
||||||
|
GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST, NULL, pAddresses, &outBufLen);
|
||||||
|
|
||||||
|
PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
|
||||||
|
PIP_ADAPTER_UNICAST_ADDRESS pUnicast = NULL;
|
||||||
|
LPSOCKADDR addr = NULL;
|
||||||
|
pCurrAddresses = pAddresses;
|
||||||
|
char buff[100];
|
||||||
|
DWORD bufflen=100;
|
||||||
|
|
||||||
|
ifaddrinfo_ipv4_t addr_t;
|
||||||
|
while (pCurrAddresses) {
|
||||||
|
if (pCurrAddresses->OperStatus != IfOperStatusUp) {
|
||||||
|
pCurrAddresses = pCurrAddresses->Next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pUnicast = pCurrAddresses->FirstUnicastAddress;
|
||||||
|
|
||||||
|
while (pUnicast) {
|
||||||
|
addr = pUnicast->Address.lpSockaddr;
|
||||||
|
if (addr->sa_family == AF_INET && pCurrAddresses->IfType != MIB_IF_TYPE_LOOPBACK) {
|
||||||
|
sockaddr_in *sa_in = (sockaddr_in *)addr;
|
||||||
|
char* strIP = ::inet_ntoa((sa_in->sin_addr));
|
||||||
|
addr_t.ifa_name = strIP;
|
||||||
|
addr_t.ifa_ip = sa_in->sin_addr.S_un.S_addr;
|
||||||
|
socket_inet_ntop(sa_in->sin_family, &(sa_in->sin_addr), addr_t.ip, sizeof(addr_t.ip));
|
||||||
|
//if (pCurrAddresses->IfType == IF_TYPE_IEEE80211) {
|
||||||
|
// _addrs.insert(_addrs.begin(), addr_t);
|
||||||
|
//}
|
||||||
|
//else {
|
||||||
|
// _addrs.push_back(addr_t);
|
||||||
|
//}
|
||||||
|
sockaddr_in *sa_in = (sockaddr_in *)pUnicast->Address.lpSockaddr;
|
||||||
|
char *ip_address = inet_ntop(AF_INET,&(sa_in->sin_addr),buff,bufflen);
|
||||||
|
//printf("\tIPV4:%s\n",ip_address);
|
||||||
|
if( strlen(ip_address) > 0 &&
|
||||||
|
strncmp(ip_address,"127.",4) != 0 &&
|
||||||
|
strncmp(ip_address,"0.",2) != 0) {
|
||||||
|
if(std::find(ipList.begin(),ipList.end(),ip_address) == ipList.end()) {
|
||||||
|
ipList.push_back(ip_address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pUnicast = pUnicast->Next;
|
||||||
|
}
|
||||||
|
pCurrAddresses = pCurrAddresses->Next;
|
||||||
|
}
|
||||||
|
free(pAddresses);
|
||||||
|
//return !_addrs.empty();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ipList;
|
return ipList;
|
||||||
|
|
Loading…
Reference in New Issue