本文整理汇总了C++中networkinterface::Map类的典型用法代码示例。如果您正苦于以下问题:C++ Map类的具体用法?C++ Map怎么用?C++ Map使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Map类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testForAddress
void NetworkInterfaceTest::testForAddress()
{
NetworkInterface::Map map = NetworkInterface::map();
for (NetworkInterface::Map::const_iterator it = map.begin(); it != map.end(); ++it)
{
// not all interfaces have IP configured
if (it->second.addressList().empty()) continue;
if (it->second.supportsIPv4())
{
NetworkInterface ifc = NetworkInterface::forAddress(it->second.firstAddress(IPAddress::IPv4));
assert (ifc.firstAddress(IPAddress::IPv4) == it->second.firstAddress(IPAddress::IPv4));
IPAddress addr(IPAddress::IPv4);
assert (addr.isWildcard());
it->second.firstAddress(addr, IPAddress::IPv4);
assert (!addr.isWildcard());
}
else
{
try
{
it->second.firstAddress(IPAddress::IPv4);
fail ("must throw");
}
catch (NotFoundException&) { }
IPAddress addr(IPAddress::IPv4);
assert (addr.isWildcard());
it->second.firstAddress(addr, IPAddress::IPv4);
assert (addr.isWildcard());
}
}
}
示例2: testListMapConformance
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());
}
示例3: testMapUpOnly
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());
}
}
示例4: testForIndex
void NetworkInterfaceTest::testForIndex()
{
NetworkInterface::Map map = NetworkInterface::map();
for (NetworkInterface::Map::const_iterator it = map.begin(); it != map.end(); ++it)
{
NetworkInterface ifc = NetworkInterface::forIndex(it->second.index());
assert (ifc.index() == it->second.index());
}
}
示例5: testMapIpOnly
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());
}
}
示例6: NetworkInterface
Poco::Net::NetworkInterface MulticastEchoServer::findInterface()
{
NetworkInterface::Map m = NetworkInterface::map();
for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
{
if (it->second.supportsIPv4() &&
it->second.firstAddress(IPAddress::IPv4).isUnicast() &&
!it->second.isLoopback() &&
!it->second.isPointToPoint())
{
return it->second;
}
}
return NetworkInterface();
}
示例7: testMapIpOnly
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;
}
}
示例8:
/**
* Returns a vector (list) of IP address (active connections).
*/
vector<string> Parameters::getIP()
{
vector<string> list_of_ip;
NetworkInterface::Map m = NetworkInterface::map(false, false);
for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it) {
if ( ! it->second.isUp())
continue;
typedef NetworkInterface::AddressList List;
const List& ipList = it->second.addressList();
for (auto ip: ipList) {
std::string tmp = ip.get<NetworkInterface::IP_ADDRESS>().toString();
if ( (! ip.get<NetworkInterface::IP_ADDRESS>().isLoopback()) && // no localhost
(ip.get<NetworkInterface::IP_ADDRESS>().family() == Poco::Net::IPAddress::IPv4) && // only IPv4
(std::find(list_of_ip.begin(), list_of_ip.end(), tmp) == list_of_ip.end()) ) { // not in list
list_of_ip.push_back(tmp); // add
}
}
}
return list_of_ip;
}
示例9: testMap
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;
}
}
示例10: main
int main(int argc, char** argv)
{
if (argc != 1)
{
Path p(argv[0]);
std::cerr << "usage: " << p.getBaseName() << std::endl;
return 1;
}
try
{
const NetworkInterface::Map map = NetworkInterface::map();
for ( NetworkInterface::Map::const_iterator it = map.begin();
it != map.end(); ++it)
{
const NetworkInterface& intf = it->second;
std::string sep("");
std::cout << intf.name() << " [" << intf.index() << "]: ";
std::cout << "<";
if (intf.isUp())
{
std::cout << sep << "UP";
sep = ",";
}
if (intf.isRunning())
{
std::cout << sep << "RUNNING";
sep = ",";
}
if (intf.isLoopback())
{
std::cout << sep << "LOOPBACK";
sep = ",";
}
if (intf.isPointToPoint())
{
std::cout << sep << "P2P";
sep = ",";
}
if (intf.supportsIPv4())
{
std::cout << sep << "IPv4";
sep = ",";
}
if (intf.supportsIPv6())
{
std::cout << sep << "IPv6";
sep = ",";
}
if (intf.supportsBroadcast())
{
std::cout << sep << "BCAST";
sep = ",";
}
if (intf.supportsMulticast())
{
std::cout << sep << "MCAST";
sep = ",";
}
if (!intf.isLoopback())
{
std::cout << sep << std::dec << intf.mtu();
sep = ",";
}
std::cout << ">" << std::endl;
const NetworkInterface::AddressList& ipList = intf.addressList();
NetworkInterface::AddressList::const_iterator ipIt = ipList.begin();
NetworkInterface::AddressList::const_iterator ipEnd = ipList.end();
for (; ipIt != ipEnd; ++ipIt)
{
std::cout << " " << ipIt->get<NetworkInterface::IP_ADDRESS>().toString();
IPAddress addr;
addr = ipIt->get<NetworkInterface::SUBNET_MASK>();
if (!addr.isWildcard()) std::cout << '/' << addr.toString() << " (" << addr.prefixLength() << ')';
addr = ipIt->get<NetworkInterface::BROADCAST_ADDRESS>();
if (!addr.isWildcard()) std::cout << (intf.isPointToPoint() ? " dest " : " bcast ") << addr.toString();
std::cout << std::endl;
}
std::cout << std::endl;
}
}
catch (Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}
return 0;
//.........这里部分代码省略.........