Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::Net::IPAddress Class Reference

#include <IPAddress.h>

+ Collaboration diagram for Poco::Net::IPAddress:

Public Types

enum  { MAX_ADDRESS_LENGTH }
 Returns a broadcast IPv4 address (255.255.255.255). More...
 
using List = std::vector<IPAddress>
 
using Family = AddressFamily::Family
 

Public Member Functions

 IPAddress ()
 
 IPAddress (const IPAddress &addr)
 Creates a wildcard (zero) IPv4 IPAddress.
 
 IPAddress (Family family)
 Creates an IPAddress by copying another one.
 
 IPAddress (const std::string &addr)
 
 IPAddress (const std::string &addr, Family family)
 
 IPAddress (const void *addr, poco_socklen_t length)
 
 IPAddress (const void *addr, poco_socklen_t length, Poco::UInt32 scope)
 
 IPAddress (unsigned prefix, Family family)
 
 IPAddress (const struct sockaddr &sockaddr)
 Creates an IPAddress mask with the given length of prefix.
 
 ~IPAddress ()
 Same for struct sock_addr on POSIX.
 
IPAddressoperator= (const IPAddress &addr)
 Destroys the IPAddress.
 
Family family () const
 Assigns an IPAddress.
 
Poco::UInt32 scope () const
 Returns the address family (IPv4 or IPv6) of the address.
 
std::string toString () const
 
bool isWildcard () const
 
bool isBroadcast () const
 
bool isLoopback () const
 
bool isMulticast () const
 
bool isUnicast () const
 
bool isLinkLocal () const
 
bool isSiteLocal () const
 
bool isIPv4Compatible () const
 
bool isIPv4Mapped () const
 
bool isWellKnownMC () const
 
bool isNodeLocalMC () const
 
bool isLinkLocalMC () const
 
bool isSiteLocalMC () const
 
bool isOrgLocalMC () const
 
bool isGlobalMC () const
 
bool operator== (const IPAddress &addr) const
 
bool operator!= (const IPAddress &addr) const
 
bool operator< (const IPAddress &addr) const
 
bool operator<= (const IPAddress &addr) const
 
bool operator> (const IPAddress &addr) const
 
bool operator>= (const IPAddress &addr) const
 
IPAddress operator& (const IPAddress &addr) const
 
IPAddress operator| (const IPAddress &addr) const
 
IPAddress operator^ (const IPAddress &addr) const
 
IPAddress operator~ () const
 
poco_socklen_t length () const
 
const void * addr () const
 Returns the length in bytes of the internal socket address structure.

 
int af () const
 Returns the internal address structure.
 
unsigned prefixLength () const
 Returns the address family (AF_INET or AF_INET6) of the address.
 
void mask (const IPAddress &mask)
 Returns the prefix length.
 
void mask (const IPAddress &mask, const IPAddress &set)
 

Static Public Member Functions

static IPAddress parse (const std::string &addr)
 
static bool tryParse (const std::string &addr, IPAddress &result)
 
static IPAddress wildcard (Family family=IPv4)
 
static IPAddress broadcast ()
 Returns a wildcard IPv4 or IPv6 address (0.0.0.0).
 

Static Public Attributes

static const Family IPv4 = AddressFamily::IPv4
 

Private Types

typedef Poco::Net::Impl::IPAddressImpl Impl
 
typedef Poco::AutoPtr< ImplPtr
 

Private Member Functions

Ptr pImpl () const
 
void newIPv4 ()
 
void newIPv4 (const void *hostAddr)
 
void newIPv4 (unsigned prefix)
 

Private Attributes

Ptr _pImpl
 

Detailed Description

This class represents an internet (IP) host address. The address can belong either to the IPv4 or the IPv6 address family.

Relational operators (==, !=, <, <=, >, >=) are supported. However, you must not interpret any special meaning into the result of these operations, other than that the results are consistent.

Especially, an IPv4 address is never equal to an IPv6 address, even if the IPv6 address is IPv4 compatible and the addresses are the same.

IPv6 addresses are supported only if the target platform supports IPv6.

Definition at line 38 of file IPAddress.h.

Member Typedef Documentation

◆ Family

◆ Impl

Definition at line 367 of file IPAddress.h.

◆ List

using Poco::Net::IPAddress::List = std::vector<IPAddress>

Definition at line 57 of file IPAddress.h.

◆ Ptr

Definition at line 368 of file IPAddress.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Returns a broadcast IPv4 address (255.255.255.255).

