diff --git a/Net/include/Poco/Net/NetworkInterface.h b/Net/include/Poco/Net/NetworkInterface.h index 6115d4661..f1f0ee602 100644 --- a/Net/include/Poco/Net/NetworkInterface.h +++ b/Net/include/Poco/Net/NetworkInterface.h @@ -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 diff --git a/Net/src/NetworkInterface.cpp b/Net/src/NetworkInterface.cpp index 584264137..1997e6e51 100644 --- a/Net/src/NetworkInterface.cpp +++ b/Net/src/NetworkInterface.cpp @@ -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(); IPAddress mask = ipIt->get();