class IPv4

IPv4 address class. More...

Definition#include <ipv4.hh>
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Types

Public Methods

Public Static Methods


Detailed Description

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

 IPv4 ()

IPv4

Default constructor

The address value is initialized to INADDR_ANY.

 IPv4 (const IPv4& ipv4)

IPv4

Constructor from another IPv4 address.

Parameters:
ipv4the IPv4 address to assign the address value from.

explicit  IPv4 (uint32_t value)

IPv4

Constructor from an integer value.

Parameters:
value32-bit unsigned integer to assign to the address.

explicit  IPv4 (const uint8_t *from_uint8)

IPv4

Constructor from a (uint8_t *) memory pointer.

Parameters:
from_uint8the pointer to the memory to copy the address value from.

 IPv4 (const in_addr& from_in_addr)

IPv4

Constructor from in_addr structure.

Parameters:
from_in_addrthe storage to copy the address value from.

 IPv4 (const sockaddr& sa)
throw (InvalidFamily)

IPv4

Constructor from sockaddr structure.

Parameters:
sasockaddr to construct IPv4 addr from.

 IPv4 (const sockaddr_in& sin)
throw (InvalidFamily)

IPv4

Constructor from sockaddr_in structure.

Parameters:
sinsockaddr_in to construct IPv4 addr from.

 IPv4 (const char *from_string)
throw (InvalidString)

IPv4

Constructor from a string.

Parameters:
from_cstringC-style string in the IPv4 dotted decimal human-readable format used for initialization.

size_t  copy_out (uint8_t *to_uint8)

copy_out

[const]

Copy the IPv4 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)

copy_out

[const]

Copy the IP4 raw address to an in_addr structure.

Parameters:
to_in_addrthe storage to copy the address to.

Returns: the number of copied octets.

size_t  copy_out (sockaddr& to_sockaddr)

copy_out

[const]

Copy the IPv4 raw address to a sockaddr structure.

Copy the raw address held within an IPv4 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.

size_t  copy_out (sockaddr_in& to_sockaddr_in)

copy_out

[const]

Copy the IPv4 raw address to a sockaddr_in structure.

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

Parameters:
to_sockaddr_inthe 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 IPv4 address from specified memory location into IPv4 structure.

Parameters:
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 IPv4 structure.

Parameters:
from_in_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 IPv4 structure.

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

Parameters:
from_sockaddrthe 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 IPv4 structure.

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

Parameters:
from_sockaddr_inthe storage to copy the address from.

Returns: the number of copied octets.

inline IPv4  operator~ ()

operator~

[const]

Bitwise-Negation Operator

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

inline IPv4  operator| (const IPv4& other)

operator|

[const]

OR Operator

Parameters:
otherthe right-hand operand to OR with.

Returns: bitwise OR of two addresses.

inline IPv4  operator& (const IPv4& other)

operator&

[const]

AND Operator

Parameters:
otherthe right-hand operand to AND with.

Returns: bitwise AND of two addresses.

inline IPv4  operator^ (const IPv4& other)

operator^

[const]

XOR Operator

Returns: eXclusive-OR of two addresses.

IPv4  operator<< (uint32_t left_shift)

operator<<

[const]

Operator <<

Parameters:
left_shiftthe number of bits to shift to the left.

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

IPv4  operator>> (uint32_t right_shift)

operator>>

[const]

Operator >>

Parameters:
right_shiftthe number of bits to shift to the right.

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

bool  operator< (const IPv4& 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 IPv4& 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 IPv4& 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.

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

IPv4&  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_nodelocal_multicast ()

is_nodelocal_multicast

[const]

Test if this address is a valid node-local multicast address.

Returns: true if the address is a valid multicast address, and the scope of the address is node-local. XXX: in IPv4 there is no node-local multicast scope, therefore the return value is always false.

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.

inline size_t  addr_size ()

addr_size

[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 = IPv4::addr_size(); OK size_t my_size = ipv4.addr_size(); OK

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 = IPv4::addr_bitlen(); OK uint32_t my_bitlen = ipv4.addr_bitlen(); OK

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: uint32_t my_len = IPv4::ip_multicast_base_address_mask_len(); OK uint32_t my_len = ipv4.ip_multicast_base_address_mask_len(); OK

Returns: the multicast base address mask length for family AF_INET.

IPv4  make_prefix (uint32_t mask_len)
throw (InvalidNetmaskLength)

make_prefix

[static]

Make an IPv4 mask prefix.

Parameters:
mask_lenthe length of the mask to create.

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

inline IPv4  mask_by_prefix_len (uint32_t mask_len)
throw (InvalidNetmaskLength)

mask_by_prefix_len

[const]

Make an IPv4 address prefix.

Parameters:
prefix_lenthe length of the mask of the prefix to create.

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

inline uint32_t  addr ()

addr

[const]

Get the uint32_t raw value of this address.

Returns: the value of this IPv4 address as an unsigned 32-bit integer.

inline void  set_addr (uint32_t value)

set_addr

Set the address value.

Parameters:
valueunsigned 32-bit integer value to set the address to.

enum { AF = AF_INET }

Constant for address family

enum { IPV = 4 }

Constant for IP protocol version

inline const int  af ()

af

[static]

Get the address family.

Returns: the address family of this address.

inline const 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:
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.

inline IPv4  ZERO (int af = AF_INET)

ZERO

[static]

Pre-defined IPv4 address constants.

inline IPv4  ANY (int af = AF_INET)

ANY

[static]

inline IPv4  ALL_ONES (int af = AF_INET)

ALL_ONES

[static]

inline IPv4  MULTICAST_BASE (int af = AF_INET)

MULTICAST_BASE

[static]

inline IPv4  MULTICAST_ALL_SYSTEMS (int af = AF_INET)

MULTICAST_ALL_SYSTEMS

[static]

inline IPv4  MULTICAST_ALL_ROUTERS (int af = AF_INET)

MULTICAST_ALL_ROUTERS

[static]

inline IPv4  DVMRP_ROUTERS (int af = AF_INET)

DVMRP_ROUTERS

[static]

inline IPv4  OSPFIGP_ROUTERS (int af = AF_INET)

OSPFIGP_ROUTERS

[static]

inline IPv4  OSPFIGP_DESIGNATED_ROUTERS (int af = AF_INET)

OSPFIGP_DESIGNATED_ROUTERS

[static]

inline IPv4  RIP2_ROUTERS (int af = AF_INET)

RIP2_ROUTERS

[static]

inline IPv4  PIM_ROUTERS (int af = AF_INET)

PIM_ROUTERS

[static]


Generated by: pavlin on possum.icir.org on Thu Nov 6 23:46:46 2003, using kdoc 2.0a54+XORP.