void NetworkInterfaceTest::testListMapConformance() { NetworkInterface::Map m = NetworkInterface::map(false, false); assert (!m.empty()); NetworkInterface::List l = NetworkInterface::list(false, false); assert (!l.empty()); int counter = 0; NetworkInterface::Map::const_iterator mapIt = m.begin(); NetworkInterface::List::const_iterator listIt = l.begin(); for (; mapIt != m.end(); ++mapIt) { NetworkInterface::MACAddress mac(mapIt->second.macAddress()); typedef NetworkInterface::AddressList List; const List& ipList = mapIt->second.addressList(); List::const_iterator ipIt = ipList.begin(); List::const_iterator ipEnd = ipList.end(); for (; ipIt != ipEnd; ++ipIt, ++counter, ++listIt) { NetworkInterface::MACAddress lmac = listIt->macAddress(); assert (lmac == mac); if (listIt == l.end()) fail ("wrong number of list items"); } } assert (counter == l.size()); }
void NetworkInterfaceTest::testList() { NetworkInterface::List list = NetworkInterface::list(false, false); assert (!list.empty()); for (NetworkInterface::List::const_iterator it = list.begin(); it != list.end(); ++it) { std::cout << std::endl << "==============" << std::endl; std::cout << "Index: " << it->index() << std::endl; std::cout << "Name: " << it->name() << std::endl; std::cout << "DisplayName: " << it->displayName() << std::endl; std::cout << "Status: " << (it->isUp() ? "Up" : "Down") << std::endl; NetworkInterface::MACAddress mac(it->macAddress()); if (!mac.empty() && (it->type() != NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK)) std::cout << "MAC Address: (" << it->type() << ") " << mac << std::endl; typedef NetworkInterface::AddressList AddrList; const AddrList& ipList = it->addressList(); AddrList::const_iterator ipIt = ipList.begin(); AddrList::const_iterator ipEnd = ipList.end(); for (int counter = 0; ipIt != ipEnd; ++ipIt, ++counter) { std::cout << "IP Address: " << ipIt->get<NetworkInterface::IP_ADDRESS>() << std::endl; IPAddress addr = ipIt->get<NetworkInterface::SUBNET_MASK>(); if (!addr.isWildcard()) std::cout << "Subnet: " << ipIt->get<NetworkInterface::SUBNET_MASK>() << " (/" << ipIt->get<NetworkInterface::SUBNET_MASK>().prefixLength() << ")" << std::endl; addr = ipIt->get<NetworkInterface::BROADCAST_ADDRESS>(); if (!addr.isWildcard()) std::cout << "Broadcast: " << ipIt->get<NetworkInterface::BROADCAST_ADDRESS>() << std::endl; } std::cout << "==============" << std::endl << std::endl; } }