mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-19 00:46:03 +01:00
Poco::Net::NetworkInterface::list does not list inactive interfaces even when explicitly being asked for it #2044
This commit is contained in:
parent
56a483bcf9
commit
2b125e1c4e
@ -89,7 +89,7 @@ public:
|
||||
NI_TYPE_IEEE1394,
|
||||
NI_TYPE_OTHER
|
||||
};
|
||||
|
||||
|
||||
enum IPVersion
|
||||
{
|
||||
IPv4_ONLY, /// Return interfaces with IPv4 address only
|
||||
@ -173,10 +173,10 @@ public:
|
||||
|
||||
const AddressList& addressList() const;
|
||||
/// Returns the list of IP addresses bound to the interface.
|
||||
|
||||
|
||||
const IPAddress& subnetMask(unsigned index = 0) const;
|
||||
/// Returns the subnet mask for this network interface.
|
||||
|
||||
|
||||
const IPAddress& broadcastAddress(unsigned index = 0) const;
|
||||
/// Returns the broadcast address for this network interface.
|
||||
|
||||
@ -249,7 +249,7 @@ public:
|
||||
///
|
||||
/// Throws an InterfaceNotFoundException if an interface
|
||||
/// with the given index does not exist.
|
||||
|
||||
|
||||
static List list(bool ipOnly = true, bool upOnly = true);
|
||||
/// Returns a list with all network interfaces
|
||||
/// on the system.
|
||||
@ -264,7 +264,7 @@ public:
|
||||
/// If there are multiple addresses bound to one interface,
|
||||
/// multiple NetworkInterface entries are listed for
|
||||
/// the same interface.
|
||||
|
||||
|
||||
static Map map(bool ipOnly = true, bool upOnly = true);
|
||||
/// Returns a map containing system network interfaces
|
||||
/// Map is keyed by interface system indices.
|
||||
@ -307,10 +307,10 @@ protected:
|
||||
unsigned index,
|
||||
MACAddress* pMACAddress = 0);
|
||||
/// Creates the NetworkInterface.
|
||||
|
||||
|
||||
IPAddress interfaceNameToAddress(const std::string& interfaceName) const;
|
||||
/// Determines the IPAddress bound to the interface with the given name.
|
||||
|
||||
|
||||
unsigned interfaceNameToIndex(const std::string& interfaceName) const;
|
||||
/// Determines the interface index of the interface with the given name.
|
||||
|
||||
@ -318,7 +318,7 @@ protected:
|
||||
|
||||
private:
|
||||
NetworkInterfaceImpl* _pImpl;
|
||||
|
||||
|
||||
static Poco::FastMutex _mutex;
|
||||
};
|
||||
|
||||
|
@ -875,33 +875,40 @@ NetworkInterface::List NetworkInterface::list(bool ipOnly, bool upOnly)
|
||||
|
||||
typedef NetworkInterface::AddressList List;
|
||||
const List& ipList = it->second.addressList();
|
||||
List::const_iterator ipIt = ipList.begin();
|
||||
List::const_iterator ipEnd = ipList.end();
|
||||
for (; ipIt != ipEnd; ++ipIt)
|
||||
if (ipList.size() > 0)
|
||||
{
|
||||
IPAddress addr = ipIt->get<NetworkInterface::IP_ADDRESS>();
|
||||
IPAddress mask = ipIt->get<NetworkInterface::SUBNET_MASK>();
|
||||
NetworkInterface ni;
|
||||
if (mask.isWildcard())
|
||||
List::const_iterator ipIt = ipList.begin();
|
||||
List::const_iterator ipEnd = ipList.end();
|
||||
for(; ipIt != ipEnd; ++ipIt)
|
||||
{
|
||||
ni = NetworkInterface(name, displayName, adapterName, addr, index, &mac);
|
||||
}
|
||||
else
|
||||
{
|
||||
IPAddress broadcast = ipIt->get<NetworkInterface::BROADCAST_ADDRESS>();
|
||||
ni = NetworkInterface(name, displayName, adapterName, addr, mask, broadcast, index, &mac);
|
||||
}
|
||||
IPAddress addr = ipIt->get<NetworkInterface::IP_ADDRESS>();
|
||||
IPAddress mask = ipIt->get<NetworkInterface::SUBNET_MASK>();
|
||||
NetworkInterface ni;
|
||||
if(mask.isWildcard())
|
||||
{
|
||||
ni = NetworkInterface(name, displayName, adapterName, addr, index, &mac);
|
||||
}
|
||||
else
|
||||
{
|
||||
IPAddress broadcast = ipIt->get<NetworkInterface::BROADCAST_ADDRESS>();
|
||||
ni = NetworkInterface(name, displayName, adapterName, addr, mask, broadcast, index, &mac);
|
||||
}
|
||||
|
||||
ni._pImpl->_broadcast = it->second._pImpl->_broadcast;
|
||||
ni._pImpl->_loopback = it->second._pImpl->_loopback;
|
||||
ni._pImpl->_multicast = it->second._pImpl->_multicast;
|
||||
ni._pImpl->_pointToPoint = it->second._pImpl->_pointToPoint;
|
||||
ni._pImpl->_up = it->second._pImpl->_up;
|
||||
ni._pImpl->_running = it->second._pImpl->_running;
|
||||
ni._pImpl->_mtu = it->second._pImpl->_mtu;
|
||||
ni._pImpl->_type = it->second._pImpl->_type;
|
||||
ni._pImpl->_broadcast = it->second._pImpl->_broadcast;
|
||||
ni._pImpl->_loopback = it->second._pImpl->_loopback;
|
||||
ni._pImpl->_multicast = it->second._pImpl->_multicast;
|
||||
ni._pImpl->_pointToPoint = it->second._pImpl->_pointToPoint;
|
||||
ni._pImpl->_up = it->second._pImpl->_up;
|
||||
ni._pImpl->_running = it->second._pImpl->_running;
|
||||
ni._pImpl->_mtu = it->second._pImpl->_mtu;
|
||||
ni._pImpl->_type = it->second._pImpl->_type;
|
||||
|
||||
list.push_back(ni);
|
||||
list.push_back(ni);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list.push_back(NetworkInterface(name, displayName, adapterName, index, &mac));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
List::const_iterator ipIt = ipList.begin();
|
||||
List::const_iterator ipEnd = ipList.end();
|
||||
for (; ipIt != ipEnd; ++ipIt, ++counter, ++listIt)
|
||||
if (ipList.size() > 0)
|
||||
{
|
||||
NetworkInterface::MACAddress lmac = listIt->macAddress();
|
||||
assert (lmac == mac);
|
||||
if (listIt == l.end()) fail ("wrong number of list items");
|
||||
List::const_iterator ipIt = ipList.begin();
|
||||
List::const_iterator ipEnd = ipList.end();
|
||||
for(; ipIt != ipEnd; ++ipIt, ++counter, ++listIt)
|
||||
{
|
||||
NetworkInterface::MACAddress lmac = listIt->macAddress();
|
||||
assert (lmac == mac);
|
||||
if(listIt == l.end()) fail("wrong number of list items");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user