class IPvX

Basic IPvX class (for both IPv4 and IPv6). More...

 
LOGO
 Annotated List  Files  Globals  Hierarchy  Index  Top

Public Methods

Public Static Methods


Detailed Description

 IPvX ()

IPvX

Default contructor

Creates an IPvX address with address family of AF_INET, and address value of INADDR_ANY (i.e., containing IPv4(0)).

explicit  IPvX (int family)
throw (InvalidFamily)

IPvX

Constructor for a specified address family.

Creates an address of specified family, and address value of INADDR_ANY or IN6ADDR_ANY (for IPv4 and IPv6 respectively).

Parameters:

familythe address family.
 IPvX (int family, const uint8_t *from_uint8)
throw (InvalidFamily)

IPvX

Constructor from a (uint8_t *) memory pointer.

Creates an address of specified family, and address value by using data from specified location.

Parameters:

familythe address family.
from_uint8the pointer to the memory to copy the address value from.
 IPvX (const IPv4& ipv4)

IPvX

Constructor from an IPv4 address.

Create an IPvX address from an IPv4 address.

Parameters:

ipv4the IPv4 address to assign the address value from.
 IPvX (const IPv6& ipv6)

IPvX

Constructor from an IPv6 address.

Create an IPvX address from an IPv6 address.

Parameters:

ipv6the IPv6 address to assign the address value from.
 IPvX (const in_addr& from_in_addr)

IPvX

Constructor from in_addr structure.

Note that this address must be of AF_INET family.

Parameters:

from_in_addrthe storage to copy the address value from.
 IPvX (const in6_addr& from_in6_addr)

IPvX

Constructor from in6_addr structure.

Note that this address must be of AF_INET6 family.

Parameters:

from_in6_addrthe storage to copy the address value from.
 IPvX (const sockaddr& from_sockaddr)
throw (InvalidFamily)

IPvX

Constructor from sockaddr structure.

Parameters:

from_sockaddrthe storage to copy the address from.
 IPvX (const sockaddr_storage& from_sockaddr_storage)
throw (InvalidFamily)

IPvX

Constructor from sockaddr_storage structure.

Parameters:

from_sockaddr_storagethe storage to copy the address from.
 IPvX (const sockaddr_in& from_sockaddr_in)
throw (InvalidFamily)

IPvX

Constructor from sockaddr_in structure.

Parameters:

from_sockaddr_inthe storage to copy the address from.
 IPvX (const sockaddr_in6& from_sockaddr_in6)
throw (InvalidFamily)

IPvX

Constructor from sockaddr_in6 structure.

Parameters:

from_sockaddr_in6the storage to copy the address from.
 IPvX (const char *from_cstring)
throw (InvalidString)

IPvX

Constructor from a string.

Parameters:

from_cstringC-style string in the IPv4 dotted decimal or IPv6 canonical human-readable format used for initialization.
size_t  copy_out (uint8_t *to_uint8)

copy_out

[const]

Copy the IPvX 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 (in_addr& to_in_addr)
throw (InvalidFamily)

copy_out

[const]

Copy the IPvX raw address to an in_addr structure.

Note that this address must be of AF_INET family.

Parameters:

to_in_addrthe storage to copy the address to.

Returns: the number of copied octets.

size_t  copy_out (in6_addr& to_in6_addr)
throw (InvalidFamily)

copy_out

[const]

Copy the IPvX raw address to an in6_addr structure.

Note that this address must be of AF_INET6 family.

Parameters:

to_in6_addrthe storage to copy the address to.

Returns: the number of copied octets.

size_t  copy_out (sockaddr& to_sockaddr)
throw (InvalidFamily)

copy_out

[const]

Copy the IPvX raw address to a sockaddr structure.

Copy the raw address held within an IPvX instance to an sockaddr structure and assign appropriately and set fields within sockaddr appropriately. The underlying address representation may be either IPv4 or IPv6.

Parameters:

to_sockaddrthe storage to copy the address to.

