A "subnet" is specified by a base "address" and a "prefix length".
IPNet ()
| IPNet |
Default constructor taking no parameters.
Default value has INADDR_ANY/0.
IPNet (const A& a, uint32_t prefix_len)
throw (InvalidNetmaskLength) | IPNet |
Constructor from a given base address and a prefix length.
Parameters:
a | base address for the subnet. |
prefix_len | length of subnet mask (e.g., class C nets would have prefix_len=24). |
IPNet (const char *from_cstring)
throw (InvalidString, InvalidNetmaskLength) | IPNet |
Constructor from a string.
Parameters:
from_cstring | C-style string with slash separated address and prefix length. |
IPNet (const IPNet& n)
| IPNet |
Copy constructor
Parameters:
n | the subnet to copy from. |
IPNet& operator= (const IPNet& n)
| operator= |
Assignment operator
Parameters:
n | the subnet to assign from. |
Returns: the subnet after the assignment.
bool operator== (const IPNet& other)
| operator== |
[const]
Equality Operator
Parameters:
other | the right-hand operand to compare against. |
Returns: true if the left-hand operand is numerically same as the right-hand operand.
bool operator< (const IPNet& other)
| operator< |
[const]
Less-than comparison for subnets (see body for description).
Parameters:
other | the 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.
IPNet& operator-- ()
| 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
IPNet& operator++ ()
| 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
bool operator== (const U32Range& range)
| operator== |
[const]
Equality Operator for U32Range operand.
Parameters:
range | the right-hand operand to compare against. |
Returns: true if the prefix length falls inside the range defined by the right-hand operand.
bool operator!= (const U32Range& range)
| operator!= |
[const]
Non-equality Operator for U32Range operand.
Parameters:
range | the right-hand operand to compare against. |
Returns: true if the prefix length falls outside the range defined by the right-hand operand.
bool operator< (const U32Range& range)
| operator< |
[const]
Less-than comparison for prefix lengths for U32Range operand.
Parameters:
range | the right-hand side of the comparison. |
Returns: true if the prefix length is bellow the range defined by the right-hand operand.
bool operator<= (const U32Range& range)
| operator<= |
[const]
Less-than or equal comparison for prefix lengths for U32Range operand.
Parameters:
range | the right-hand side of the comparison. |
Returns: true if the prefix length is bellow or within the range defined by the right-hand operand.
bool operator> (const U32Range& range)
| operator> |
[const]
Greater-than comparison for prefix lengths for U32Range operand.
Parameters:
range | the right-hand side of the comparison. |
Returns: true if the prefix length is above the range defined by the right-hand operand.
bool operator>= (const U32Range& range)
| operator>= |
[const]
Greater-than or equal comparison for prefix lengths for U32Range operand.
Parameters:
range | the right-hand side of the comparison. |
Returns: true if the prefix length is above or within the range defined by the right-hand operand.
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_valid ()
| is_valid |
[const]
Test if the object contains a real (non-default) value.
Returns: true if the object stores a real (non-default) value.
bool is_overlap (const IPNet& other)
| is_overlap |
[const]
Test if subnets overlap.
Parameters:
other | the subnet to compare against. |
Returns: true if there is some overlap between the two subnets.
bool contains (const IPNet& other)
| contains |
[const]
Test if a subnet contains (or is equal to) another subnet.
in LaTeX, x.contains(y) would be $x \superseteq y$
Parameters:
other | the subnet to test against. |
Returns: true if this subnet contains or is equal to other.
bool contains (const A& addr)
| contains |
[const]
Test if an address is within a subnet.
Parameters:
addr | the address to test against. |
Returns: true if addr is within this subnet.
uint32_t overlap (const IPNet& other)
| overlap |
[const]
Determine the number of the most significant bits overlapping with another subnet.
Parameters:
other | the subnet to test against. |
Returns: the number of bits overlapping between other and this subnet.
int af ()
| af |
[static]
Get the address family.
Returns: the address family of this address.
const A& masked_addr ()
| masked_addr |
[const]
Get the base address.
Returns: the base address for this subnet.
uint32_t prefix_len ()
| prefix_len |
[const]
Get the prefix length.
Returns: the prefix length for this subnet.
A netmask ()
| netmask |
[const]
Get the network mask.
Returns: the netmask associated with this subnet.
bool is_unicast ()
| 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.
const IPNet<A> ip_multicast_base_prefix ()
| ip_multicast_base_prefix |
[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.
const IPNet<A> ip_class_a_base_prefix ()
| 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.
const IPNet<A> ip_class_b_base_prefix ()
| 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.
const IPNet<A> ip_class_c_base_prefix ()
| 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.
const IPNet<A> ip_experimental_base_prefix ()
| 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.
bool is_multicast ()
| is_multicast |
[const]
Test if this subnet is within the multicast address range.
Returns: true if this subnet is within the multicast address range.
bool is_class_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.
bool is_class_b ()
| 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.
bool is_class_c ()
| 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.
bool is_experimental ()
| 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.
A top_addr ()
| top_addr |
[const]
Get the highest address within this subnet.
Returns: the highest address within this subnet.
IPNet<A> common_subnet (const IPNet<A> x, const IPNet<A> y)
| common_subnet |
[static]
Get the smallest subnet containing both subnets.
Returns: the smallest subnet containing both subnets passed as arguments.