join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::IpAddress Class Reference

IPv6, IPv4 address class. More...

#include <ipaddress.hpp>

Collaboration diagram for join::IpAddress:

Public Member Functions

 IpAddress ()
 create the IpAddress instance (default: IPv6 wildcard address).
 
 IpAddress (int family)
 create the IpAddress instance using address family.
 
 IpAddress (const IpAddress &address)
 create the IpAddress instance by copy.
 
 IpAddress (IpAddress &&address)
 create the IpAddress instance by move.
 
 IpAddress (const struct sockaddr &address)
 create the IpAddress instance using a sockaddr structure.
 
 IpAddress (const void *address, socklen_t length)
 create the IpAddress instance using an in_addr structure or an in6_addr structure.
 
 IpAddress (const void *address, socklen_t length, uint32_t scope)
 create the IpAddress instance using an in_addr structure or an in6_addr structure.
 
 IpAddress (const std::string &address, int family)
 create the IpAddress instance using a string and address family.
 
 IpAddress (const std::string &address)
 create the IpAddress instance using a string.
 
 IpAddress (const char *address, int family)
 create the IpAddress instance using a string and address family.
 
 IpAddress (const char *address)
 create the IpAddress instance using a string.
 
 IpAddress (int prefix, int family)
 create netmask address using prefix length.
 
IpAddressoperator= (const IpAddress &address)
 assign the IpAddress instance by copy.
 
IpAddressoperator= (IpAddress &&address)
 assign the IpAddress instance by move.
 
IpAddressoperator= (const struct sockaddr &address)
 assign the IpAddress using a sockaddr structure.
 
 ~IpAddress ()
 destroy the IpAddress instance.
 
int family () const
 get address family.
 
const void * addr () const
 get the internal address structure.
 
socklen_t length () const
 get the size in byte of the internal address structure.
 
uint32_t scope () const
 get the scope identifier of the address.
 
int prefix () const
 get prefix length from netmask address.
 
bool isWildcard () const
 check if IP address is a wildcard address.
 
bool isLoopBack () const
 check if IP address is a loopback address.
 
bool isLinkLocal () const
 check if IP address is link local.
 
bool isSiteLocal () const
 check if IP address is site local (deprecated).
 
bool isUniqueLocal () const
 check if IP address is unique local.
 
bool isUnicast () const
 check if IP address is unicast.
 
bool isBroadcast (int prefix=0) const
 check if IP address is a broadcast address.
 
bool isMulticast () const
 check if IP address is multicast.
 
bool isGlobal () const
 check if IP address is global.
 
bool isIpv6Address () const
 check if IP address is an IPv6 address.
 
bool isIpv4Compat () const
 check if IP address is IPv4 compatible (deprecated).
 
bool isIpv4Mapped () const
 check if IP address is IPv4 mapped.
 
bool isIpv4Address () const
 check if IP address is an IPv4 address.
 
IpAddress toIpv6 () const
 convert IP address to an IPv6 address.
 
IpAddress toIpv4 () const
 convert IP address to an IPv4 address.
 
std::string toString () const
 convert internal address structure to string.
 
std::string toArpa () const
 convert IP address to the in-addr.arpa or ip6.arpa domain name.
 
void clear ()
 clear IP address (wilcard address).
 
IpAddress operator~ () const
 perform NOT operation on IP address.
 
uint8_t & operator[] (size_t position)
 returns a reference to the element at the specified location.
 
const uint8_t & operator[] (size_t position) const
 returns a reference to the element at the specified location.
 

Static Public Member Functions

static bool isIpAddress (const std::string &address)
 check if the specified string is an IP address.
 
static bool isIpv6Address (const std::string &address)
 check if the specified string is an IPv6 address.
 
static bool isIpv4Address (const std::string &address)
 check if the specified string is an IPv4 address.
 
static IpAddress ipv4Address (const std::string &interface)
 get the specified interface IPv4 address.
 

Static Public Attributes

static const IpAddress ipv6Wildcard = "::"
 wildcard IPv6 address.
 
static const IpAddress ipv6AllNodes = "ff02::1"
 all nodes multicast IPv6 address.
 
static const IpAddress ipv6SolicitedNodes = "ff02::1:ff00:0"
 solicited nodes multicast IPv6 address.
 
static const IpAddress ipv6Routers = "ff02::2"
 routers multicast IPv6 address.
 
static constexpr socklen_t ipv6Length = 16
 IPv6 length.
 
static const IpAddress ipv4Wildcard = "0.0.0.0"
 wildcard IPv4 address.
 
static const IpAddress ipv4Broadcast = "255.255.255.255"
 broadcast IPv4 address.
 
static constexpr socklen_t ipv4Length = 4
 IPv4 length.
 

Detailed Description

IPv6, IPv4 address class.

Constructor & Destructor Documentation

◆ IpAddress() [1/12]

IpAddress::IpAddress ( )

create the IpAddress instance (default: IPv6 wildcard address).

◆ IpAddress() [2/12]

IpAddress::IpAddress ( int family)

