libtins  4.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
Tins::IPv4Address Class Reference

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

Detailed Description

Abstraction of an IPv4 address.

Constructor & Destructor Documentation

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.

Parameters
ipconst 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

Parameters
ipstd::string containing the dotted-notation address.
Tins::IPv4Address::IPv4Address ( uint32_t  ip)
explicit

Constructor taking a IP address represented as a big endian integer.

This constructor should be used internally by PDUs that handle IP addresses. The provided integer must be be in big endian.

Member Function Documentation

IPv4Address Tins::IPv4Address::from_prefix_length ( uint32_t  prefix_length)
static

Constructs an IPv4 address from a prefix length.

Parameters
prefix_lengthThe 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:

  • 192.168.0.0/16
  • 10.0.0.0/8
  • 172.16.0.0/12
bool Tins::IPv4Address::operator!= ( const IPv4Address rhs) const
inline

Compare this IPv4Address for inequality.

Parameters
rhsThe address to be compared.
Returns
bool indicating whether this address is distinct from rhs.
IPv4Address Tins::IPv4Address::operator& ( const IPv4Address mask) const

Apply a mask to this address.

Parameters
maskThe mask to be applied
Returns
The result of applying the mask to this address
bool Tins::IPv4Address::operator< ( const IPv4Address rhs) const
inline

Compare this IPv4Address for less-than inequality.

Parameters
rhsThe address to be compared.
Returns
bool indicating whether this address is less-than rhs.
bool Tins::IPv4Address::operator<= ( const IPv4Address rhs) const
inline

Compares this address for less-than equality.

Parameters
rhsThe address to be compared to.
Returns
bool indicating whether this address is equal or less-than rhs.
bool Tins::IPv4Address::operator== ( const IPv4Address rhs) const
inline

Compare this IPv4Address for equality.

Parameters
rhsThe address to be compared.
Returns
bool indicating whether this address equals rhs.
bool Tins::IPv4Address::operator> ( const IPv4Address rhs) const
inline

Compare this IPv4Address for greater-than inequality.

Parameters
rhsThe address to be compared.
Returns
bool indicating whether this address is greater-than rhs.
bool Tins::IPv4Address::operator>= ( const IPv4Address rhs) const
inline

Compares this address for greater-than equality.

Parameters
rhsThe address to be compared to.
Returns
bool indicating whether this address is equal or greater-than rhs.
IPv4Address Tins::IPv4Address::operator| ( const IPv4Address mask) const

Apply a mask to this address.

Parameters
maskThe mask to be applied
Returns
The result of applying the mask to this address
IPv4Address Tins::IPv4Address::operator~ ( ) const

not operator (invert)

size_t Tins::IPv4Address::size ( ) const
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.

Returns
std::string containing the representation of this address.

Friends And Related Function Documentation

TINS_API friend std::ostream& operator<< ( std::ostream &  output,
const IPv4Address addr 
)
friend

Writes this address to a std::ostream.

This method writes addr in a dotted-string notation address to the std::ostream argument.

Parameters
outputThe std::ostream in which to write the address.
addrThe IPv4Address to be written.
Returns
std::stream& pointing to output.

Member Data Documentation

const size_t Tins::IPv4Address::address_size = sizeof(uint32_t)
static

The address size.

const IPv4Address Tins::IPv4Address::broadcast
static

The broadcast address.


The documentation for this class was generated from the following files: