SuperTuxKart
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
TransportAddress Class Reference

Describes a transport-layer address. For IP networks, a transport address is the couple ip:port. More...

#include <transport_address.hpp>

Public Member Functions

 TransportAddress (uint32_t ip=0, uint16_t port=0)
 Constructor. More...
 
 TransportAddress (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint16_t port=0)
 
 TransportAddress (const ENetAddress &a)
 Construct an transport address from an ENetAddress. More...
 
 TransportAddress (const std::string &str, uint16_t port_number)
 Construct an IO address from a string in the format x.x.x.x with a port number. More...
 
 TransportAddress (const std::string &str)
 Construct an IO address from a string in the format x.x.x.x:x. More...
 
bool isPublicAddressLocalhost () const
 Returns this IP address is localhost (127.0.0.1).
 
bool isLAN () const
 Returns if this IP address belongs to a LAN, i.e. More...
 
bool isUnset () const
 
void clear ()
 Resets ip and port to 0. More...
 
uint32_t getIP () const
 Returns the ip address. More...
 
uint16_t getPort () const
 Returns the port number. More...
 
void setIP (uint32_t ip)
 Sets the ip address. More...
 
void setPort (uint16_t port)
 Set the port. More...
 
ENetAddress toEnetAddress () const
 Converts the address to an enet address. More...
 
bool operator== (const TransportAddress &other) const
 Compares if ip address and port are identical. More...
 
bool operator== (const ENetAddress &other)
 
bool operator!= (const TransportAddress &other) const
 Compares if ip address or port are different. More...
 
std::string toString (bool show_port=true) const
 Returns a std::string representing the ip address and port in human readable format. More...
 

Static Public Member Functions

static void unitTesting ()
 Unit testing. More...
 
static TransportAddress fromDomain (const std::string &str)
 

Private Attributes

uint32_t m_ip
 The IPv4 address.
 
uint16_t m_port
 The port number.
 

Detailed Description

Describes a transport-layer address. For IP networks, a transport address is the couple ip:port.

Constructor & Destructor Documentation

◆ TransportAddress() [1/4]

TransportAddress::TransportAddress ( uint32_t  ip = 0,
uint16_t  port = 0 
)
inline

Constructor.

◆ TransportAddress() [2/4]

TransportAddress::TransportAddress ( const ENetAddress &  a)
inline

Construct an transport address from an ENetAddress.

◆ TransportAddress() [3/4]

TransportAddress::TransportAddress ( const std::string &  str,
uint16_t  port_number 
)

Construct an IO address from a string in the format x.x.x.x with a port number.

◆ TransportAddress() [4/4]

TransportAddress::TransportAddress ( const std::string &  str)

Construct an IO address from a string in the format x.x.x.x:x.

Member Function Documentation

◆ clear()

void TransportAddress::clear ( )
inline

Resets ip and port to 0.

◆ getIP()

uint32_t TransportAddress::getIP ( ) const
inline

Returns the ip address.

◆ getPort()

uint16_t TransportAddress::getPort ( ) const
inline

Returns the port number.

◆ isLAN()

bool TransportAddress::isLAN ( ) const

Returns if this IP address belongs to a LAN, i.e.

is in 192.168* or 10*, 172.16-31.*, or is on the same host, i.e. 127* or same public address.

◆ operator!=()

bool TransportAddress::operator!= ( const TransportAddress other) const
inline

Compares if ip address or port are different.

◆ operator==()

bool TransportAddress::operator== ( const TransportAddress other) const
inline

Compares if ip address and port are identical.

◆ setIP()

void TransportAddress::setIP ( uint32_t  ip)
inline

Sets the ip address.

◆ setPort()

void TransportAddress::setPort ( uint16_t  port)
inline

Set the port.

◆ toEnetAddress()

ENetAddress TransportAddress::toEnetAddress ( ) const
inline

Converts the address to an enet address.

◆ toString()

std::string TransportAddress::toString ( bool  show_port = true) const

Returns a std::string representing the ip address and port in human readable format.

Parameters
show_portTrue if the port should be shown as well, otherwise only the ip address will be returned.

◆ unitTesting()

void TransportAddress::unitTesting ( )
static

Unit testing.

Test various LAN patterns to verify that isLAN() works as expected.


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