mavtables  0.2.1
MAVLink router and firewall.
Public Member Functions | Friends | Related Functions | List of all members
IPAddress Class Reference

#include <IPAddress.hpp>

Collaboration diagram for IPAddress:
Collaboration graph

Public Member Functions

 IPAddress (const IPAddress &other)=default
 
 IPAddress (IPAddress &&other)=default
 
 IPAddress (const IPAddress &other, unsigned int port)
 
 IPAddress (unsigned long address, unsigned int port=0)
 
 IPAddress (std::string address)
 
unsigned long address () const
 
unsigned int port () const
 
IPAddressoperator= (const IPAddress &other)=default
 
IPAddressoperator= (IPAddress &&other)=default
 

Friends

std::ostream & operator<< (std::ostream &os, const IPAddress &ipaddress)
 

Related Functions

(Note that these are not member functions.)

bool operator== (const IPAddress &lhs, const IPAddress &rhs)
 
bool operator!= (const IPAddress &lhs, const IPAddress &rhs)
 
bool operator< (const IPAddress &lhs, const IPAddress &rhs)
 
bool operator> (const IPAddress &lhs, const IPAddress &rhs)
 
bool operator<= (const IPAddress &lhs, const IPAddress &rhs)
 
bool operator>= (const IPAddress &lhs, const IPAddress &rhs)
 
IPAddress dnslookup (const std::string &url)
 

Detailed Description

An IP address with optional port number.

Definition at line 31 of file IPAddress.hpp.

Constructor & Destructor Documentation

◆ IPAddress() [1/5]

IPAddress::IPAddress ( const IPAddress other)
default

Copy constructor.

Parameters
otherIP address to copy from.

◆ IPAddress() [2/5]

IPAddress::IPAddress ( IPAddress &&  other)
default

Move constructor.

Parameters
otherIP address to move from.

◆ IPAddress() [3/5]

IPAddress::IPAddress ( const IPAddress other,
unsigned int  port 
)

Construct IP address from another IP address, changing the port number.

Copy constructor that also changes the port.

Parameters
otherIP address to copy from.
portPort number (0 - 65535). A port number of 0 has the special meaning of no specific port.
Exceptions
std::out_of_rangeif the port number is outside of the allowed 16 bit range.

Definition at line 88 of file IPAddress.cpp.

References port().

Here is the call graph for this function:

◆ IPAddress() [4/5]

IPAddress::IPAddress ( unsigned long  address,
unsigned int  port = 0 
)

Construct IP address from address and port number.

Parameters
address32-bit IP address in system byte order (0x00000000 - 0xFFFFFFFF).
portPort number (0 - 65535). A port number of 0 has the special meaning of no specific port.
Exceptions
std::out_of_rangeif either the IP address or the port number is outside of the respectively allowed 32 or 16 bit ranges.

Definition at line 103 of file IPAddress.cpp.

References address(), and port().

Here is the call graph for this function:

◆ IPAddress() [5/5]

IPAddress::IPAddress ( std::string  address)

Construct IP address from a string.

Parse a string of the form "<IP Address>" or "<IP Address>:<Port Number>".

Some examples are:

  • "127.0.0.1"
  • "127.0.0.1:8888"
  • "183.125.120.42:443"

If no port is given the 0 port is used which represents no specific port.

Parameters
addressString representing the IP address and optionally the port number.
Exceptions
std::invalid_argumentif the string does not represent a valid IP address.
std::out_of_rangeif an address octet or the port number is out of range.

Definition at line 127 of file IPAddress.cpp.

References address(), and port().

Here is the call graph for this function:

Member Function Documentation

◆ address()

unsigned long IPAddress::address ( ) const

Return the IP address.

Returns
The 32-bit IP address (in system byte order) as an integer (0x00000000 - 0xFFFFFFFF).

Definition at line 205 of file IPAddress.cpp.

Here is the caller graph for this function:

◆ operator=() [1/2]

IPAddress& IPAddress::operator= ( const IPAddress other)
default

Assignment operator.

Parameters
otherIP address to copy from.

