- Code: Select all
NetworkInterface::NetworkInterfaceList NetworkInterface::list()
{
FastMutex::ScopedLock lock(_mutex);
NetworkInterfaceList result;
struct ifaddrs* ifaphead;
int rc = getifaddrs(&ifaphead);
if (rc) throw NetException("cannot get network adapter list");
for (int index = 0 ,struct ifaddrs* ifap = ifaphead; ifap; ifap = ifap->ifa_next, ++index)
{
if (ifap->ifa_addr)
{
if (ifap->ifa_addr->sa_family == AF_INET)
{
IPAddress addr(&reinterpret_cast(ifap->ifa_addr)->sin_addr, sizeof(struct in_addr));
IPAddress subnetMask(&reinterpret_cast(ifap->ifa_netmask)->sin_addr, sizeof(struct in_addr));
IPAddress broadcastAddress(&reinterpret_cast(ifap->ifa_dstaddr)->sin_addr, sizeof(struct in_addr));
result.push_back(NetworkInterface(std::string(ifap->ifa_name), addr, subnetMask, broadcastAddress), index);
}
}
}
freeifaddrs(ifaphead);
return result;
}