Enumerator
MAX_ADDRESS_LENGTH 

Definition at line 355 of file IPAddress.h.

Constructor & Destructor Documentation

◆ IPAddress() [1/9]

Poco::Net::IPAddress::IPAddress ( )

◆ IPAddress() [2/9]

Poco::Net::IPAddress::IPAddress ( const IPAddress & addr)

Creates a wildcard (zero) IPv4 IPAddress.

◆ IPAddress() [3/9]

Poco::Net::IPAddress::IPAddress ( Family family)
explicit

Creates an IPAddress by copying another one.

◆ IPAddress() [4/9]

Poco::Net::IPAddress::IPAddress ( const std::string & addr)
explicit

Creates a wildcard (zero) IPAddress for the given address family.

◆ IPAddress() [5/9]

Poco::Net::IPAddress::IPAddress ( const std::string & addr,
Family family )

Creates an IPAddress from the string containing an IP address in presentation format (dotted decimal for IPv4, hex string for IPv6).

Depending on the format of addr, either an IPv4 or an IPv6 address is created.

See toString() for details on the supported formats.

Throws an InvalidAddressException if the address cannot be parsed.

◆ IPAddress() [6/9]

Poco::Net::IPAddress::IPAddress ( const void * addr,
poco_socklen_t length )

Creates an IPAddress from the string containing an IP address in presentation format (dotted decimal for IPv4, hex string for IPv6).

+ Here is the caller graph for this function:

◆ IPAddress() [7/9]

Poco::Net::IPAddress::IPAddress ( const void * addr,
poco_socklen_t length,
Poco::UInt32 scope )

Creates an IPAddress from a native internet address. A pointer to a in_addr or a in6_addr structure may be passed.

◆ IPAddress() [8/9]

Poco::Net::IPAddress::IPAddress ( unsigned prefix,
Family family )

Creates an IPAddress from a native internet address. A pointer to a in_addr or a in6_addr structure may be passed. Additionally, for an IPv6 address, a scope ID may be specified. The scope ID will be ignored if an IPv4 address is specified.

◆ IPAddress() [9/9]

Poco::Net::IPAddress::IPAddress ( const struct sockaddr & sockaddr)

Creates an IPAddress mask with the given length of prefix.

◆ ~IPAddress()

Poco::Net::IPAddress::~IPAddress ( )

Same for struct sock_addr on POSIX.

Member Function Documentation

◆ addr()

const void * Poco::Net::IPAddress::addr ( ) const

Returns the length in bytes of the internal socket address structure.

+ Here is the caller graph for this function:

◆ af()

int Poco::Net::IPAddress::af ( ) const

Returns the internal address structure.

◆ broadcast()

static IPAddress Poco::Net::IPAddress::broadcast ( )
static

Returns a wildcard IPv4 or IPv6 address (0.0.0.0).

◆ family()

Family Poco::Net::IPAddress::family ( ) const

Assigns an IPAddress.

◆ isBroadcast()

bool Poco::Net::IPAddress::isBroadcast ( ) const

Returns true iff the address is a wildcard (all zero) address.

◆ isGlobalMC()

bool Poco::Net::IPAddress::isGlobalMC ( ) const

Returns true iff the address is a organization-local multicast address.

For IPv4, organization-local multicast addresses are in the 239.192.0.0/16 range.

For IPv6, organization-local multicast addresses are in the FFx8:x:x:x:x:x:x:x range.

◆ isIPv4Compatible()

bool Poco::Net::IPAddress::isIPv4Compatible ( ) const

Returns true iff the address is a site local unicast address.

IPv4 site local addresses are in on of the 10.0.0.0/24, 192.168.0.0/16 or 172.16.0.0 to 172.31.255.255 ranges.

Originally, IPv6 site-local addresses had FEC0/10 (1111 1110 11) prefix (RFC 4291), followed by 38 zeros. Interfaces using
this mask are supported, but obsolete; RFC 4193 prescribes fc00::/7 (1111 110) as local unicast prefix.

◆ isIPv4Mapped()

bool Poco::Net::IPAddress::isIPv4Mapped ( ) const

Returns true iff the address is IPv4 compatible.

For IPv4 addresses, this is always true.

For IPv6, the address must be in the x:x range (the first 96 bits are zero).

◆ isLinkLocal()

bool Poco::Net::IPAddress::isLinkLocal ( ) const

Returns true iff the address is a unicast address.

An address is unicast if it is neither a wildcard, broadcast or multicast address.

◆ isLinkLocalMC()

bool Poco::Net::IPAddress::isLinkLocalMC ( ) const

Returns true iff the address is a node-local multicast address.

IPv4 does not support node-local addresses, thus the result is always false for an IPv4 address.

For IPv6, node-local multicast addresses are in the FFx1:x:x:x:x:x:x:x range.

◆ isLoopback()

bool Poco::Net::IPAddress::isLoopback ( ) const

Returns true iff the address is a broadcast address.

Only IPv4 addresses can be broadcast addresses. In a broadcast address, all bits are one.

For an IPv6 address, returns always false.

◆ isMulticast()

bool Poco::Net::IPAddress::isMulticast ( ) const

Returns true iff the address is a loopback address.

For IPv4, the loopback address is 127.0.0.1.

For IPv6, the loopback address is ::1.

◆ isNodeLocalMC()

bool Poco::Net::IPAddress::isNodeLocalMC ( ) const

Returns true iff the address is a well-known multicast address.

For IPv4, well-known multicast addresses are in the 224.0.0.0/8 range.

For IPv6, well-known multicast addresses are in the FF0x:x:x:x:x:x:x:x range.

◆ isOrgLocalMC()

bool Poco::Net::IPAddress::isOrgLocalMC ( ) const

Returns true iff the address is a site-local multicast address.

For IPv4, site local multicast addresses are in the 239.255.0.0/16 range.

For IPv6, site-local multicast addresses are in the FFx5:x:x:x:x:x:x:x range.

◆ isSiteLocal()

bool Poco::Net::IPAddress::isSiteLocal ( ) const

Returns true iff the address is a link local unicast address.

IPv4 link local addresses are in the 169.254.0.0/16 range, according to RFC 3927.

IPv6 link local addresses have 1111 1110 10 as the first 10 bits, followed by 54 zeros.

◆ isSiteLocalMC()

bool Poco::Net::IPAddress::isSiteLocalMC ( ) const

Returns true iff the address is a link-local multicast address.

For IPv4, link-local multicast addresses are in the 224.0.0.0/24 range. Note that this overlaps with the range for well-known multicast addresses.

For IPv6, link-local multicast addresses are in the FFx2:x:x:x:x:x:x:x range.

◆ isUnicast()

bool Poco::Net::IPAddress::isUnicast ( ) const

Returns true iff the address is a multicast address.

IPv4 multicast addresses are in the 224.0.0.0 to 239.255.255.255 range (the first four bits have the value 1110).

IPv6 multicast addresses are in the FFxx:x:x:x:x:x:x:x range.

◆ isWellKnownMC()

bool Poco::Net::IPAddress::isWellKnownMC ( ) const

Returns true iff the address is an IPv4 mapped IPv6 address.

For IPv4 addresses, this is always true.

For IPv6, the address must be in the ::FFFF:x:x range.

◆ isWildcard()

bool Poco::Net::IPAddress::isWildcard ( ) const

Returns a string containing a representation of the address in presentation format.

For IPv4 addresses the result will be in dotted-decimal (d.d.d.d) notation.

Textual representation of IPv6 address is one of the following forms:

The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the hexadecimal values of the eight 16-bit pieces of the address. This is the full form. Example: 1080:0:0:0:8:600:200A:425C

It is not necessary to write the leading zeros in an individual field. However, there must be at least one numeral in every field, except as described below.

It is common for IPv6 addresses to contain long strings of zero bits. In order to make writing addresses containing zero bits easier, a special syntax is available to compress the zeros. The use of "::" indicates multiple groups of 16-bits of zeros. The "::" can only appear once in an address. The "::" can also be used to compress the leading and/or trailing zeros in an address. Example: 1080::8:600:200A:425C

For dealing with IPv4 compatible addresses in a mixed environment, a special syntax is available: x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values of the six high-order 16-bit pieces of the address, and the 'd's are the decimal values of the four low-order 8-bit pieces of the standard IPv4 representation address. Example: ::FFFF:192.168.1.120

If an IPv6 address contains a non-zero scope identifier, it is added to the string, delimited by a percent character. On Windows platforms, the numeric value (which specifies an interface index) is directly appended. On Unix platforms, the name of the interface corresponding to the index (interpretation of the scope identifier) is added.

◆ length()

poco_socklen_t Poco::Net::IPAddress::length ( ) const

◆ mask() [1/2]

void Poco::Net::IPAddress::mask ( const IPAddress & mask)

