sptk2 logo
SPTK Home Page
Public Member Functions | List of all members
sptk::Host Class Reference

#include <Host.h>

Public Member Functions

 Host () noexcept
 
 Host (const String &hostname, uint16_t port)
 
 Host (const String &hostAndPort)
 
 Host (const sockaddr_in *addressAndPort)
 
 Host (const sockaddr_in6 *addressAndPort)
 
 Host (const Host &other)
 
 Host (Host &&other) noexcept
 
virtual ~Host ()=default
 
Hostoperator= (const Host &other)
 
Hostoperator= (Host &&other) noexcept
 
bool operator== (const Host &other) const
 
bool operator!= (const Host &other) const
 
const Stringhostname () const
 
void port (uint16_t p)
 
uint16_t port () const
 
String toString (bool forceAddress=false) const
 
void getAddress (sockaddr_in &address) const
 
void getAddress (sockaddr_in6 &address) const
 
void setHostNameFromAddress (socklen_t addressLen)
 

Detailed Description

Network host information

Constructor & Destructor Documentation

◆ Host() [1/7]

sptk::Host::Host ( )
noexcept

Default constructor

◆ Host() [2/7]

sptk::Host::Host ( const String hostname,
uint16_t  port 
)

Constructor

Parameters
hostnameHost name or IP address
portPort number

◆ Host() [3/7]

sptk::Host::Host ( const String hostAndPort)
explicit

Constructor In order to work with IPv6 address, enclose address part in square brackets.

Parameters
hostAndPortThe host and port definition, in the format ipv4addr:port.

◆ Host() [4/7]

sptk::Host::Host ( const sockaddr_in *  addressAndPort)
explicit

Constructor

Parameters
addressAndPortThe host and port, IPv4

◆ Host() [5/7]

sptk::Host::Host ( const sockaddr_in6 *  addressAndPort)
explicit

Constructor

Parameters
addressAndPortThe host and port, IPv6

◆ Host() [6/7]

sptk::Host::Host ( const Host other)

Copy constructor

Parameters
otherThe other object

◆ Host() [7/7]

sptk::Host::Host ( Host &&  other)
noexcept

Move constructor

Parameters
otherThe other object

◆ ~Host()

virtual sptk::Host::~Host ( )
virtualdefault

Destructor

Member Function Documentation

◆ getAddress() [1/2]

void sptk::Host::getAddress ( sockaddr_in &  address) const
inline

Get host address

◆ getAddress() [2/2]

void sptk::Host::getAddress ( sockaddr_in6 &  address) const
inline

Get host address

◆ hostname()

const String & sptk::Host::hostname ( ) const
inline

Get host name

Returns
host name

◆ operator!=()

bool sptk::Host::operator!= ( const Host other) const

Compare to another host

Parameters
otherThe other object
Returns
true if objects have not equal data

◆ operator=() [1/2]

Host & sptk::Host::operator= ( const Host other)

Assign from another host

Parameters
otherThe other object

◆ operator=() [2/2]

Host & sptk::Host::operator= ( Host &&  other)
noexcept

Move assignment from another host

Parameters
otherThe other object

◆ operator==()

bool sptk::Host::operator== ( const Host other) const

Compare to another host

Parameters
otherThe other object
Returns
true if objects have equal data

◆ port() [1/2]

uint16_t sptk::Host::port ( ) const
inline

Get port number

Returns
port number

◆ port() [2/2]

void sptk::Host::port ( uint16_t  p)
inline

Set port number

Parameters
pPort number

◆ toString()

String sptk::Host::toString ( bool  forceAddress = false) const

Get host name and port as a string. IPv6 addresses are enclosed in square brackets.

Parameters
forceAddressIf true then use IP address instead of hostname
Returns
host name and port string

Referenced by sptk::HostCompare::operator()().


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

Fri Oct 14 2022 09:58:42: SPTK 5.4.1