The IPv6 address class is a trivial class for handling IPv6 addresses and for performing operations on them such as printing and masking.
typedef struct in6_addr InAddrType | InAddrType |
typedef struct sockaddr_in6 SockAddrType | SockAddrType |
IPv6 ()
| IPv6 |
Default constructor
The address value is initialized to IN6ADDR_ANY.
explicit IPv6 (const uint8_t *from_uint8)
| IPv6 |
Constructor from a (uint8_t *) memory pointer.
Parameters:
from_uint8 | the pointer to the memory to copy the address value from. |
explicit IPv6 (const uint32_t *from_uint32)
| IPv6 |
Constructor from a (uint32_t *) memory pointer.
Parameters:
from_uint32 | the pointer to the memory to copy the address value from. |
IPv6 (const in6_addr& from_in6_addr)
| IPv6 |
Constructor from in6_addr structure.
Parameters:
from_in6_addr | the storage to copy the address value from. |
IPv6 (const sockaddr& sa)
throw (InvalidFamily) | IPv6 |
Constructor from sockaddr structure.
Parameters:
sa | sockaddr to construct IPv6 addr from. |
IPv6 (const sockaddr_in6& sin)
throw (InvalidFamily) | IPv6 |
Constructor from sockaddr_in6 structure.
Parameters:
sin | sockaddr_in6 to construct IPv6 addr from. |
IPv6 (const char *from_cstring)
throw (InvalidString) | IPv6 |
Constructor from a string.
Parameters:
from_cstring | C-style string in the IPv6 canonical human-readable. format used for initialization. |
size_t copy_out (uint8_t *to_uint8)
| copy_out |
[const]
Copy the IPv6 raw address to specified memory location.
@param: to_uint8 the pointer to the memory to copy the address to.
Returns: the number of copied octets.
size_t copy_out (in6_addr& to_in6_addr)
| copy_out |
[const]
Copy the IPv6 raw address to an in6_addr structure.
Parameters:
to_in6_addr | the storage to copy the address to. |
Returns: the number of copied octets.
size_t copy_out (sockaddr& to_sockaddr)
| copy_out |
[const]
Copy the IPv6 raw address to a sockaddr structure.
Copy the raw address held within an IPv6 instance to an sockaddr structure and assign appropriately and set fields within sockaddr appropriately.
Parameters:
to_sockaddr | the storage to copy the address to. |
Returns: the number of copied octets.
size_t copy_out (sockaddr_in6& to_sockaddr_in6)
| copy_out |
[const]
Copy the IPv6 raw address to a sockaddr_in6 structure.
Copy the raw address held within an IPv6 instance to a sockaddr_in6 structure and assign appropriately and set fields within sockaddr_in appropriately.
Parameters:
to_sockaddr_in6 | the storage to copy the address to. |
Returns: the number of copied octets.
size_t copy_in (const uint8_t *from_uint8)
| copy_in |
Copy a raw IPv6 address from specificed memory location into IPv6 structure.
Parameters:
from_uint8 | the memory address to copy the address from. |
Returns: the number of copied octets.
size_t copy_in (const in6_addr& from_in6_addr)
| copy_in |
Copy a raw IPv6 address from a in6_addr structure into IPv6 structure.
Parameters:
from_in6_addr | the storage to copy the address from. |
Returns: the number of copied octets.
size_t copy_in (const sockaddr& from_sockaddr)
throw (InvalidFamily) | copy_in |
Copy a raw IPv6 address from a sockaddr structure into IPv6 structure.
Note that the address in the sockaddr structure must be of IPv6 address family.
Parameters:
from_sockaddr | the storage to copy the address from. |
Returns: the number of copied octets.
size_t copy_in (const sockaddr_in6& from_sockaddr_in6)
throw (InvalidFamily) | copy_in |
Copy a raw address from sockaddr_in6 structure into IPv6 structure.
Note that the address in the sockaddr structure must be of IPv6 address family.
Parameters:
from_sockaddr_in6 | the storage to copy the address from. |
Returns: the number of copied octets.
inline IPv6 operator~ ()
| operator~ |
[const]
Bitwise-Negation Operator
Returns: address complement (i.e., all 0s become 1s, and vice-versa).
inline IPv6 operator| (const IPv6& other)
| operator| |
[const]
OR Operator
Parameters:
other | the right-hand operand to OR with. |
Returns: bitwise OR of two addresses.
inline IPv6 operator& (const IPv6& other)
| operator& |
[const]
AND Operator
Parameters:
other | the right-hand operand to AND with. |
Returns: bitwise AND of two addresses.
inline IPv6 operator^ (const IPv6& other)
| operator^ |
[const]
XOR Operator
Parameters:
other | the right-hand operand to XOR with. |
Returns: bitwize eXclusive-OR of two addresses.
IPv6 operator<< (uint32_t left_shift)
| operator<< |
[const]
Operator <<
Parameters:
left_shift | the number of bits to shift to the left. |
Returns: IPv6 address that is shift bitwise to the left.
IPv6 operator>> (uint32_t right_shift)
| operator>> |
[const]
Operator >>
Parameters:
right_shift | the number of bits to shift to the right. |
Returns: IPv6 address that is shift bitwise to the right.
bool operator< (const IPv6& other)
| operator< |
[const]
Less-Than Operator
Parameters:
other | the right-hand operand to compare against. |
Returns: true if the left-hand operand is numerically smaller than the right-hand operand.
bool operator== (const IPv6& other)
| operator== |
[const]
Equality Operator
Parameters:
other | the right-hand operand to compare against. |
Returns: true if the left-hand operand is numerically same as the right-hand operand.
bool operator!= (const IPv6& other)
| operator!= |
[const]
Not-Equal Operator
Parameters:
other | the right-hand operand to compare against. |
Returns: true if the left-hand operand is numerically not same as the right-hand operand.
bool operator== (const IPv6Range& rhs)
| operator== |
[const]
Equality Operator for IPv6 against IPv6Range operand.
Parameters:
rhs | the right-hand IPv6Range operand. |
Returns: true if the value of the left-hand operand falls inside the range defined by the right-hand operand.
bool operator!= (const IPv6Range& rhs)
| operator!= |
[const]
Non-equality Operator for IPv6 against IPv6Range operand.
Parameters:
rhs | the right-hand IPv6Range operand. |
Returns: true if the value of the left-hand operand falls outside the range defined by the right-hand operand.
bool operator< (const IPv6Range& rhs)
| operator< |
[const]
Less-than comparison for IPv6 against IPv6Range operand.
Parameters:
rhs | the right-hand IPv6Range operand. |
Returns: true if the value of the left-hand operand is bellow the range defined by the right-hand operand.
bool operator<= (const IPv6Range& rhs)
| operator<= |
[const]
Less-than or equal comparison for IPv6 against IPv6Range
Parameters:
rhs | the right-hand IPv6Range operand. |
Returns: true if the value of the left-hand operand is bellow or within the range defined by the right-hand operand.
bool operator> (const IPv6Range& rhs)
| operator> |
[const]
Greater-than comparison for IPv6 against IPv6Range operand.
Parameters:
rhs | the right-hand IPv6Range operand. |
Returns: true if the value of the left-hand operand is above the range defined by the right-hand operand.
bool operator>= (const IPv6Range& rhs)
| operator>= |
[const]
Greater-than or equal comparison for IPv6 against IPv6Range
Parameters:
rhs | the right-hand IPv6Range operand. |
Returns: true if the value of the left-hand operand is above or within the range defined by the right-hand operand.
IPv6& operator-- ()
| operator-- |
Decrement Operator
The numerical value of this address is decremented by one. However, if the address value before the decrement was all-0s, after the decrement its value would be all-1s (i.e., it will wrap-around).
Returns: a reference to this address after it was decremented by one.
IPv6& operator++ ()
| operator++ |
Increment Operator
The numerical value of this address is incremented by one. However, if the address value before the increment was all-1s, after the increment its value would be all-0s (i.e., it will wrap-around).
Returns: a reference to this address after it was incremented by one.
string str ()
| str |
[const]
Convert this address from binary form to presentation format.
Returns: C++ string with the human-readable ASCII representation of the address.
inline bool is_zero ()
| is_zero |
[const]
Test if this address is numerically zero.
Returns: true if the address is numerically zero.
bool is_unicast ()
| is_unicast |
[const]
Test if this address is a valid unicast address.
Note that the numerically zero address is excluded.
Returns: true if the address is a valid unicast address.
bool is_multicast ()
| is_multicast |
[const]
Test if this address is a valid multicast address.
Returns: true if the address is a valid multicast address.
bool is_linklocal_unicast ()
| is_linklocal_unicast |
[const]
Test if this address is a valid link-local unicast address.
Returns: true if the address is a valid unicast address, and the scope of the address is link-local.
bool is_interfacelocal_multicast ()
| is_interfacelocal_multicast |
[const]
Test if this address is a valid interface-local multicast address.
Note that "node-local" multicast addresses were renamed to "interface-local" by RFC-3513.
Returns: true if the address is a valid multicast address, and the scope of the address is interface-local.
bool is_nodelocal_multicast ()
| is_nodelocal_multicast |
[const]
Test if this address is a valid node-local multicast address.
Note that "node-local" multicast addresses were renamed to "interface-local" by RFC-3513. This method is kept for backward compatibility.
Returns: true if the address is a valid multicast address, and the scope of the address is node-local.
bool is_linklocal_multicast ()
| is_linklocal_multicast |
[const]
Test if this address is a valid link-local multicast address.
Returns: true if the address is a valid multicast address, and the scope of the address is link-local.
bool is_loopback ()
| is_loopback |
[const]
Test if this address is the loopback address.
Returns: true if the address is the loopback address.
inline size_t addr_bytelen ()
| addr_bytelen |
[static]
Get the address octet-size.
Note that this is a static function and can be used without a particular object. Example: size_t my_size = IPv6::addr_bytelen(); size_t my_size = ipv6.addr_bytelen();
Returns: address size in number of octets.
inline uint32_t addr_bitlen ()
| addr_bitlen |
[static]
Get the address bit-length.
Note that this is a static function and can be used without a particular object. Example: uint32_t my_bitlen = IPv6::addr_bitlen(); uint32_t my_bitlen = ipv6.addr_bitlen();
Returns: address size in number of bits.
uint32_t ip_multicast_base_address_mask_len ()
| ip_multicast_base_address_mask_len |
[static]
Get the mask length for the multicast base address.
Note that this is a static function and can be used without a particular object. Example: size_t my_len = IPv6::ip_multicast_base_address_mask_len(); size_t my_len = ipv6.ip_multicast_base_address_mask_len();
Returns: the multicast base address mask_len for family AF_INET6.
const IPv6& make_prefix (uint32_t mask_len)
throw (InvalidNetmaskLength) | make_prefix |
[static]
Make an IPv6 mask prefix.
Parameters:
mask_len | the length of the mask to create. |
Returns: a new IPv6 address that contains a mask of length mask_len.
inline IPv6 mask_by_prefix_len (uint32_t prefix_len)
throw (InvalidNetmaskLength) | mask_by_prefix_len |
[const]
Make an IPv6 address prefix.
Parameters:
prefix_len | the length of the mask of the prefix to create. |
Returns: a new IPv6 address created by masking this address with a mask of length prefix_len.
uint32_t mask_len ()
| mask_len |
[const]
Get the mask length.
Returns: the prefix length of the contiguous mask presumably stored as an IPv6 address.
const uint32_t * addr ()
| addr |
[const]
Get the uint32_t raw value of this address.
Returns: the value of this IPv6 address as a pointer to an array of 4 unsigned 32-bit integers.
void set_addr (const uint8_t *from_uint8)
| set_addr |
Set the address value.
Parameters:
from | the pointer to an array of 16 8-bit unsigned integers with the value to set this address to. |
enum { AF = AF_INET6 } |
enum { IPV = 6 } |
Constant for IP protocol version
inline int af ()
| af |
[static]
Get the address family.
Returns: the address family of this address.
inline uint32_t ip_version ()
| ip_version |
[static]
Get the IP protocol version.
Returns: the IP protocol version of this address.
const string& ip_version_str ()
| ip_version_str |
[static]
Get the human-readable string with the IP protocol version.
Returns: the human-readable string with the IP protocol version of this address.
inline uint32_t bits (uint32_t lsb, uint32_t len)
| bits |
[const]
Extract bits from an address.
Parameters:
lsb | starting bit position (from the right) to extract. |
len | number of bits to extract. The maximum value is 32. |
Returns: the first len bits starting from the rightmost position lsb. The returned bits are in host order.
inline uint32_t bit_count ()
| bit_count |
[const]
Count the number of bits that are set in this address.
Returns: the number of bits that are set in this address.
inline uint32_t leading_zero_count ()
| leading_zero_count |
[const]
Count the number of leading zeroes in this address.
Returns: the number of leading zeroes in this address.
inline const IPv6& ZERO (int af = AF_INET6)
| ZERO |
[static]
Pre-defined IPv6 address constants.
inline const IPv6& ANY (int af = AF_INET6)
| ANY |
[static]
inline const IPv6& ALL_ONES (int af = AF_INET6)
| ALL_ONES |
[static]
inline const IPv6& LOOPBACK (int af = AF_INET6)
| LOOPBACK |
[static]
inline const IPv6& MULTICAST_BASE (int af = AF_INET6)
| MULTICAST_BASE |
[static]
inline const IPv6& MULTICAST_ALL_SYSTEMS (int af = AF_INET6)
| MULTICAST_ALL_SYSTEMS |
[static]
inline const IPv6& MULTICAST_ALL_ROUTERS (int af = AF_INET6)
| MULTICAST_ALL_ROUTERS |
[static]
inline const IPv6& DVMRP_ROUTERS (int af = AF_INET6)
| DVMRP_ROUTERS |
[static]
inline const IPv6& OSPFIGP_ROUTERS (int af = AF_INET6)
| OSPFIGP_ROUTERS |
[static]
inline const IPv6& OSPFIGP_DESIGNATED_ROUTERS (int af = AF_INET6)
| OSPFIGP_DESIGNATED_ROUTERS |
[static]
inline const IPv6& RIP2_ROUTERS (int af = AF_INET6)
| RIP2_ROUTERS |
[static]
inline const IPv6& PIM_ROUTERS (int af = AF_INET6)
| PIM_ROUTERS |
[static]
inline const IPv6& SSM_ROUTERS (int af = AF_INET6)
| SSM_ROUTERS |
[static]
static const uint32_t ADDR_BITLEN | ADDR_BITLEN |
static const uint32_t ADDR_BYTELEN | ADDR_BYTELEN |