IPAddress::IPAddress(const std::string& addr) { IPv4AddressImpl empty4 = IPv4AddressImpl(); if (addr.empty() || trim(addr) == "0.0.0.0") { newIPv4(empty4.addr()); return; } IPv4AddressImpl addr4(IPv4AddressImpl::parse(addr)); if (addr4 != empty4) { newIPv4(addr4.addr()); return; } #if defined(POCO_HAVE_IPv6) IPv6AddressImpl empty6 = IPv6AddressImpl(); if (addr.empty() || trim(addr) == "::") { newIPv6(empty6.addr()); return; } IPv6AddressImpl addr6(IPv6AddressImpl::parse(addr)); if (addr6 != IPv6AddressImpl()) { newIPv6(addr6.addr(), addr6.scope()); return; } #endif throw InvalidAddressException(addr); }
SocketAddress::SocketAddress(const SocketAddress& socketAddress) { if (socketAddress.family() == IPAddress::IPv4) newIPv4(reinterpret_cast<const sockaddr_in*>(socketAddress.addr())); else newIPv6(reinterpret_cast<const sockaddr_in6*>(socketAddress.addr())); }
IPAddress::IPAddress(const IPAddress& addr) { if (addr.family() == IPv4) newIPv4(addr.addr()); else newIPv6(addr.addr(), addr.scope()); }
void SocketAddress::init(const IPAddress& hostAddress, Poco::UInt16 portNumber) { if (hostAddress.family() == IPAddress::IPv4) newIPv4(hostAddress, portNumber); #if defined(POCO_HAVE_IPv6) else if (hostAddress.family() == IPAddress::IPv6) newIPv6(hostAddress, portNumber); #endif else throw Poco::NotImplementedException("unsupported IP address family"); }
IPAddress::IPAddress(const void* addr, poco_socklen_t length, Poco::UInt32 scope) { if (length == sizeof(struct in_addr)) newIPv4(addr); #if defined(POCO_HAVE_IPv6) else if (length == sizeof(struct in6_addr)) newIPv6(addr, scope); #endif else throw Poco::InvalidArgumentException("Invalid address length passed to IPAddress()"); }
SocketAddress::SocketAddress(const struct sockaddr* sockAddr, poco_socklen_t length) { if (length == sizeof(struct sockaddr_in)) newIPv4(reinterpret_cast<const struct sockaddr_in*>(sockAddr)); #if defined(POCO_HAVE_IPv6) else if (length == sizeof(struct sockaddr_in6)) newIPv6(reinterpret_cast<const struct sockaddr_in6*>(sockAddr)); #endif else throw Poco::InvalidArgumentException("Invalid address length passed to SocketAddress()"); }
IPAddress::IPAddress(Family family) { if (family == IPv4) newIPv4(); #if defined(POCO_HAVE_IPv6) else if (family == IPv6) newIPv6(); #endif else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()"); }
SocketAddress& SocketAddress::operator = (const SocketAddress& socketAddress) { if (&socketAddress != this) { destruct(); if (socketAddress.family() == IPAddress::IPv4) newIPv4(reinterpret_cast<const sockaddr_in*>(socketAddress.addr())); else newIPv6(reinterpret_cast<const sockaddr_in6*>(socketAddress.addr())); } return *this; }
IPAddress& IPAddress::operator = (const IPAddress& addr) { if (&addr != this) { destruct(); if (addr.family() == IPAddress::IPv4) newIPv4(addr.addr()); else newIPv6(addr.addr(), addr.scope()); } return *this; }
IPAddress::IPAddress(const struct sockaddr& sockaddr) { unsigned short family = sockaddr.sa_family; if (family == AF_INET) newIPv4(&reinterpret_cast<const struct sockaddr_in*>(&sockaddr)->sin_addr); #if defined(POCO_HAVE_IPv6) else if (family == AF_INET6) newIPv6(&reinterpret_cast<const struct sockaddr_in6*>(&sockaddr)->sin6_addr, reinterpret_cast<const struct sockaddr_in6*>(&sockaddr)->sin6_scope_id); #endif else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()"); }
SocketAddress::SocketAddress(const SocketAddress& socketAddress) { if (socketAddress.family() == IPv4) newIPv4(reinterpret_cast<const sockaddr_in*>(socketAddress.addr())); #if defined(POCO_HAVE_IPv6) else if (socketAddress.family() == IPv6) newIPv6(reinterpret_cast<const sockaddr_in6*>(socketAddress.addr())); #endif #if defined(POCO_OS_FAMILY_UNIX) else if (socketAddress.family() == UNIX_LOCAL) newLocal(reinterpret_cast<const sockaddr_un*>(socketAddress.addr())); #endif }
IPAddress::IPAddress(const void* addr, poco_socklen_t length) #ifndef POCO_HAVE_ALIGNMENT : _pImpl(0) #endif { if (length == sizeof(struct in_addr)) newIPv4(addr); #if defined(POCO_HAVE_IPv6) else if (length == sizeof(struct in6_addr)) newIPv6(addr); #endif else throw Poco::InvalidArgumentException("Invalid address length passed to IPAddress()"); }
SocketAddress::SocketAddress(const struct sockaddr* sockAddr, poco_socklen_t addressLength) { if (addressLength == sizeof(struct sockaddr_in) && sockAddr->sa_family == AF_INET) newIPv4(reinterpret_cast<const struct sockaddr_in*>(sockAddr)); #if defined(POCO_HAVE_IPv6) else if (addressLength == sizeof(struct sockaddr_in6) && sockAddr->sa_family == AF_INET6) newIPv6(reinterpret_cast<const struct sockaddr_in6*>(sockAddr)); #endif #if defined(POCO_OS_FAMILY_UNIX) else if (addressLength > 0 && addressLength <= sizeof(struct sockaddr_un) && sockAddr->sa_family == AF_UNIX) newLocal(reinterpret_cast<const sockaddr_un*>(sockAddr)); #endif else throw Poco::InvalidArgumentException("Invalid address length or family passed to SocketAddress()"); }
IPAddress::IPAddress(const SOCKET_ADDRESS& socket_address) #ifndef POCO_HAVE_ALIGNMENT : _pImpl(0) #endif { ADDRESS_FAMILY family = socket_address.lpSockaddr->sa_family; if (family == AF_INET) newIPv4(&reinterpret_cast<const struct sockaddr_in*>(socket_address.lpSockaddr)->sin_addr); #if defined(POCO_HAVE_IPv6) else if (family == AF_INET6) newIPv6(&reinterpret_cast<const struct sockaddr_in6*>(socket_address.lpSockaddr)->sin6_addr, reinterpret_cast<const struct sockaddr_in6*>(socket_address.lpSockaddr)->sin6_scope_id); #endif else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()"); }
SocketAddress& SocketAddress::operator = (const SocketAddress& socketAddress) { if (&socketAddress != this) { destruct(); if (socketAddress.family() == IPv4) newIPv4(reinterpret_cast<const sockaddr_in*>(socketAddress.addr())); #if defined(POCO_HAVE_IPv6) else if (socketAddress.family() == IPv6) newIPv6(reinterpret_cast<const sockaddr_in6*>(socketAddress.addr())); #endif #if defined(POCO_OS_FAMILY_UNIX) else if (socketAddress.family() == UNIX_LOCAL) newLocal(reinterpret_cast<const sockaddr_un*>(socketAddress.addr())); #endif } return *this; }
IPAddress::IPAddress(const std::string& addr, Family family) { if (family == IPv4) { IPv4AddressImpl addr4(IPv4AddressImpl::parse(addr)); newIPv4(addr4.addr()); return; } #if defined(POCO_HAVE_IPv6) else if (family == IPv6) { IPv6AddressImpl addr6(IPv6AddressImpl::parse(addr)); newIPv6(addr6.addr(), addr6.scope()); return; } #endif else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()"); }
IPAddress::IPAddress(unsigned prefix, Family family) { if (family == IPv4) { if (prefix <= 32) newIPv4(prefix); else throw Poco::InvalidArgumentException("Invalid prefix length passed to IPAddress()"); } #if defined(POCO_HAVE_IPv6) else if (family == IPv6) { if (prefix <= 128) newIPv6(prefix); else throw Poco::InvalidArgumentException("Invalid prefix length passed to IPAddress()"); } #endif else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()"); }
SocketAddress::SocketAddress() { newIPv4(); }
IPAddress::IPAddress() { newIPv4(); }