create the IpAddress instance using address family.

Parameters
familyaddress family.

◆ IpAddress() [3/12]

IpAddress::IpAddress ( const IpAddress & address)

create the IpAddress instance by copy.

Parameters
addressaddress to copy.

◆ IpAddress() [4/12]

IpAddress::IpAddress ( IpAddress && address)

create the IpAddress instance by move.

Parameters
addressaddress to move.

◆ IpAddress() [5/12]

IpAddress::IpAddress ( const struct sockaddr & address)

create the IpAddress instance using a sockaddr structure.

Parameters
addressaddress structure to use.
Exceptions
invalid_argumentif address is wrong.

◆ IpAddress() [6/12]

IpAddress::IpAddress ( const void * address,
socklen_t length )

create the IpAddress instance using an in_addr structure or an in6_addr structure.

Parameters
addressaddress structure to use.
lengthaddress structure size.
Exceptions
invalid_argumentif address is wrong.

◆ IpAddress() [7/12]

IpAddress::IpAddress ( const void * address,
socklen_t length,
uint32_t scope )

create the IpAddress instance using an in_addr structure or an in6_addr structure.

Parameters
addressaddress structure to use.
lengthaddress structure size.
scopethe scope identifier of the address (ignored when IPv4).
Exceptions
invalid_argumentif address is wrong.

◆ IpAddress() [8/12]

IpAddress::IpAddress ( const std::string & address,
int family )

create the IpAddress instance using a string and address family.

Parameters
addressaddress string to use.
familyaddress family.
Exceptions
invalid_argumentif address is wrong.

◆ IpAddress() [9/12]

IpAddress::IpAddress ( const std::string & address)

create the IpAddress instance using a string.

Parameters
addressaddress string to use.
Exceptions
invalid_argumentif address is wrong.

◆ IpAddress() [10/12]

IpAddress::IpAddress ( const char * address,
int family )

create the IpAddress instance using a string and address family.

Parameters
addressaddress string to use.
familyaddress family.
Exceptions
invalid_argumentif address is wrong.

◆ IpAddress() [11/12]

IpAddress::IpAddress ( const char * address)

create the IpAddress instance using a string.

Parameters
addressaddress string to use.
Exceptions
invalid_argumentif address is wrong.

◆ IpAddress() [12/12]

IpAddress::IpAddress ( int prefix,
int family )

create netmask address using prefix length.

Parameters
prefixnumber of bits to create the netmask address from.
familyaddress family.

◆ ~IpAddress()

IpAddress::~IpAddress ( )

destroy the IpAddress instance.

Member Function Documentation

◆ addr()

const void * IpAddress::addr ( ) const

get the internal address structure.

Returns
a pointer to an in6_addr structure if IPv6 or to an in_addr structure if IPv4.

◆ clear()

void IpAddress::clear ( )

clear IP address (wilcard address).

◆ family()

int IpAddress::family ( ) const

get address family.

Returns
AF_INET6 if IPv6, AF_INET if IPv4.

◆ ipv4Address()

IpAddress IpAddress::ipv4Address ( const std::string & interface)
static

get the specified interface IPv4 address.

Parameters
interfaceinterface name.
Returns
the specified interface IPv4 address.

◆ isBroadcast()

bool IpAddress::isBroadcast ( int prefix = 0) const

check if IP address is a broadcast address.

Parameters
prefixprefix length.
Returns
if broadcast true is returned, false otherwise.

◆ isGlobal()

bool IpAddress::isGlobal ( ) const

check if IP address is global.

Returns
if IP address is global true is returned, false otherwise.

◆ isIpAddress()

bool IpAddress::isIpAddress ( const std::string & address)
static

check if the specified string is an IP address.

Parameters
addressstring that may contain an IP address.
Returns
true if the specified string is an IP address, false otherwise.

◆ isIpv4Address() [1/2]

bool IpAddress::isIpv4Address ( ) const

check if IP address is an IPv4 address.

Returns
if IP address is an IPv4 address true is returned, false otherwise.

◆ isIpv4Address() [2/2]

bool IpAddress::isIpv4Address ( const std::string & address)
static

check if the specified string is an IPv4 address.

Parameters
addressstring that may contain an IPv4 address.
Returns
true if the specified string is an IPv4 address, false otherwise.

◆ isIpv4Compat()

bool IpAddress::isIpv4Compat ( ) const

check if IP address is IPv4 compatible (deprecated).

Returns
if IPv4 compatible true is returned, false otherwise.

◆ isIpv4Mapped()

bool IpAddress::isIpv4Mapped ( ) const

check if IP address is IPv4 mapped.

Returns
if IPv4 mapped true is returned, false otherwise.

◆ isIpv6Address() [1/2]

bool IpAddress::isIpv6Address ( ) const

check if IP address is an IPv6 address.

Returns
if IP address is an IPv6 address true is returned, false otherwise.

◆ isIpv6Address() [2/2]

bool IpAddress::isIpv6Address ( const std::string & address)
static

