libtins
4.0
|
Abstraction of an IPv4 address. More...
#include <ip_address.h>
Public Member Functions | |
IPv4Address (const char *ip=0) | |
Constructor taking a const char*. More... | |
IPv4Address (const std::string &ip) | |
Constructor taking a std::string. More... | |
IPv4Address (uint32_t ip) | |
Constructor taking a IP address represented as a big endian integer. More... | |
operator uint32_t () const | |
User defined conversion to big endian integral value. | |
std::string | to_string () const |
Retrieve the string representation of this address. More... | |
bool | operator== (const IPv4Address &rhs) const |
Compare this IPv4Address for equality. More... | |
bool | operator!= (const IPv4Address &rhs) const |
Compare this IPv4Address for inequality. More... | |
bool | operator< (const IPv4Address &rhs) const |
Compare this IPv4Address for less-than inequality. More... | |
bool | operator<= (const IPv4Address &rhs) const |
Compares this address for less-than equality. More... | |
bool | operator> (const IPv4Address &rhs) const |
Compare this IPv4Address for greater-than inequality. More... | |
bool | operator>= (const IPv4Address &rhs) const |
Compares this address for greater-than equality. More... | |
IPv4Address | operator& (const IPv4Address &mask) const |
Apply a mask to this address. More... | |
IPv4Address | operator| (const IPv4Address &mask) const |
Apply a mask to this address. More... | |
IPv4Address | operator~ () const |
bool | is_private () const |
Returns true if this is a private IPv4 address. More... | |
bool | is_loopback () const |
Returns true if this is a loopback IPv4 address. More... | |
bool | is_multicast () const |
Returns true if this is a multicast IPv4 address. More... | |
bool | is_unicast () const |
Returns true if this is an unicast IPv4 address. | |
bool | is_broadcast () const |
Returns true if this is a broadcast IPv4 address. | |
size_t | size () const |
Returns the size of an IPv4 Address. More... | |
Static Public Member Functions | |
static IPv4Address | from_prefix_length (uint32_t prefix_length) |
Constructs an IPv4 address from a prefix length. More... | |
Static Public Attributes | |
static const size_t | address_size = sizeof(uint32_t) |
static const IPv4Address | broadcast |
Friends | |
TINS_API friend std::ostream & | operator<< (std::ostream &output, const IPv4Address &addr) |
Writes this address to a std::ostream. More... | |
Abstraction of an IPv4 address.
Tins::IPv4Address::IPv4Address | ( | const char * | ip = 0 | ) |
Constructor taking a const char*.
Constructs an IPv4Address from a dotted-notation address cstring. If the pointer provided is null, then a default IPv4Address object is constructed, which corresponds to the 0.0.0.0 address.
ip | const char* containing the dotted-notation address. |
Tins::IPv4Address::IPv4Address | ( | const std::string & | ip | ) |
Constructor taking a std::string.
Constructs an IPv4Address from a dotted-notation std::strings
ip | std::string containing the dotted-notation address. |
|
explicit |
|
static |
Constructs an IPv4 address from a prefix length.
prefix_length | The length of the prefix |
bool Tins::IPv4Address::is_loopback | ( | ) | const |
Returns true if this is a loopback IPv4 address.
This method returns true if this address is in the address range 127.0.0.0/8, false otherwise.
bool Tins::IPv4Address::is_multicast | ( | ) | const |
Returns true if this is a multicast IPv4 address.
This method returns true if this address is in the address range 224.0.0.0/4, false otherwise.
bool Tins::IPv4Address::is_private | ( | ) | const |
Returns true if this is a private IPv4 address.
This takes into account the private network ranges defined in RFC 1918. Therefore, this method returns true if this address is in any of the following network ranges, false otherwise:
|
inline |
Compare this IPv4Address for inequality.
rhs | The address to be compared. |
IPv4Address Tins::IPv4Address::operator& | ( | const IPv4Address & | mask | ) | const |
Apply a mask to this address.
mask | The mask to be applied |
|
inline |
Compare this IPv4Address for less-than inequality.
rhs | The address to be compared. |
|
inline |
Compares this address for less-than equality.
rhs | The address to be compared to. |
|
inline |
Compare this IPv4Address for equality.
rhs | The address to be compared. |
|
inline |
Compare this IPv4Address for greater-than inequality.
rhs | The address to be compared. |
|
inline |
Compares this address for greater-than equality.
rhs | The address to be compared to. |
IPv4Address Tins::IPv4Address::operator| | ( | const IPv4Address & | mask | ) | const |
Apply a mask to this address.
mask | The mask to be applied |
IPv4Address Tins::IPv4Address::operator~ | ( | ) | const |
not operator (invert)
|
inline |
Returns the size of an IPv4 Address.
This returns the value of IPv4Address::address_size
string Tins::IPv4Address::to_string | ( | ) | const |
Retrieve the string representation of this address.
|
friend |
Writes this address to a std::ostream.
This method writes addr in a dotted-string notation address to the std::ostream argument.
output | The std::ostream in which to write the address. |
addr | The IPv4Address to be written. |
|
static |
The address size.
|
static |
The broadcast address.