◆ operator=() [2/2]

IPAddress& IPAddress::operator= ( IPAddress &&  other)
default

Assignment operator (by move semantics).

Parameters
otherIP address to move from.

◆ port()

unsigned int IPAddress::port ( ) const

Return the port.

Returns
The port number (0 - 65535).

Definition at line 215 of file IPAddress.cpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ dnslookup()

IPAddress dnslookup ( const std::string &  url)
related

Lookup an IP address based on a hostname.

Warning
Currently only supports IPv4.
Note
Currently only UNIX based operating system are supported.
Parameters
urlThe URL to get an IP address for.
Returns
IP addresses corresponding to the given URL.
Exceptions
DNSLookupErrorif the address cannot be found.

Definition at line 371 of file IPAddress.cpp.

◆ operator!=()

bool operator!= ( const IPAddress lhs,
const IPAddress rhs 
)
related

Inequality comparison.

Note
Compares address and port number.
Parameters
lhsThe left hand side IP address.
rhsThe right hand side IP address.
Return values
trueif lhs and rhs do not have the same address and port.
falseif lhs and rhs have the same address and port.

Definition at line 247 of file IPAddress.cpp.

References address(), and port().

Here is the call graph for this function:

◆ operator<()

bool operator< ( const IPAddress lhs,
const IPAddress rhs 
)
related

Less than comparison.

Note
The address is considered first followed by the port.
Parameters
lhsThe left hand side IP address.
rhsThe right hand side IP address.
Return values
trueif lhs is less than rhs.
falseif lhs is not less than rhs.

Definition at line 263 of file IPAddress.cpp.

References address(), and port().

Here is the call graph for this function:

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const IPAddress ipaddress 
)
friend

Print the IP address to the given output stream.

The format is "<IP Address>" or "<IP Address>:<Port Number>" if the port number is nonzero an "<IP Address>" if the port is 0.

Some examples are:

  • 127.0.0.1
  • 127.0.0.1:14555
  • 183.125.120.42:443
Note
The string constructor IPAddress(std::string) and the output stream operator are inverses and thus:
std::string addr = "127.0.0.1:14555"
str(IPAddress(addr)) == addr
Parameters
osThe output stream to print to.
ipaddressThe IP address to print.
Returns
The output stream.

Definition at line 340 of file IPAddress.cpp.

◆ operator<=()

bool operator<= ( const IPAddress lhs,
const IPAddress rhs 
)
related

Less than or equal comparison.

Note
The address is considered first followed by the port.
Parameters
lhsThe left hand side IP address.
rhsThe right hand side IP address.
Return values
trueif lhs is less than or eqaul to rhs.
falseif lhs is greater than rhs.

Definition at line 297 of file IPAddress.cpp.

◆ operator==()

bool operator== ( const IPAddress lhs,
const IPAddress rhs 
)
related

Equality comparison.

Note
Compares address and port number.
Parameters
lhsThe left hand side IP address.
rhsThe right hand side IP address.
Return values
trueif lhs and rhs have the same address and port.
falseif lhs and rhs do not have the same address and port.

Definition at line 231 of file IPAddress.cpp.

References address(), and port().

Here is the call graph for this function:

◆ operator>()

bool operator> ( const IPAddress lhs,
const IPAddress rhs 
)
related

Greater than comparison.

Note
The address is considered first followed by the port.
Parameters
lhsThe left hand side IP address.
rhsThe right hand side IP address.
Return values
trueif lhs is greater than rhs.
falseif lhs is not greater than rhs.

Definition at line 280 of file IPAddress.cpp.

References address(), and port().

Here is the call graph for this function:

◆ operator>=()

bool operator>= ( const IPAddress lhs,
const IPAddress rhs 
)
related

Greater than comparison.

Note
The address is considered first followed by the port.
Parameters
lhsThe left hand side IP address.
rhsThe right hand side IP address.
Return values
trueif lhs is greater than or equal to rhs.
falseif lhs is less than rhs.

Definition at line 313 of file IPAddress.cpp.


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