|
xorp
|
A template class for subnets. More...
#include <ipnet.hh>
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. | |
| IPNet & | operator= (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). | |
| IPNet & | operator-- () |
| Decrement Operator. | |
| IPNet & | operator++ () |
| 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) |
| A | 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). | |
| A | 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 | |
| A | _masked_addr |
| uint8_t | _prefix_len |
A template class for subnets.
A "subnet" is specified by a base "address" and a "prefix length".
Default constructor taking no parameters.
Default value has INADDR_ANY/0.
| IPNet< A >::IPNet | ( | const A & | a, |
| uint8_t | prefix_len | ||
| ) | throw (InvalidNetmaskLength) [inline] |
Constructor from a given base address and a prefix length.
| a | base address for the subnet. |
| prefix_len | length of subnet mask (e.g., class C nets would have prefix_len=24). |
| IPNet< A >::IPNet | ( | const char * | from_cstring | ) | throw (InvalidString, InvalidNetmaskLength) [inline] |
Constructor from a string.
| from_cstring | C-style string with slash separated address and prefix length. |
Copy constructor.
| n | the subnet to copy from. |
| static int IPNet< A >::af | ( | ) | [inline, static] |
Test if a subnet contains (or is equal to) another subnet.
in LaTeX, x.contains(y) would be $x y$
| other | the subnet to test against. |
| bool IPNet< A >::contains | ( | const A & | addr | ) | const [inline] |
Test if an address is within a subnet.
| addr | the address to test against. |
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();
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();
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();
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();
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();
| bool IPNet< A >::is_class_a | ( | ) | const |
| bool IPNet< A >::is_class_b | ( | ) | const |
| bool IPNet< A >::is_class_c | ( | ) | const |
| bool IPNet< A >::is_experimental | ( | ) | const |
| bool IPNet< A >::is_multicast | ( | ) | const [inline] |
| 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.
Reimplemented in IPvXNet.
| bool IPNet< A >::is_valid | ( | ) | const [inline] |
| const A& IPNet< A >::masked_addr | ( | ) | const [inline] |
| A IPNet< A >::netmask | ( | ) | const [inline] |
| uint8_t IPNet< A >::prefix_len | ( | ) | const [inline] |
| string IPNet< A >::str | ( | ) | const |
| A IPNet< A >::top_addr | ( | ) | const [inline] |