本文整理汇总了C++中NetworkInterface::firstAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkInterface::firstAddress方法的具体用法?C++ NetworkInterface::firstAddress怎么用?C++ NetworkInterface::firstAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkInterface
的用法示例。
在下文中一共展示了NetworkInterface::firstAddress方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: leaveGroup
void MulticastSocket::leaveGroup(const IPAddress& groupAddress, const NetworkInterface& interfc)
{
if (groupAddress.af() == AF_INET)
{
struct ip_mreq mr;
std::memcpy(&mr.imr_multiaddr, groupAddress.addr(), groupAddress.length());
std::memcpy(&mr.imr_interface, interfc.firstAddress(IPAddress::IPv4).addr(), interfc.firstAddress(IPAddress::IPv4).length());
impl()->setRawOption(IPPROTO_IP, IP_DROP_MEMBERSHIP, &mr, sizeof(mr));
}
else
{
#if defined(POCO_HAVE_IPv6)
struct ipv6_mreq mr;
std::memcpy(&mr.ipv6mr_multiaddr, groupAddress.addr(), groupAddress.length());
mr.ipv6mr_interface = interfc.index();
impl()->setRawOption(IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mr, sizeof(mr));
#endif
}
}
示例3: setInterface
void MulticastSocket::setInterface(const NetworkInterface& interfc)
{
if (address().family() == IPAddress::IPv4)
{
impl()->setOption(IPPROTO_IP, IP_MULTICAST_IF, interfc.firstAddress(IPAddress::IPv4));
}
#if defined(POCO_HAVE_IPv6)
else if (address().family() == IPAddress::IPv6)
{
impl()->setOption(IPPROTO_IPV6, IPV6_MULTICAST_IF, interfc.index());
}
#endif
else
throw UnsupportedFamilyException("Unknown or unsupported socket family.");
}