xorp

IPv6 Class Reference

IPv6 address class. More...

#include <ipv6.hh>

List of all members.

Public Types

enum  { AF = AF_INET6 }
 

Constant for address family.


enum  { IPV = 6 }
 

Constant for IP protocol version.


typedef struct in6_addr InAddrType
typedef struct sockaddr_in6 SockAddrType

Public Member Functions

 IPv6 ()
 Default constructor.
 IPv6 (const uint8_t *from_uint8)
 Constructor from a (uint8_t *) memory pointer.
 IPv6 (const uint32_t *from_uint32)
 Constructor from a (uint32_t *) memory pointer.
 IPv6 (const in6_addr &from_in6_addr)
 Constructor from in6_addr structure.
 IPv6 (const sockaddr &sa) throw (InvalidFamily)
 Constructor from sockaddr structure.
 IPv6 (const sockaddr_storage &ss) throw (InvalidFamily)
 Constructor from sockaddr_storage structure.
 IPv6 (const sockaddr_in6 &sin6) throw (InvalidFamily)
 Constructor from sockaddr_in6 structure.
 IPv6 (const char *from_cstring) throw (InvalidString)
 Constructor from a string.
size_t copy_out (uint8_t *to_uint8) const
 Copy the IPv6 raw address to specified memory location.
size_t copy_out (in6_addr &to_in6_addr) const
 Copy the IPv6 raw address to an in6_addr structure.
size_t copy_out (sockaddr &to_sockaddr) const
 Copy the IPv6 raw address to a sockaddr structure.
size_t copy_out (sockaddr_storage &to_sockaddr_storage) const
 Copy the IPv6 raw address to a sockaddr_storage structure.
size_t copy_out (sockaddr_in6 &to_sockaddr_in6) const
 Copy the IPv6 raw address to a sockaddr_in6 structure.
size_t copy_in (const uint8_t *from_uint8)
 Copy a raw IPv6 address from specificed memory location into IPv6 structure.
size_t copy_in (const in6_addr &from_in6_addr)
 Copy a raw IPv6 address from a in6_addr structure into IPv6 structure.
size_t copy_in (const sockaddr &from_sockaddr) throw (InvalidFamily)
 Copy a raw IPv6 address from a sockaddr structure into IPv6 structure.
size_t copy_in (const sockaddr_storage &from_sockaddr_storage) throw (InvalidFamily)
 Copy a raw IPv6 address from a sockaddr_storage structure into IPv6 structure.
size_t copy_in (const sockaddr_in6 &from_sockaddr_in6) throw (InvalidFamily)
 Copy a raw address from sockaddr_in6 structure into IPv6 structure.
IPv6 operator~ () const
 Bitwise-Negation Operator.
IPv6 operator| (const IPv6 &other) const
 OR Operator.
IPv6 operator& (const IPv6 &other) const
 AND Operator.
IPv6 operator^ (const IPv6 &other) const
 XOR Operator.
IPv6 operator<< (uint32_t left_shift) const
 Operator <<.
IPv6 operator>> (uint32_t right_shift) const
 Operator >>
bool operator< (const IPv6 &other) const
 Less-Than Operator.
bool operator== (const IPv6 &other) const
 Equality Operator.
bool operator!= (const IPv6 &other) const
 Not-Equal Operator.
bool operator== (const IPv6Range &rhs) const
 Equality Operator for IPv6 against IPv6Range operand.
bool operator!= (const IPv6Range &rhs) const
 Non-equality Operator for IPv6 against IPv6Range operand.
bool operator< (const IPv6Range &rhs) const
 Less-than comparison for IPv6 against IPv6Range operand.
bool operator<= (const IPv6Range &rhs) const
 Less-than or equal comparison for IPv6 against IPv6Range.
bool operator> (const IPv6Range &rhs) const
 Greater-than comparison for IPv6 against IPv6Range operand.
bool operator>= (const IPv6Range &rhs) const
 Greater-than or equal comparison for IPv6 against IPv6Range.
IPv6operator-- ()
 Decrement Operator.
IPv6operator++ ()
 Increment Operator.
string str () const
 Convert this address from binary form to presentation format.
bool is_zero () const
 Test if this address is numerically zero.
bool is_unicast () const
 Test if this address is a valid unicast address.
bool is_multicast () const
 Test if this address is a valid multicast address.
bool is_linklocal_unicast () const
 Test if this address is a valid link-local unicast address.
bool is_interfacelocal_multicast () const
 Test if this address is a valid interface-local multicast address.
