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()); } } }
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 } }
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."); }