xorp

IPNet< A > Class Template Reference

A template class for subnets. More...

#include <ipnet.hh>

Inheritance diagram for IPNet< A >:
IPvXNet

List of all members.

Public Member Functions

 IPNet ()
 Default constructor taking no parameters.
 IPNet (const A &a, uint8_t prefix_len) throw (InvalidNetmaskLength)
 Constructor from a given base address and a prefix length.
 IPNet (const char *from_cstring) throw (InvalidString, InvalidNetmaskLength)
 Constructor from a string.
 IPNet (const IPNet &n)
 Copy constructor.
IPNetoperator= (const IPNet &n)
 Assignment operator.
bool operator== (const IPNet &other) const
 Equality Operator.
bool operator< (const IPNet &other) const
 Less-than comparison for subnets (see body for description).
IPNetoperator-- ()
 Decrement Operator.
IPNetoperator++ ()
 Increment Operator.
bool operator== (const U32Range &range) const
 Equality Operator for U32Range operand.
bool operator!= (const U32Range &range) const
 Non-equality Operator for U32Range operand.
bool operator< (const U32Range &range) const
 Less-than comparison for prefix lengths for U32Range operand.
bool operator<= (const U32Range &range) const
 Less-than or equal comparison for prefix lengths for U32Range operand.
bool operator> (const U32Range &range) const
 Greater-than comparison for prefix lengths for U32Range operand.
bool operator>= (const U32Range &range) const
 Greater-than or equal comparison for prefix lengths for U32Range operand.
string str () const
 Convert this address from binary form to presentation format.
bool is_valid () const
 Test if the object contains a real (non-default) value.
bool is_overlap (const IPNet &other) const
 Test if subnets overlap.
bool contains (const IPNet &other) const
 Test if a subnet contains (or is equal to) another subnet.
bool contains (const A &addr) const
 Test if an address is within a subnet.
uint32_t overlap (const IPNet &other) const
 Determine the number of the most significant bits overlapping with another subnet.
const A & masked_addr () const
 Get the base address.
A & masked_addr_nc ()
uint8_t prefix_len () const
 Get the prefix length.
void set_prefix_len (uint8_t v)
netmask () const
 Get the network mask.
bool is_unicast () const
 Test if this subnet is a unicast prefix.
bool is_multicast () const
 Test if this subnet is within the multicast address range.
bool is_class_a () const
 Test if this subnet is within the IPv4 Class A address range (0.0.0.0/1).
bool is_class_b () const
 Test if this subnet is within the IPv4 Class B address range (128.0.0.0/2).
bool is_class_c () const
 Test if this subnet is within the IPv4 Class C address range (192.0.0.0/3).
bool is_experimental () const
 Test if this subnet is within the IPv4 experimental Class E address range (240.0.0.0/4).
top_addr () const
 Get the highest address within this subnet.
template<>
 IPNet (const IPvX &ipvx, uint8_t prefix_len) throw(InvalidNetmaskLength)

Static Public Member Functions

static int af ()
 Get the address family.
static const IPNet< A > ip_multicast_base_prefix ()
 Return the subnet containing all multicast addresses.
static const IPNet< A > ip_class_a_base_prefix ()
 Return the subnet containing all IPv4 Class A addresses (0.0.0.0/1).
static const IPNet< A > ip_class_b_base_prefix ()
 Return the subnet containing all IPv4 Class B addresses (128.0.0.0/2).
static const IPNet< A > ip_class_c_base_prefix ()
 Return the subnet containing all IPv4 Class C addresses (192.0.0.0/3).
static const IPNet< A > ip_experimental_base_prefix ()
 Return the subnet containing all IPv4 experimental Class E addresses (240.0.0.0/4).
static IPNet< A > common_subnet (const IPNet< A > x, const IPNet< A > y)
 Get the smallest subnet containing both subnets.

Private Member Functions

void initialize_from_string (const char *s) throw (InvalidString, InvalidNetmaskLength)
template<>
void initialize_from_string (const char *cp) throw(InvalidString, InvalidNetmaskLength)

Private Attributes

_masked_addr
uint8_t _prefix_len

Detailed Description

template<class A>
class IPNet< A >

A template class for subnets.

A "subnet" is specified by a base "address" and a "prefix length".


Constructor & Destructor Documentation

template<class A>
IPNet< A >::IPNet ( ) [inline]

Default constructor taking no parameters.

Default value has INADDR_ANY/0.

template<class A>
IPNet< A >::IPNet ( const A &  a,
uint8_t  prefix_len 
) throw (InvalidNetmaskLength) [inline]

Constructor from a given base address and a prefix length.

Parameters:
abase address for the subnet.
prefix_lenlength of subnet mask (e.g., class C nets would have prefix_len=24).
template<class A>
IPNet< A >::IPNet ( const char *  from_cstring) throw (InvalidString, InvalidNetmaskLength) [inline]

