当前位置: 首页>>代码示例>>C++>>正文


C++ NetworkInterface::firstAddress方法代码示例

本文整理汇总了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());
		}
	}
}
开发者ID:trafficsim-jp,项目名称:poco,代码行数:34,代码来源:NetworkInterfaceTest.cpp

示例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
	}
}
开发者ID:Chingliu,项目名称:poco,代码行数:19,代码来源:MulticastSocket.cpp

示例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.");
}
开发者ID:Chingliu,项目名称:poco,代码行数:15,代码来源:MulticastSocket.cpp


注:本文中的NetworkInterface::firstAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。