bool is_nodelocal_multicast () const
 Test if this address is a valid node-local multicast address.
bool is_linklocal_multicast () const
 Test if this address is a valid link-local multicast address.
bool is_loopback () const
 Test if this address is the loopback address.
IPv6 mask_by_prefix_len (uint32_t prefix_len) const throw (InvalidNetmaskLength)
 Make an IPv6 address prefix.
uint32_t mask_len () const
 Get the mask length.
const uint32_t * addr () const
 Get the uint32_t raw value of this address.
void set_addr (const uint8_t *from_uint8)
 Set the address value.
uint32_t bits (uint32_t lsb, uint32_t len) const
 Extract bits from an address.
uint32_t bit_count () const
 Count the number of bits that are set in this address.
uint32_t leading_zero_count () const
 Count the number of leading zeroes in this address.

Static Public Member Functions

static size_t addr_bytelen ()
 Get the address octet-size.
static uint32_t addr_bitlen ()
 Get the address bit-length.
static uint32_t ip_multicast_base_address_mask_len ()
 Get the mask length for the multicast base address.
static const IPv6make_prefix (uint32_t mask_len) throw (InvalidNetmaskLength)
 Make an IPv6 mask prefix.
static int af ()
 Get the address family.
static uint32_t ip_version ()
 Get the IP protocol version.
static const string & ip_version_str ()
 Get the human-readable string with the IP protocol version.
static const IPv6ZERO (int af=AF_INET6)
 Pre-defined IPv6 address constants.
static const IPv6ANY (int af=AF_INET6)
static const IPv6ALL_ONES (int af=AF_INET6)
static const IPv6LOOPBACK (int af=AF_INET6)
static const IPv6MULTICAST_BASE (int af=AF_INET6)
static const IPv6MULTICAST_ALL_SYSTEMS (int af=AF_INET6)
static const IPv6MULTICAST_ALL_ROUTERS (int af=AF_INET6)
static const IPv6DVMRP_ROUTERS (int af=AF_INET6)
static const IPv6OSPFIGP_ROUTERS (int af=AF_INET6)
static const IPv6OSPFIGP_DESIGNATED_ROUTERS (int af=AF_INET6)
static const IPv6RIP2_ROUTERS (int af=AF_INET6)
static const IPv6PIM_ROUTERS (int af=AF_INET6)
static const IPv6SSM_ROUTERS (int af=AF_INET6)

Static Public Attributes

static const uint32_t ADDR_BITLEN = 128
 Number of bits in address as a constant.
static const uint32_t ADDR_BYTELEN = ADDR_BITLEN / 8
 Number of bytes in address as a constant.

Private Attributes

uint32_t _addr [4]

Detailed Description

IPv6 address class.

The IPv6 address class is a trivial class for handling IPv6 addresses and for performing operations on them such as printing and masking.


Constructor & Destructor Documentation

IPv6::IPv6 ( ) [inline]

Default constructor.

The address value is initialized to IN6ADDR_ANY.

IPv6::IPv6 ( const uint8_t *  from_uint8) [explicit]

Constructor from a (uint8_t *) memory pointer.

Parameters:
from_uint8the pointer to the memory to copy the address value from.
IPv6::IPv6 ( const uint32_t *  from_uint32) [explicit]

Constructor from a (uint32_t *) memory pointer.

Parameters:
from_uint32the pointer to the memory to copy the address value from.
IPv6::IPv6 ( const in6_addr &  from_in6_addr)

Constructor from in6_addr structure.

Parameters:
from_in6_addrthe storage to copy the address value from.
IPv6::IPv6 ( const sockaddr &  sa) throw (InvalidFamily)

Constructor from sockaddr structure.

Parameters:
sasockaddr to construct IPv6 addr from.
IPv6::IPv6 ( const sockaddr_storage &  ss) throw (InvalidFamily)

Constructor from sockaddr_storage structure.

Parameters:
sssockaddr_storage to construct IPv6 addr from.
IPv6::IPv6 ( const sockaddr_in6 &  sin6) throw (InvalidFamily)

Constructor from sockaddr_in6 structure.

Parameters:
sin6sockaddr_in6 to construct IPv6 addr from.
IPv6::IPv6 ( const char *  from_cstring) throw (InvalidString)

Constructor from a string.

Parameters:
from_cstringC-style string in the IPv6 canonical human-readable. format used for initialization.

Member Function Documentation