Constructor from a string.

Parameters:
from_cstringC-style string with slash separated address and prefix length.
template<class A>
IPNet< A >::IPNet ( const IPNet< A > &  n) [inline]

Copy constructor.

Parameters:
nthe subnet to copy from.

Member Function Documentation

template<class A>
static int IPNet< A >::af ( ) [inline, static]

Get the address family.

Returns:
the address family of this address.
template<class A>
static IPNet<A> IPNet< A >::common_subnet ( const IPNet< A >  x,
const IPNet< A >  y 
) [inline, static]

Get the smallest subnet containing both subnets.

Returns:
the smallest subnet containing both subnets passed as arguments.
template<class A >
bool IPNet< A >::contains ( const IPNet< A > &  other) const

Test if a subnet contains (or is equal to) another subnet.

in LaTeX, x.contains(y) would be $x y$

Parameters:
otherthe subnet to test against.
Returns:
true if this subnet contains or is equal to other.
template<class A>
bool IPNet< A >::contains ( const A &  addr) const [inline]

Test if an address is within a subnet.

Parameters:
addrthe address to test against.
Returns:
true if addr is within this subnet.
template<class A>
static const IPNet<A> IPNet< A >::ip_class_a_base_prefix ( ) [static]

Return the subnet containing all IPv4 Class A addresses (0.0.0.0/1).

This method applies only for IPv4. Note that this is a static function and can be used without a particular object. Example: IPv4Net my_prefix = IPv4Net::ip_class_a_base_prefix(); IPv4Net my_prefix = ipv4net.ip_class_a_base_prefix();

Returns:
the subnet containing Class A addresses.
template<class A>
static const IPNet<A> IPNet< A >::ip_class_b_base_prefix ( ) [static]

Return the subnet containing all IPv4 Class B addresses (128.0.0.0/2).

This method applies only for IPv4. Note that this is a static function and can be used without a particular object. Example: IPv4Net my_prefix = IPv4Net::ip_class_b_base_prefix(); IPv4Net my_prefix = ipv4net.ip_class_b_base_prefix();

Returns:
the subnet containing Class B addresses.
template<class A>
static const IPNet<A> IPNet< A >::ip_class_c_base_prefix ( ) [static]

Return the subnet containing all IPv4 Class C addresses (192.0.0.0/3).

This method applies only for IPv4. Note that this is a static function and can be used without a particular object. Example: IPv4Net my_prefix = IPv4Net::ip_class_c_base_prefix(); IPv4Net my_prefix = ipv4net.ip_class_c_base_prefix();

Returns:
the subnet containing Class C addresses.
template<class A>
static const IPNet<A> IPNet< A >::ip_experimental_base_prefix ( ) [static]

Return the subnet containing all IPv4 experimental Class E addresses (240.0.0.0/4).

This method applies only for IPv4. Note that this is a static function and can be used without a particular object. Example: IPv4Net my_prefix = IPv4Net::ip_experimental_base_prefix(); IPv4Net my_prefix = ipv4net.ip_experimental_base_prefix();

Returns:
the subnet containing experimental addresses.
template<class A>
static const IPNet<A> IPNet< A >::ip_multicast_base_prefix ( ) [inline, static]

Return the subnet containing all multicast addresses.

Note that this is a static function and can be used without a particular object. Example: IPv4Net my_prefix = IPv4Net::ip_multicast_base_prefix(); IPv4Net my_prefix = ipv4net.ip_multicast_base_prefix();

Returns:
the subnet containing multicast addresses.
template<class A>
bool IPNet< A >::is_class_a ( ) const

Test if this subnet is within the IPv4 Class A address range (0.0.0.0/1).

This method applies only for IPv4.

Returns:
true if this subnet is within the IPv4 Class A address range.

Reimplemented in IPvXNet.

template<class A>
bool IPNet< A >::is_class_b ( ) const

Test if this subnet is within the IPv4 Class B address range (128.0.0.0/2).

This method applies only for IPv4.

Returns:
true if this subnet is within the IPv4 Class B address range.

Reimplemented in IPvXNet.

template<class A>
bool IPNet< A >::is_class_c ( ) const

Test if this subnet is within the IPv4 Class C address range (192.0.0.0/3).

This method applies only for IPv4.

Returns:
true if this subnet is within the IPv4 Class C address range.

Reimplemented in IPvXNet.

template<class A>
bool IPNet< A >::is_experimental ( ) const

Test if this subnet is within the IPv4 experimental Class E address range (240.0.0.0/4).

This method applies only for IPv4.

Returns:
true if this subnet is within the IPv4 experimental address range.

Reimplemented in IPvXNet.

template<class A>
bool IPNet< A >::is_multicast ( ) const [inline]

