getLocalAddresses collects loopback address too

This commit is contained in:
Gio 2015-12-21 17:34:53 +01:00
parent 9d78bba3b8
commit 436f619fcb
2 changed files with 2 additions and 4 deletions

View File

@ -1021,7 +1021,7 @@ bool p3NetMgrIMPL::checkNetAddress()
std::list<sockaddr_storage>::iterator it;
if (getLocalAddresses(addrs))
for(it = addrs.begin(); (it != addrs.end() && !validAddr); ++it)
if(sockaddr_storage_isValidNet(*it))
if(sockaddr_storage_isValidNet(*it) && !sockaddr_storage_isLoopbackNet(*it))
{
prefAddr = *it;
validAddr = true;

View File

@ -303,8 +303,6 @@ bool getLocalAddresses(std::list<sockaddr_storage> & addrs)
IP_ADAPTER_ADDRESSES* adapter(NULL);
for(adapter = adapter_addresses; NULL != adapter; adapter = adapter->Next)
{
if (adapter->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
IP_ADAPTER_UNICAST_ADDRESS* address;
for ( address = adapter->FirstUnicastAddress; address; address = address->Next)
{
@ -320,7 +318,7 @@ bool getLocalAddresses(std::list<sockaddr_storage> & addrs)
struct ifaddrs *ifsaddrs, *ifa;
if(getifaddrs(&ifsaddrs) != 0) getLocalAddressesFailed();
for ( ifa = ifsaddrs; ifa; ifa = ifa->ifa_next )
if ( (ifa->ifa_flags & IFF_UP) && !(ifa->ifa_flags & IFF_LOOPBACK) )
if ( ifa->ifa_addr && (ifa->ifa_flags & IFF_UP) )
{
sockaddr_storage * tmp = new sockaddr_storage;
sockaddr_storage_clear(*tmp);