Poco::Net::NetworkInterface::list does not list inactive interfaces even when explicitly being asked for it #2044

This commit is contained in:
Alex Fabijanic 2017-12-19 08:47:31 +01:00
parent 56a483bcf9
commit 2b125e1c4e
3 changed files with 56 additions and 42 deletions

View File

@ -875,14 +875,16 @@ NetworkInterface::List NetworkInterface::list(bool ipOnly, bool upOnly)
typedef NetworkInterface::AddressList List;
const List& ipList = it->second.addressList();
if (ipList.size() > 0)
{
List::const_iterator ipIt = ipList.begin();
List::const_iterator ipEnd = ipList.end();
for (; ipIt != ipEnd; ++ipIt)
for(; ipIt != ipEnd; ++ipIt)
{
IPAddress addr = ipIt->get<NetworkInterface::IP_ADDRESS>();
IPAddress mask = ipIt->get<NetworkInterface::SUBNET_MASK>();
NetworkInterface ni;
if (mask.isWildcard())
if(mask.isWildcard())
{
ni = NetworkInterface(name, displayName, adapterName, addr, index, &mac);
}
@ -904,6 +906,11 @@ NetworkInterface::List NetworkInterface::list(bool ipOnly, bool upOnly)
list.push_back(ni);
}
}
else
{
list.push_back(NetworkInterface(name, displayName, adapterName, index, &mac));
}
}
return list;
}

View File

@ -79,7 +79,7 @@ void NetworkInterfaceTest::testList()
{
NetworkInterface::List list = NetworkInterface::list(false, false);
assert (!list.empty());
for (NetworkInterface::NetworkInterfaceList::const_iterator it = list.begin(); it != list.end(); ++it)
for (NetworkInterface::List::const_iterator it = list.begin(); it != list.end(); ++it)
{
std::cout << std::endl << "==============" << std::endl;
@ -92,10 +92,10 @@ void NetworkInterfaceTest::testList()
if (!mac.empty() && (it->type() != NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK))
std::cout << "MAC Address: (" << it->type() << ") " << mac << std::endl;
typedef NetworkInterface::AddressList List;
const List& ipList = it->addressList();
List::const_iterator ipIt = ipList.begin();
List::const_iterator ipEnd = ipList.end();
typedef NetworkInterface::AddressList AddrList;
const AddrList& ipList = it->addressList();
AddrList::const_iterator ipIt = ipList.begin();
AddrList::const_iterator ipEnd = ipList.end();
for (int counter = 0; ipIt != ipEnd; ++ipIt, ++counter)
{
std::cout << "IP Address: " << ipIt->get<NetworkInterface::IP_ADDRESS>() << std::endl;
@ -213,13 +213,20 @@ void NetworkInterfaceTest::testListMapConformance()
typedef NetworkInterface::AddressList List;
const List& ipList = mapIt->second.addressList();
if (ipList.size() > 0)
{
List::const_iterator ipIt = ipList.begin();
List::const_iterator ipEnd = ipList.end();
for (; ipIt != ipEnd; ++ipIt, ++counter, ++listIt)
for(; ipIt != ipEnd; ++ipIt, ++counter, ++listIt)
{
NetworkInterface::MACAddress lmac = listIt->macAddress();
assert (lmac == mac);
if (listIt == l.end()) fail ("wrong number of list items");
if(listIt == l.end()) fail("wrong number of list items");
}
}
else
{
++counter;
}
}