Returns the prefix length.

◆ mask() [2/2]

void Poco::Net::IPAddress::mask ( const IPAddress & mask,
const IPAddress & set )

Masks the IP address using the given netmask, which is usually a IPv4 subnet mask. Only supported for IPv4 addresses.

The new address is (address & mask).

◆ newIPv4() [1/3]

void Poco::Net::IPAddress::newIPv4 ( )
inlineprivate

Definition at line 394 of file IPAddress.h.

+ Here is the call graph for this function:

◆ newIPv4() [2/3]

void Poco::Net::IPAddress::newIPv4 ( const void * hostAddr)
inlineprivate

Definition at line 400 of file IPAddress.h.

+ Here is the call graph for this function:

◆ newIPv4() [3/3]

void Poco::Net::IPAddress::newIPv4 ( unsigned prefix)
inlineprivate

Definition at line 406 of file IPAddress.h.

+ Here is the call graph for this function:

◆ operator!=()

bool Poco::Net::IPAddress::operator!= ( const IPAddress & addr) const

◆ operator&()

IPAddress Poco::Net::IPAddress::operator& ( const IPAddress & addr) const

◆ operator<()

bool Poco::Net::IPAddress::operator< ( const IPAddress & addr) const

◆ operator<=()

bool Poco::Net::IPAddress::operator<= ( const IPAddress & addr) const

◆ operator=()

IPAddress & Poco::Net::IPAddress::operator= ( const IPAddress & addr)

Destroys the IPAddress.

◆ operator==()

bool Poco::Net::IPAddress::operator== ( const IPAddress & addr) const

Returns true iff the address is a global multicast address.

For IPv4, global multicast addresses are in the 224.0.1.0 to 238.255.255.255 range.

For IPv6, global multicast addresses are in the FFxF:x:x:x:x:x:x:x range.

+ Here is the caller graph for this function:

◆ operator>()

bool Poco::Net::IPAddress::operator> ( const IPAddress & addr) const

◆ operator>=()

bool Poco::Net::IPAddress::operator>= ( const IPAddress & addr) const

◆ operator^()

IPAddress Poco::Net::IPAddress::operator^ ( const IPAddress & addr) const

◆ operator|()

IPAddress Poco::Net::IPAddress::operator| ( const IPAddress & addr) const

◆ operator~()

IPAddress Poco::Net::IPAddress::operator~ ( ) const

◆ parse()

static IPAddress Poco::Net::IPAddress::parse ( const std::string & addr)
static

Masks the IP address using the given netmask, which is usually a IPv4 subnet mask. Only supported for IPv4 addresses.

The new address is (address & mask) | (set & ~mask).

◆ pImpl()

IPAddress::Ptr Poco::Net::IPAddress::pImpl ( ) const
inlineprivate

Definition at line 387 of file IPAddress.h.

◆ prefixLength()

unsigned Poco::Net::IPAddress::prefixLength ( ) const

Returns the address family (AF_INET or AF_INET6) of the address.

◆ scope()

Poco::UInt32 Poco::Net::IPAddress::scope ( ) const

Returns the address family (IPv4 or IPv6) of the address.

◆ toString()

std::string Poco::Net::IPAddress::toString ( ) const

Returns the IPv6 scope identifier of the address. Returns 0 if the address is an IPv4 address, or the address is an IPv6 address but does not have a scope identifier.

◆ tryParse()

static bool Poco::Net::IPAddress::tryParse ( const std::string & addr,
IPAddress & result )
static

Creates an IPAddress from the string containing an IP address in presentation format (dotted decimal for IPv4, hex string for IPv6).

Depending on the format of addr, either an IPv4 or an IPv6 address is created.

See toString() for details on the supported formats.

Throws an InvalidAddressException if the address cannot be parsed.

◆ wildcard()

static IPAddress Poco::Net::IPAddress::wildcard ( Family family = IPv4)
static

Tries to interpret the given address string as an IP address in presentation format (dotted decimal for IPv4, hex string for IPv6).

Returns true and stores the IPAddress in result if the string contains a valid address.

Returns false and leaves result unchanged otherwise.

Member Data Documentation

◆ _pImpl

Ptr Poco::Net::IPAddress::_pImpl
private

Definition at line 380 of file IPAddress.h.

◆ IPv4

const Family Poco::Net::IPAddress::IPv4 = AddressFamily::IPv4
static

Definition at line 63 of file IPAddress.h.


The documentation for this class was generated from the following file: