This commit is contained in:
Aleksandar Fabijanic 2012-08-26 05:08:42 +00:00
Родитель 8a84ef0e86
Коммит 7093d032e4
2 изменённых файлов: 19 добавлений и 4 удалений

Просмотреть файл

@ -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<const struct sockaddr_in6*>(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 (...)

Просмотреть файл

@ -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)
{