check if the specified string is an IPv6 address.

Parameters
addressstring that may contain an IPv6 address.
Returns
true if the specified string is an IPv6 address, false otherwise.

◆ isLinkLocal()

bool IpAddress::isLinkLocal ( ) const

check if IP address is link local.

Returns
if IP address is link local true is returned, false otherwise.

◆ isLoopBack()

bool IpAddress::isLoopBack ( ) const

check if IP address is a loopback address.

Returns
if loopback true is returned, false otherwise.

◆ isMulticast()

bool IpAddress::isMulticast ( ) const

check if IP address is multicast.

Returns
if multicast true is returned, false otherwise.

◆ isSiteLocal()

bool IpAddress::isSiteLocal ( ) const

check if IP address is site local (deprecated).

Returns
if IP address is site local true is returned, false otherwise.

◆ isUnicast()

bool IpAddress::isUnicast ( ) const

check if IP address is unicast.

Returns
if unicast true is returned, false otherwise.

◆ isUniqueLocal()

bool IpAddress::isUniqueLocal ( ) const

check if IP address is unique local.

Returns
if IP address is unique local true is returned, false otherwise.

◆ isWildcard()

bool IpAddress::isWildcard ( ) const

check if IP address is a wildcard address.

Returns
if wildcard true is returned, false otherwise.

◆ length()

socklen_t IpAddress::length ( ) const

get the size in byte of the internal address structure.

Returns
the size in byte of the internal address structure.

◆ operator=() [1/3]

IpAddress & IpAddress::operator= ( const IpAddress & address)

assign the IpAddress instance by copy.

Parameters
addressaddress to copy.
Returns
a reference of the current object.

◆ operator=() [2/3]

IpAddress & IpAddress::operator= ( const struct sockaddr & address)

assign the IpAddress using a sockaddr structure.

Parameters
addressaddress structure to use.
Returns
a reference of the current object.
Exceptions
invalid_argumentif address is wrong.

◆ operator=() [3/3]

IpAddress & IpAddress::operator= ( IpAddress && address)

assign the IpAddress instance by move.

Parameters
addressaddress to move.
Returns
a reference of the current object.

◆ operator[]() [1/2]

uint8_t & IpAddress::operator[] ( size_t position)

returns a reference to the element at the specified location.

Parameters
positionposition of the element to return.
Returns
reference to the requested element.
Exceptions
invalid_argumentif position is out of range.

◆ operator[]() [2/2]

const uint8_t & IpAddress::operator[] ( size_t position) const

returns a reference to the element at the specified location.

Parameters
positionposition of the element to return.
Returns
reference to the requested element.
Exceptions
invalid_argumentif position is out of range.

◆ operator~()

IpAddress IpAddress::operator~ ( ) const

perform NOT operation on IP address.

Returns
result of NOT operation on IpAddress.

◆ prefix()

int IpAddress::prefix ( ) const

get prefix length from netmask address.

Returns
prefix length.

◆ scope()

uint32_t IpAddress::scope ( ) const

get the scope identifier of the address.

Returns
the scope identifier of the address.

◆ toArpa()

std::string IpAddress::toArpa ( ) const

convert IP address to the in-addr.arpa or ip6.arpa domain name.

Returns
the converted IP address.

◆ toIpv4()

IpAddress IpAddress::toIpv4 ( ) const

convert IP address to an IPv4 address.

Returns
a valid IPv4 address if IP address is an IPv4 address or an IPv4 mapped IPv6 address.

◆ toIpv6()

IpAddress IpAddress::toIpv6 ( ) const

convert IP address to an IPv6 address.

Returns
a valid IPv6 address if IP address is an IPv6 address or an IPv4 mapped IPv6 address if IP address is an IPv4 address.

◆ toString()

std::string IpAddress::toString ( ) const

convert internal address structure to string.

Returns
the internal address structure converted to string.

Member Data Documentation

◆ ipv4Broadcast

const IpAddress IpAddress::ipv4Broadcast = "255.255.255.255"
static

broadcast IPv4 address.

◆ ipv4Length

socklen_t join::IpAddress::ipv4Length = 4
staticconstexpr

IPv4 length.

◆ ipv4Wildcard

const IpAddress IpAddress::ipv4Wildcard = "0.0.0.0"
static

wildcard IPv4 address.

◆ ipv6AllNodes

const IpAddress IpAddress::ipv6AllNodes = "ff02::1"
static

all nodes multicast IPv6 address.

◆ ipv6Length

socklen_t join::IpAddress::ipv6Length = 16
staticconstexpr

IPv6 length.

◆ ipv6Routers

const IpAddress IpAddress::ipv6Routers = "ff02::2"
static

routers multicast IPv6 address.

◆ ipv6SolicitedNodes

const IpAddress IpAddress::ipv6SolicitedNodes = "ff02::1:ff00:0"
static

solicited nodes multicast IPv6 address.

◆ ipv6Wildcard

const IpAddress IpAddress::ipv6Wildcard = "::"
static

wildcard IPv6 address.


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