Returns: the number of copied octets.

size_t  copy_out (sockaddr_storage& to_sockaddr_storage)
throw (InvalidFamily)

copy_out

[const]

Copy the IPvX raw address to a sockaddr_storage structure.

Copy the raw address held within an IPvX instance to an sockaddr_storage structure and assign appropriately and set fields within sockaddr_storage appropriately. The underlying address representation may be either IPv4 or IPv6.

Parameters:

to_sockaddr_storagethe storage to copy the address to.

Returns: the number of copied octets.

size_t  copy_out (sockaddr_in& to_sockaddr_in)
throw (InvalidFamily)

copy_out

[const]

Copy the IPvX raw address to a sockaddr_in structure.

Copy the raw address held within an IPvX instance to an sockaddr_in structure and assign appropriately and set fields within sockaddr_in appropriately. The underlying address representation may be either IPv4 or IPv6.

Parameters:

to_sockaddr_inthe storage to copy the address to.

Returns: the number of copied octets.

size_t  copy_out (sockaddr_in6& to_sockaddr_in6)
throw (InvalidFamily)

copy_out

[const]

Copy the IPvX raw address to a sockaddr_in6 structure.

Copy the raw address held within an IPvX instance to a sockaddr_in6 structure and assign appropriately and set fields within sockaddr_in appropriately. The underlying address representation may be either IPv4 or IPv6.

Parameters:

to_sockaddr_in6the storage to copy the address to.

Returns: the number of copied octets.

size_t  copy_in (int family, const uint8_t *from_uint8)
throw (InvalidFamily)

copy_in

Copy a raw address of specified family type from specified memory location into IPvX structure.

Parameters:

familythe address family.
from_uint8the memory address to copy the address from.

Returns: the number of copied octets.

size_t  copy_in (const in_addr& from_in_addr)

copy_in

Copy a raw IPv4 address from a in_addr structure into IPvX structure.

Parameters:

from_in_addrthe storage 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 IPvX structure.

Parameters:

from_in6_addrthe 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 address from a sockaddr structure into IPvX structure.

Copy a raw address from a sockaddr structure, and set internal address family appropriately.

Parameters:

from_sockaddrthe storage to copy the address from.

Returns: the number of copied octets.

size_t  copy_in (const sockaddr_storage& from_sockaddr_storage)
throw (InvalidFamily)

copy_in

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

Copy a raw address from a sockaddr_storage structure, and set internal address family appropriately.

Parameters:

from_sockaddr_storagethe storage to copy the address from.

Returns: the number of copied octets.

size_t  copy_in (const sockaddr_in& from_sockaddr_in)
throw (InvalidFamily)

copy_in

Copy a raw address from a sockaddr_in structure into IPvX structure.

Copy a raw address from a sockaddr_in structure, and set internal address family appropriately.

Parameters:

from_sockaddr_inthe 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 IPvX structure.

Copy a raw address from sockaddr_in6 structure, and set internal address family appropriately.

Parameters:

from_sockaddr_in6the storage to copy the address from.

Returns: the number of copied octets.

IPvX  operator~ ()

operator~

[const]

Bitwise-Negation Operator

Returns: address complement (i.e., all 0s become 1s, and vice-versa).

IPvX  operator| (const IPvX& other)
throw (InvalidCast)

operator|

[const]

OR Operator

Parameters:

otherthe right-hand operand to OR with.

Returns: bitwise OR of two addresses.

IPvX  operator& (const IPvX& other)
throw (InvalidCast)

operator&

[const]

AND Operator

Parameters:

otherthe right-hand operand to AND with.

Returns: bitwise AND of two addresses.

IPvX  operator^ (const IPvX& other)
throw (InvalidCast)

operator^

[const]

XOR Operator

Parameters:

otherthe right-hand operand to XOR with.

Returns: bitwize eXclusive-OR of two addresses.

IPvX  operator<< (uint32_t left_shift)

operator<<

[const]

Operator <<

Parameters:

