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 } }
HostEntry DNS::hostByAddress(const IPAddress& address) { NetworkInitializer networkInitializer; #if defined(POCO_HAVE_IPv6) || defined(POCO_HAVE_ADDRINFO) SocketAddress sa(address, 0); static char fqname[1024]; int rc = getnameinfo(sa.addr(), sa.length(), fqname, sizeof(fqname), NULL, 0, NI_NAMEREQD); if (rc == 0) { struct addrinfo* pAI; struct addrinfo hints; std::memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; rc = getaddrinfo(fqname, NULL, &hints, &pAI); if (rc == 0) { HostEntry result(pAI); freeaddrinfo(pAI); return result; } else { aierror(rc, address.toString()); } } else { aierror(rc, address.toString()); } #elif defined(POCO_VXWORKS) char name[MAXHOSTNAMELEN + 1]; if (hostGetByAddr(*reinterpret_cast<const int*>(address.addr()), name) == OK) { return HostEntry(std::string(name), address); } #else struct hostent* he = gethostbyaddr(reinterpret_cast<const char*>(address.addr()), address.length(), address.af()); if (he) { return HostEntry(he); } #endif int err = lastError(); error(err, address.toString()); // will throw an appropriate exception throw NetException(); // to silence compiler }
HostEntry DNS::hostByAddress(const IPAddress& address, unsigned #ifdef POCO_HAVE_ADDRINFO hintFlags #endif ) { #if defined(POCO_HAVE_LIBRESOLV) Poco::ScopedReadRWLock readLock(resolverLock); #endif #if defined(POCO_HAVE_ADDRINFO) SocketAddress sa(address, 0); static char fqname[1024]; int rc = getnameinfo(sa.addr(), sa.length(), fqname, sizeof(fqname), NULL, 0, NI_NAMEREQD); if (rc == 0) { struct addrinfo* pAI; struct addrinfo hints; std::memset(&hints, 0, sizeof(hints)); hints.ai_flags = hintFlags; rc = getaddrinfo(fqname, NULL, &hints, &pAI); if (rc == 0) { HostEntry result(pAI); freeaddrinfo(pAI); return result; } else { aierror(rc, address.toString()); } } else { aierror(rc, address.toString()); } #elif defined(POCO_VXWORKS) char name[MAXHOSTNAMELEN + 1]; if (hostGetByAddr(*reinterpret_cast<const int*>(address.addr()), name) == OK) { return HostEntry(std::string(name), address); } #else struct hostent* he = gethostbyaddr(reinterpret_cast<const char*>(address.addr()), address.length(), address.af()); if (he) { return HostEntry(he); } #endif int err = lastError(); error(err, address.toString()); // will throw an appropriate exception throw NetException(); // to silence compiler }
bool operator () (const IPAddress& a1, const IPAddress& a2) { return a1.af() < a2.af(); }