mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-18 12:19:30 +01:00
Merge pull request #989 from aaron0x/NetworkInterface
revise NetworkInterface
This commit is contained in:
commit
ee62025cc3
@ -236,6 +236,9 @@ public:
|
||||
/// The ipVersion argument can be used to specify whether
|
||||
/// an IPv4 (IPv4_ONLY) or IPv6 (IPv6_ONLY) interface is required,
|
||||
/// or whether the caller does not care (IPv4_OR_IPv6).
|
||||
///
|
||||
/// Throws an InterfaceNotFoundException if an interface
|
||||
/// with the give name does not exist.
|
||||
|
||||
static NetworkInterface forAddress(const IPAddress& address);
|
||||
/// Returns the NetworkInterface for the given IP address.
|
||||
@ -247,8 +250,7 @@ public:
|
||||
/// Returns the NetworkInterface for the given interface index.
|
||||
///
|
||||
/// Throws an InterfaceNotFoundException if an interface
|
||||
/// with the given index does not exist (or IPv6 is not
|
||||
/// available).
|
||||
/// with the given index does not exist.
|
||||
|
||||
static List list(bool ipOnly = true, bool upOnly = true);
|
||||
/// Returns a list with all network interfaces
|
||||
|
@ -794,16 +794,8 @@ bool NetworkInterface::isUp() const
|
||||
|
||||
NetworkInterface NetworkInterface::forName(const std::string& name, bool requireIPv6)
|
||||
{
|
||||
Map map = NetworkInterface::map(false, false);
|
||||
Map::const_iterator it = map.begin();
|
||||
Map::const_iterator end = map.end();
|
||||
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
if (it->second.name() == name && ((requireIPv6 && it->second.supportsIPv6()) || !requireIPv6))
|
||||
return it->second;
|
||||
}
|
||||
throw InterfaceNotFoundException(name);
|
||||
if (requireIPv6) return forName(name, IPv6_ONLY);
|
||||
else return forName(name, IPv4_OR_IPv6);
|
||||
}
|
||||
|
||||
|
||||
@ -881,7 +873,7 @@ NetworkInterface::List NetworkInterface::list(bool ipOnly, bool upOnly)
|
||||
const List& ipList = it->second.addressList();
|
||||
List::const_iterator ipIt = ipList.begin();
|
||||
List::const_iterator ipEnd = ipList.end();
|
||||
for (int counter = 0; ipIt != ipEnd; ++ipIt, ++counter)
|
||||
for (; ipIt != ipEnd; ++ipIt)
|
||||
{
|
||||
IPAddress addr = ipIt->get<NetworkInterface::IP_ADDRESS>();
|
||||
IPAddress mask = ipIt->get<NetworkInterface::SUBNET_MASK>();
|
||||
|
Loading…
Reference in New Issue
Block a user