const uint32_t* IPv6::addr ( ) const [inline]

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.
static uint32_t IPv6::addr_bitlen ( ) [inline, 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.
static size_t IPv6::addr_bytelen ( ) [inline, 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.
static int IPv6::af ( ) [inline, static]

Get the address family.

Returns:
the address family of this address.
uint32_t IPv6::bit_count ( ) const [inline]

Count the number of bits that are set in this address.

Returns:
the number of bits that are set in this address.
uint32_t IPv6::bits ( uint32_t  lsb,
uint32_t  len 
) const [inline]

Extract bits from an address.

Parameters:
lsbstarting bit position (from the right) to extract.
lennumber 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.
size_t IPv6::copy_in ( const uint8_t *  from_uint8)

Copy a raw IPv6 address from specificed memory location into IPv6 structure.

Copy a raw address from the memory pointed by .

Parameters:
from_uint8the memory address to copy the address from.
Returns:
the number of copied octets.
the number of copied octets.
size_t IPv6::copy_in ( const sockaddr &  from_sockaddr) throw (InvalidFamily)

Copy a raw IPv6 address from a sockaddr structure into IPv6 structure.

Copy a raw address from .

Note that the address in the sockaddr structure must be of IPv6 address family.

Parameters:
from_sockaddrthe storage to copy the address from.
Returns:
the number of copied octets.
the number of copied octets.
size_t IPv6::copy_in ( const sockaddr_storage &  from_sockaddr_storage) throw (InvalidFamily)

Copy a raw IPv6 address from a sockaddr_storage structure into IPv6 structure.

Copy a raw address from .

Note that the address in the sockaddr_storage structure must be of IPv6 address family.

Parameters:
from_sockaddr_storagethe storage to copy the address from.
Returns:
the number of copied octets.
the number of copied octets.
size_t IPv6::copy_in ( const sockaddr_in6 &  from_sockaddr_in6) throw (InvalidFamily)

Copy a raw address from sockaddr_in6 structure into IPv6 structure.

Copy a raw address from .

Note that the address in the sockaddr structure must be of IPv6 address family.

Parameters:
from_sockaddr_in6the storage to copy the address from.
Returns:
the number of copied octets.
the number of copied octets.
size_t IPv6::copy_in ( const in6_addr &  from_in6_addr)

Copy a raw IPv6 address from a in6_addr structure into IPv6 structure.

Copy a raw address of family AF_INET6 from .

Parameters:
from_in6_addrthe storage to copy the address from.
Returns:
the number of copied octets.
the number of copied octets.
size_t IPv6::copy_out ( sockaddr_storage &  to_sockaddr_storage) const

Copy the IPv6 raw address to a sockaddr_storage structure.

Copy the raw address to , and assign appropriately the rest of the fields in .

Copy the raw address held within an IPv6 instance to an sockaddr_storage structure and assign appropriately and set fields within sockaddr_storage appropriately.

Parameters:
to_sockaddr_storagethe storage to copy the address to.
Returns:
the number of copied octets.
the number of copied octets.
size_t IPv6::copy_out ( in6_addr &  to_in6_addr) const

Copy the IPv6 raw address to an in6_addr structure.

Copy the raw address to .

Parameters:
to_in6_addrthe storage to copy the address to.
Returns:
the number of copied octets.
the number of copied octets.
size_t IPv6::copy_out ( sockaddr_in6 &  to_sockaddr_in6) const

Copy the IPv6 raw address to a sockaddr_in6 structure.

Copy the raw address to , and assign appropriately the rest of the fields in .

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_in6the storage to copy the address to.
Returns:
the number of copied octets.
the number of copied octets.
size_t IPv6::copy_out ( sockaddr &  to_sockaddr) const

Copy the IPv6 raw address to a sockaddr structure.

Copy the raw address to , and assign appropriately the rest of the fields in .

Copy the raw address held within an IPv6 instance to an sockaddr structure and assign appropriately and set fields within sockaddr appropriately.

Parameters:
to_sockaddrthe storage to copy the address to.
Returns:
the number of copied octets.
the number of copied octets.
size_t IPv6::copy_out ( uint8_t *  to_uint8) const

Copy the IPv6 raw address to specified memory location.

Copy the raw address to memory pointed by .

Parameters:
to_uint8 the pointer to the memory to copy the address to.
Returns:
the number of copied octets.
the number of copied octets.
static uint32_t IPv6::ip_multicast_base_address_mask_len ( ) [inline, 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.
static uint32_t IPv6::ip_version ( ) [inline, static]

Get the IP protocol version.

Returns:
the IP protocol version of this address.
const string & IPv6::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.
bool IPv6::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 IPv6::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 IPv6::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 IPv6::is_loopback ( ) const

Test if this address is the loopback address.

Returns:
true if the address is the loopback address.
bool IPv6::is_multicast ( ) const

Test if this address is a valid multicast address.

Returns:
true if the address is a valid multicast address.
bool IPv6::is_nodelocal_multicast ( ) const [inline]

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 IPv6::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 IPv6::is_zero ( ) const [inline]

Test if this address is numerically zero.

Returns:
true if the address is numerically zero.
uint32_t IPv6::leading_zero_count ( ) const [inline]

Count the number of leading zeroes in this address.

Returns:
the number of leading zeroes in this address.
const IPv6 & IPv6::make_prefix ( uint32_t  mask_len) throw (InvalidNetmaskLength) [static]

Make an IPv6 mask prefix.

Parameters:
mask_lenthe length of the mask to create.
Returns:
a new IPv6 address that contains a mask of length mask_len.
IPv6 IPv6::mask_by_prefix_len ( uint32_t  prefix_len) const throw (InvalidNetmaskLength) [inline]

Make an IPv6 address prefix.

Parameters:
prefix_lenthe 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 IPv6::mask_len ( ) const

Get the mask length.

Returns:
the prefix length of the contiguous mask presumably stored as an IPv6 address.
bool IPv6::operator!= ( const IPv6Range rhs) const [inline]

Non-equality Operator for IPv6 against IPv6Range operand.

Parameters:
rhsthe 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 IPv6::operator!= ( const IPv6 other) const

Not-Equal Operator.

Parameters:
otherthe right-hand operand to compare against.
Returns:
true if the left-hand operand is numerically not same as the right-hand operand.
IPv6 IPv6::operator& ( const IPv6 other) const [inline]

AND Operator.

Parameters:
otherthe right-hand operand to AND with.
Returns:
bitwise AND of two addresses.
IPv6 & IPv6::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.
IPv6 & IPv6::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.
bool IPv6::operator< ( const IPv6 other) const

Less-Than Operator.

Parameters:
otherthe right-hand operand to compare against.
Returns:
true if the left-hand operand is numerically smaller than the right-hand operand.
bool IPv6::operator< ( const IPv6Range rhs) const [inline]

Less-than comparison for IPv6 against IPv6Range operand.

Parameters:
rhsthe right-hand IPv6Range operand.
Returns:
true if the value of the left-hand operand is bellow the range defined by the right-hand operand.
IPv6 IPv6::operator<< ( uint32_t  left_shift) const

Operator <<.

Parameters:
left_shiftthe number of bits to shift to the left.
Returns:
IPv6 address that is shift bitwise to the left.
bool IPv6::operator<= ( const IPv6Range rhs) const [inline]

Less-than or equal comparison for IPv6 against IPv6Range.

Parameters:
rhsthe 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 IPv6::operator== ( const IPv6Range rhs) const [inline]

Equality Operator for IPv6 against IPv6Range operand.

Parameters:
rhsthe 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 IPv6::operator== ( const IPv6 other) const

Equality Operator.

Parameters:
otherthe right-hand operand to compare against.
Returns:
true if the left-hand operand is numerically same as the right-hand operand.
bool IPv6::operator> ( const IPv6Range rhs) const [inline]

Greater-than comparison for IPv6 against IPv6Range operand.

Parameters:
rhsthe 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 IPv6::operator>= ( const IPv6Range rhs) const [inline]

Greater-than or equal comparison for IPv6 against IPv6Range.

Parameters:
rhsthe 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 IPv6::operator>> ( uint32_t  right_shift) const

Operator >>

Parameters:
right_shiftthe number of bits to shift to the right.
Returns:
IPv6 address that is shift bitwise to the right.
IPv6 IPv6::operator^ ( const IPv6 other) const [inline]

XOR Operator.

Parameters:
otherthe right-hand operand to XOR with.
Returns:
bitwize eXclusive-OR of two addresses.
IPv6 IPv6::operator| ( const IPv6 other) const [inline]

OR Operator.

Parameters:
otherthe right-hand operand to OR with.
Returns:
bitwise OR of two addresses.
IPv6 IPv6::operator~ ( ) const [inline]

Bitwise-Negation Operator.

Returns:
address complement (i.e., all 0s become 1s, and vice-versa).
void IPv6::set_addr ( const uint8_t *  from_uint8) [inline]

Set the address value.

Parameters:
fromthe pointer to an array of 16 8-bit unsigned integers with the value to set this address to.
string IPv6::str ( ) const

Convert this address from binary form to presentation format.

Returns:
C++ string with the human-readable ASCII representation of the address.

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations