Exemple #1
0
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::testMapUpOnly()
{
	NetworkInterface::Map m = NetworkInterface::map(false, true);
	assert (!m.empty());
	for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
	{
		assert(it->second.isUp());
	}
}
void NetworkInterfaceTest::testMapIpOnly()
{
	NetworkInterface::Map m = NetworkInterface::map(true, false);
	assert (!m.empty());
	for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
	{
		assert(it->second.supportsIPv4() || it->second.supportsIPv6());
	}
}
void NetworkInterfaceTest::testMapIpOnly()
{
	NetworkInterface::Map m = NetworkInterface::map(true, false);
	assert (!m.empty());

	std::cout << std::endl;
	for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
	{
		assert(it->second.supportsIPv4() || it->second.supportsIPv6());
		std::cout << "Interface: (" << it->second.index() << ")" << std::endl;
		std::cout << "Address:    " << it->second.address() << std::endl;
		NetworkInterface::MACAddress mac(it->second.macAddress());
		if (!mac.empty() && (it->second.type() != NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK))
			std::cout << "MAC Address:" << mac << std::endl;
	}
}
void NetworkInterfaceTest::testMap()
{
	NetworkInterface::Map m = NetworkInterface::map(false, false);
	assert (!m.empty());
	for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
	{
		std::cout << std::endl << "=============" << std::endl;

		std::cout << "Index:       " << it->second.index() << std::endl;
		std::cout << "Name:        " << it->second.name() << std::endl;
		std::cout << "DisplayName: " << it->second.displayName() << std::endl;
		std::cout << "Status:      " << (it->second.isUp() ? "Up" : "Down") << std::endl;

		NetworkInterface::MACAddress mac(it->second.macAddress());
		if (!mac.empty() && (it->second.type() != NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK))
			std::cout << "MAC Address: (" << it->second.type() << ") " << mac << std::endl;

		typedef NetworkInterface::AddressList List;
		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)
		{
			std::cout << std::endl << "----------" << std::endl;
			std::cout << "Address " << counter << std::endl;
			std::cout << "----------" << std::endl;
			std::cout << "Address:     " << ipIt->get<NetworkInterface::IP_ADDRESS>() << std::endl;
			IPAddress addr = ipIt->get<NetworkInterface::SUBNET_MASK>();
			if (!addr.isWildcard()) std::cout << "Subnet:      " << addr << " (/" << addr.prefixLength() << ")" << std::endl;
			addr = ipIt->get<NetworkInterface::BROADCAST_ADDRESS>();
			if (!addr.isWildcard()) std::cout << "Broadcast:   " << addr << std::endl;
		}

		std::cout << "=============" << std::endl << std::endl;
	}
}