diff --git a/Net/src/NetworkInterface.cpp b/Net/src/NetworkInterface.cpp index 018dff951..0696ea073 100644 --- a/Net/src/NetworkInterface.cpp +++ b/Net/src/NetworkInterface.cpp @@ -1308,7 +1308,7 @@ static NetworkInterface::Type fromNative(unsigned arphrd) void setInterfaceParams(struct ifaddrs* iface, NetworkInterfaceImpl& impl) { - struct sockaddr_dl* sdl = (struct sockaddr_dl*) iface->ifa_addr; + struct sockaddr_ll* sdl = (struct sockaddr_ll*) iface->ifa_addr; impl.setName(iface->ifa_name); impl.setDisplayName(iface->ifa_name); impl.setPhyParams(); @@ -1358,7 +1358,7 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly) } case AF_INET: ifIndex = if_nametoindex(iface->ifa_name); - + ifIt = result.find(ifIndex); if ((ifIt == result.end()) && ((upOnly && intf.isUp()) || !upOnly)) { intf = NetworkInterface(ifIndex); @@ -1380,11 +1380,12 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly) #if defined(POCO_HAVE_IPv6) case AF_INET6: ifIndex = if_nametoindex(iface->ifa_name); + ifIt = result.find(ifIndex); if ((ifIt == result.end()) && ((upOnly && intf.isUp()) || !upOnly)) { intf = NetworkInterface(ifIndex); setInterfaceParams(iface, intf.impl()); - ifIt = result.insert(Map::value_type(ifIndex, intf)).first; + result.insert(Map::value_type(ifIndex, intf)).first; } address = IPAddress(&reinterpret_cast(iface->ifa_addr)->sin6_addr, sizeof(struct in6_addr), ifIndex); subnetMask = IPAddress(*(iface->ifa_netmask)); @@ -1394,6 +1395,20 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly) default: continue; } + + if (family == AF_INET +#ifdef POCO_HAVE_IPv6 + || family == AF_INET6 +#endif + ) + { + intf = NetworkInterface(std::string(iface->ifa_name), address, subnetMask, broadcastAddress, ifIndex); + if ((upOnly && intf.isUp()) || !upOnly) + { + if ((ifIt = result.find(ifIndex)) != result.end()) + ifIt->second.addAddress(address, subnetMask, broadcastAddress); + } + } } // for interface } catch (...) diff --git a/Net/testsuite/src/NetworkInterfaceTest.cpp b/Net/testsuite/src/NetworkInterfaceTest.cpp index a46c2d03f..b6d166fa7 100644 --- a/Net/testsuite/src/NetworkInterfaceTest.cpp +++ b/Net/testsuite/src/NetworkInterfaceTest.cpp @@ -94,7 +94,7 @@ void NetworkInterfaceTest::testMap() void NetworkInterfaceTest::testList() { - NetworkInterface::List list = NetworkInterface::list(); + NetworkInterface::List list = NetworkInterface::list(false, false); assert (!list.empty()); for (NetworkInterface::NetworkInterfaceList::const_iterator it = list.begin(); it != list.end(); ++it) {