left_shiftthe number of bits to shift to the left.

Returns: IPvX address that is shift bitwise to the left.

IPvX  operator>> (uint32_t right_shift)

operator>>

[const]

Operator >>

Parameters:

right_shiftthe number of bits to shift to the right.

Returns: IPvX address that is shift bitwise to the right.

bool  operator< (const IPvX& other)

operator<

[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  operator== (const IPvX& other)

operator==

[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  operator!= (const IPvX& other)

operator!=

[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.

IPvX&  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.

IPvX&  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.

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.

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_class_a ()

is_class_a

[const]

Test if this address belongs to the IPv4 Class A address space (0.0.0.0/1).

This method applies only for IPv4, and always returns false for IPv6.

Returns: true if the address is a valid Class A address.

bool  is_class_b ()

is_class_b

[const]

Test if this address belongs to the IPv4 Class B address space (128.0.0.0/2).

This method applies only for IPv4, and always returns false for IPv6.

Returns: true if the address is a valid Class B address.

bool  is_class_c ()

is_class_c

[const]

Test if this address belongs to the IPv4 Class C address space (192.0.0.0/3).

This method applies only for IPv4, and always returns false for IPv6.

Returns: true if the address is a valid Class C address.

bool  is_experimental ()

is_experimental

[const]

Test if this address belongs to the IPv4 experimental Class E address space (240.0.0.0/4).

This method applies only for IPv4, and always returns false for IPv6.

Returns: true if the address is a valid experimental 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 a valid loopback address.

Returns: true if this address is a valid loopback address.

size_t  addr_bytelen (int family)
throw (InvalidFamily)

addr_bytelen

[static]

Get the address octet-size.

Note that this is a static function and is to be used without a particular object. Example: size_t my_size = IPvX::addr_bytelen(my_family);

Parameters:

familythe address family.

Returns: address size in number of octets for an address of address family of family.

size_t  addr_bytelen ()

addr_bytelen

[const]

Get the address octet-size for this address.

Note that this is not a static function, hence it has to be used with a particular object. Example: size_t my_size = ipvx.addr_bytelen();

Parameters:

familythe address family.

Returns: address size in number of octets for this IPvX address.

uint32_t  addr_bitlen (int family)
throw (InvalidFamily)

addr_bitlen

[static]

Get the address bit-length.

Note that this is a static function and is to be used without a particular object. Example: uint32_t my_bitlen = IPvX::addr_bitlen(my_family);

Parameters:

familythe address family.

Returns: address size in number of bits for an address of address family of family.

uint32_t  addr_bitlen ()

addr_bitlen

[const]

Get the address bit-length for this address.

Note that this is not a static function, hence it has to be used with a particular object. Example: uint32_t my_bitlen = ipvx.addr_bitlen();

Parameters:

familythe address family.

Returns: address size in number of bits for this IPvX address.

uint32_t  ip_multicast_base_address_mask_len (int family)
throw (InvalidFamily)

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: uint32_t my_len = IPvX::ip_multicast_base_address_mask_len(my_family);

Parameters:

familythe address family.

Returns: the multicast base address mask length for an address of address family of family.

uint32_t  ip_multicast_base_address_mask_len ()

ip_multicast_base_address_mask_len

[const]

Get the mask length for the multicast base address for this address.

Note that this is not a static function, hence it has to be used with a particular object. Example: size_t my_len = ipvx.ip_multicast_base_address_mask_len();

Parameters:

familythe address family.

Returns: the multicast base address mask length for this IPvX address.

uint32_t  ip_class_a_base_address_mask_len (int family)
throw (InvalidFamily)

ip_class_a_base_address_mask_len

[static]

Get the mask length for the Class A base address.

This method applies only for IPv4. Note that this is a static function and can be used without a particular object. Example: uint32_t my_len = IPvX::ip_class_a_base_address_mask_len(my_family);

Parameters:

familythe address family.

Returns: the Class A base address mask length for an address of address family of family.

uint32_t  ip_class_a_base_address_mask_len ()
throw (InvalidFamily)

ip_class_a_base_address_mask_len

[const]

Get the mask length for the Class A base address for this address.

This method applies only for IPv4. Note that this is not a static function, hence it has to be used with a particular object. Example: size_t my_len = ipvx.ip_class_a_base_address_mask_len();

Parameters:

familythe address family.

Returns: the Class A base address mask length for this IPvX address.

uint32_t  ip_class_b_base_address_mask_len (int family)
throw (InvalidFamily)

ip_class_b_base_address_mask_len

[static]

Get the mask length for the Class B base address.

This method applies only for IPv4. Note that this is a static function and can be used without a particular object. Example: uint32_t my_len = IPvX::ip_class_b_base_address_mask_len(my_family);

Parameters:

familythe address family.

Returns: the Class B base address mask length for an address of address family of family.

uint32_t  ip_class_b_base_address_mask_len ()
throw (InvalidFamily)

ip_class_b_base_address_mask_len

[const]

Get the mask length for the Class B base address for this address.

This method applies only for IPv4. Note that this is not a static function, hence it has to be used with a particular object. Example: size_t my_len = ipvx.ip_class_b_base_address_mask_len();

Parameters:

familythe address family.

Returns: the Class B base address mask length for this IPvX address.

uint32_t  ip_class_c_base_address_mask_len (int family)
throw (InvalidFamily)

ip_class_c_base_address_mask_len

[static]

Get the mask length for the Class C base address.

This method applies only for IPv4. Note that this is a static function and can be used without a particular object. Example: uint32_t my_len = IPvX::ip_class_c_base_address_mask_len(my_family);

Parameters:

familythe address family.

Returns: the Class C base address mask length for an address of address family of family.

uint32_t  ip_class_c_base_address_mask_len ()
throw (InvalidFamily)

ip_class_c_base_address_mask_len

[const]

Get the mask length for the Class C base address for this address.

This method applies only for IPv4. Note that this is not a static function, hence it has to be used with a particular object. Example: size_t my_len = ipvx.ip_class_c_base_address_mask_len();

Parameters:

familythe address family.

Returns: the Class C base address mask length for this IPvX address.

uint32_t  ip_experimental_base_address_mask_len (int family)
throw (InvalidFamily)

ip_experimental_base_address_mask_len

[static]

Get the mask length for the experimental base address.

This method applies only for IPv4. Note that this is a static function and can be used without a particular object. Example: uint32_t my_len = IPvX::ip_experimental_base_address_mask_len(my_family);

Parameters:

familythe address family.

Returns: the experimental base address mask length for an address of address family of family.

uint32_t  ip_experimental_base_address_mask_len ()
throw (InvalidFamily)

ip_experimental_base_address_mask_len

[const]

Get the mask length for the experimental base address for this address.

This method applies only for IPv4. Note that this is not a static function, hence it has to be used with a particular object. Example: size_t my_len = ipvx.ip_experimental_base_address_mask_len();

Parameters:

familythe address family.

Returns: the experimental base address mask length for this IPvX address.

IPvX  make_prefix (int family, uint32_t mask_len)
throw (InvalidFamily, InvalidNetmaskLength)

make_prefix

[static]

Make an IPvX mask prefix.

Parameters:

familythe address family.
mask_lenthe length of the mask to create.

Returns: a new IPvX address that contains a mask of length mask_len.

IPvX  make_prefix (uint32_t mask_len)
throw (InvalidNetmaskLength)

make_prefix

[const]

Make an IPvX mask prefix for the address family of this address.

Parameters:

mask_lenthe length of the mask to create.

Returns: a new IPvX address that contains a mask of length mask_len.

IPvX  mask_by_prefix_len (uint32_t prefix_len)
throw (InvalidNetmaskLength)

mask_by_prefix_len

[const]

Make an IPvX address prefix.

Parameters:

prefix_lenthe length of the mask of the prefix to create.

Returns: a new IPvX 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 IPvX address.

bool  is_ipv4 ()

is_ipv4

[const]

Test if this address is IPv4 address.

Returns: true if the address is IPv4.

bool  is_ipv6 ()

is_ipv6

[const]

Test if this address is IPv6 address.

Returns: true if the address is IPv6.

IPv4  get_ipv4 ()
throw (InvalidCast)

get_ipv4

[const]

Get IPv4 address.

Returns: IPv4 address contained with IPvX structure.

IPv6  get_ipv6 ()
throw (InvalidCast)

get_ipv6

[const]

Get IPv6 address.

Returns: IPv6 address contained with IPvX structure.

void  get (IPv4& to_ipv4)
throw (InvalidCast)

get

[const]

Assign address value to an IPv4 address.

Parameters:

to_ipv4IPv4 address to be assigned IPv4 value contained within this address.
void  get (IPv6& to_ipv6)
throw (InvalidCast)

get

[const]

Assign address value to an IPv6 address.

Parameters:

to_ipv6IPv6 address to be assigned IPv4 value contained within this address.
int  af ()

af

[const]

Get the address family.

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

uint32_t  ip_version ()
throw (InvalidFamily)

ip_version

[const]

Get the IP protocol version.

Returns: the IP protocol version of this address.

const string&  ip_version_str ()
throw (InvalidFamily)

ip_version_str

[const]

Get the human-readable string with the IP protocol version.

Returns: the human-readable string with the IP protocol version of this address.

uint32_t  bits (uint32_t lsb, uint32_t len)
throw (InvalidFamily)

bits

[const]

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.

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.

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.

const IPvX&  ZERO (int family)
throw (InvalidFamily)

ZERO

[static]

Pre-defined IPvX address constants.

const IPvX&  ANY (int family)
throw (InvalidFamily)

ANY

[static]

const IPvX&  ALL_ONES (int family)
throw (InvalidFamily)

ALL_ONES

[static]

const IPvX&  LOOPBACK (int family)
throw (InvalidFamily)

LOOPBACK

[static]

const IPvX&  MULTICAST_BASE (int family)
throw (InvalidFamily)

MULTICAST_BASE

[static]

const IPvX&  MULTICAST_ALL_SYSTEMS (int family)
throw (InvalidFamily)

MULTICAST_ALL_SYSTEMS

[static]

const IPvX&  MULTICAST_ALL_ROUTERS (int family)
throw (InvalidFamily)

MULTICAST_ALL_ROUTERS

[static]

const IPvX&  DVMRP_ROUTERS (int family)
throw (InvalidFamily)

DVMRP_ROUTERS

[static]

const IPvX&  OSPFIGP_ROUTERS (int family)
throw (InvalidFamily)

OSPFIGP_ROUTERS

[static]

const IPvX&  OSPFIGP_DESIGNATED_ROUTERS (int family)
throw (InvalidFamily)

OSPFIGP_DESIGNATED_ROUTERS

[static]

const IPvX&  RIP2_ROUTERS (int family)
throw (InvalidFamily)

RIP2_ROUTERS

[static]

const IPvX&  PIM_ROUTERS (int family)
throw (InvalidFamily)

PIM_ROUTERS

[static]

const IPvX&  SSM_ROUTERS (int family)
throw (InvalidFamily)

SSM_ROUTERS

[static]

const IPvX&  CLASS_A_BASE (int family)
throw (InvalidFamily)

CLASS_A_BASE

[static]

const IPvX&  CLASS_B_BASE (int family)
throw (InvalidFamily)

CLASS_B_BASE

[static]

const IPvX&  CLASS_C_BASE (int family)
throw (InvalidFamily)

CLASS_C_BASE

[static]

const IPvX&  EXPERIMENTAL_BASE (int family)
throw (InvalidFamily)

EXPERIMENTAL_BASE

[static]


Generated by: pavlin on kobe.xorp.net on Wed Jan 7 19:10:36 2009, using kdoc 2.0a54+XORP.