Test if this subnet is within the multicast address range.

Returns:
true if this subnet is within the multicast address range.

Reimplemented in IPvXNet.

template<class A >
bool IPNet< A >::is_overlap ( const IPNet< A > &  other) const

Test if subnets overlap.

Parameters:
otherthe subnet to compare against.
Returns:
true if there is some overlap between the two subnets.
template<class A>
bool IPNet< A >::is_unicast ( ) const

Test if this subnet is a unicast prefix.

In case of IPv4 all prefixes that fall within the Class A, Class B or Class C address space are unicast. In case of IPv6 all prefixes that don't contain the multicast address space are unicast. Note that the default route (0.0.0.0/0 for IPv4 or ::/0 for IPv6) is also considered an unicast prefix.

Returns:
true if this subnet is a unicast prefix.

Reimplemented in IPvXNet.

template<class A>
bool IPNet< A >::is_valid ( ) const [inline]

Test if the object contains a real (non-default) value.

Returns:
true if the object stores a real (non-default) value.
template<class A>
const A& IPNet< A >::masked_addr ( ) const [inline]

Get the base address.

Returns:
the base address for this subnet.
template<class A>
A IPNet< A >::netmask ( ) const [inline]

Get the network mask.

Returns:
the netmask associated with this subnet.
template<class A>
bool IPNet< A >::operator!= ( const U32Range range) const [inline]

Non-equality Operator for U32Range operand.

Parameters:
rangethe right-hand operand to compare against.
Returns:
true if the prefix length falls outside the range defined by the right-hand operand.
template<class A >
IPNet< A > & IPNet< A >::operator++ ( )

Increment Operator.

The numerical value of the prefix address is incremented by one. Example: incrementing 128.2.0.0/16 results in 128.3.0.0/16.

Returns:
a reference to this subnet after the increment
template<class A >
IPNet< A > & IPNet< A >::operator-- ( )

Decrement Operator.

The numerical value of the prefix address is decrement by one. Example: decrementing 128.2.0.0/16 results in 128.1.0.0/16.

Returns:
a reference to this subnet after the decrement
template<class A>
bool IPNet< A >::operator< ( const U32Range range) const [inline]

Less-than comparison for prefix lengths for U32Range operand.

Parameters:
rangethe right-hand side of the comparison.
Returns:
true if the prefix length is bellow the range defined by the right-hand operand.
template<class A >
bool IPNet< A >::operator< ( const IPNet< A > &  other) const

Less-than comparison for subnets (see body for description).

Parameters:
otherthe right-hand side of the comparison.
Returns:
true if the left-hand side is "smaller" than the right-hand side according to the chosen order.
template<class A>
bool IPNet< A >::operator<= ( const U32Range range) const [inline]

Less-than or equal comparison for prefix lengths for U32Range operand.

Parameters:
rangethe right-hand side of the comparison.
Returns:
true if the prefix length is bellow or within the range defined by the right-hand operand.
template<class A>
IPNet& IPNet< A >::operator= ( const IPNet< A > &  n) [inline]

Assignment operator.

Parameters:
nthe subnet to assign from.
Returns:
the subnet after the assignment.
template<class A>
bool IPNet< A >::operator== ( const U32Range range) const [inline]

Equality Operator for U32Range operand.

Parameters:
rangethe right-hand operand to compare against.
Returns:
true if the prefix length falls inside the range defined by the right-hand operand.
template<class A>
bool IPNet< A >::operator== ( const IPNet< A > &  other) const [inline]

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.
template<class A>
bool IPNet< A >::operator> ( const U32Range range) const [inline]

Greater-than comparison for prefix lengths for U32Range operand.

Parameters:
rangethe right-hand side of the comparison.
Returns:
true if the prefix length is above the range defined by the right-hand operand.
template<class A>
bool IPNet< A >::operator>= ( const U32Range range) const [inline]

Greater-than or equal comparison for prefix lengths for U32Range operand.

Parameters:
rangethe right-hand side of the comparison.
Returns:
true if the prefix length is above or within the range defined by the right-hand operand.
template<class A >
uint32_t IPNet< A >::overlap ( const IPNet< A > &  other) const [inline]

Determine the number of the most significant bits overlapping with another subnet.

Parameters:
otherthe subnet to test against.
Returns:
the number of bits overlapping between other and this subnet.
template<class A>
uint8_t IPNet< A >::prefix_len ( ) const [inline]

Get the prefix length.

Returns:
the prefix length for this subnet.
template<class A >
string IPNet< A >::str ( ) const

Convert this address from binary form to presentation format.

Returns:
C++ string with the human-readable ASCII representation of the address.
template<class A>
A IPNet< A >::top_addr ( ) const [inline]

Get the highest address within this subnet.

Returns:
the highest address within this subnet.

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