blocxx
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
BLOCXX_NAMESPACE::SocketAddress Class Reference

#include <SocketAddress.hpp>

Public Types

enum  AddressType { UNSET, INET, UDS }
 

Public Member Functions

AddressType getType () const
 
UInt16 getPort () const
 Get the port associated with the address. More...
 
 ~SocketAddress ()
 
const String getName () const
 Returns the hostname (FQDN) of the address. More...
 
const String getAddress () const
 Returns the IP address of the host. More...
 
const SocketAddress_tgetNativeForm () const
 
size_t getNativeFormSize () const
 
const InetSocketAddress_tgetInetAddress () const
 Get a pointer to the InetSocketAddress_t precondition: getType() == INET. More...
 
const UnixSocketAddress_tgetUnixAddress () const
 Get a pointer to the UnixSocketAddress_t precondition: getType() == UDS. More...
 
void assignFromNativeForm (const UnixSocketAddress_t *address, size_t len)
 
const String toString () const
 Returns the IP address and the port with a colon in between. More...
 
void assignFromNativeForm (const InetSocketAddress_t *address, size_t len)
 
 SocketAddress ()
 

Static Public Member Functions

static SocketAddress getByName (const String &host, unsigned short port=0)
 Do a DNS lookup on a hostname and return an SocketAddress for that host. More...
 
static SocketAddress getAnyLocalHost (UInt16 port=0)
 Do a DNS lookup on a hostname and return a list of all addresses that map to that hostname. More...
 
static SocketAddress allocEmptyAddress (AddressType type)
 Allocate an empty SocketAddress. More...
 
static SocketAddress getUDS (const String &filename)
 

Static Public Attributes

static const char *const ALL_LOCAL_ADDRESSES = "0.0.0.0"
 

Private Member Functions

 SocketAddress (const InetSocketAddress_t &nativeForm)
 
 SocketAddress (const UnixSocketAddress_t &nativeForm)
 

Static Private Member Functions

static SocketAddress getFromNativeForm (const InetAddress_t &nativeForm, UInt16 nativePort, const String &hostname)
 
static SocketAddress getFromNativeForm (const InetSocketAddress_t &nativeForm)
 
static SocketAddress getFromNativeForm (const UnixSocketAddress_t &nativeForm)
 

Private Attributes

String m_name
 
String m_address
 
size_t m_nativeSize
 
InetSocketAddress_t m_inetNativeAddress
 
UnixSocketAddress_t m_UDSNativeAddress
 
AddressType m_type
 

Detailed Description

Definition at line 85 of file SocketAddress.hpp.

Member Enumeration Documentation

◆ AddressType

Enumerator
UNSET 
INET 
UDS 

Definition at line 90 of file SocketAddress.hpp.

Constructor & Destructor Documentation

◆ ~SocketAddress()

BLOCXX_NAMESPACE::SocketAddress::~SocketAddress ( )
inline

Definition at line 133 of file SocketAddress.hpp.

◆ SocketAddress() [1/3]

BLOCXX_NAMESPACE::SocketAddress::SocketAddress ( )

Definition at line 172 of file SocketAddress.cpp.

Referenced by SocketAddress().

◆ SocketAddress() [2/3]

BLOCXX_NAMESPACE::SocketAddress::SocketAddress ( const InetSocketAddress_t nativeForm)
private

Definition at line 431 of file SocketAddress.cpp.

◆ SocketAddress() [3/3]

BLOCXX_NAMESPACE::SocketAddress::SocketAddress ( const UnixSocketAddress_t nativeForm)
private

Definition at line 423 of file SocketAddress.cpp.

References getFromNativeForm(), INET, and SocketAddress().

Member Function Documentation

◆ allocEmptyAddress()

SocketAddress BLOCXX_NAMESPACE::SocketAddress::allocEmptyAddress ( AddressType  type)
static

Allocate an empty SocketAddress.

Returns
an empty address

Definition at line 453 of file SocketAddress.cpp.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::doListen().

◆ assignFromNativeForm() [1/2]

void BLOCXX_NAMESPACE::SocketAddress::assignFromNativeForm ( const InetSocketAddress_t address,
size_t  len 
)

Definition at line 368 of file SocketAddress.cpp.

◆ assignFromNativeForm() [2/2]

void BLOCXX_NAMESPACE::SocketAddress::assignFromNativeForm ( const UnixSocketAddress_t address,
size_t  len 
)

◆ getAddress()

const String BLOCXX_NAMESPACE::SocketAddress::getAddress ( ) const

Returns the IP address of the host.

Returns
The IP address of the host

Definition at line 443 of file SocketAddress.cpp.

◆ getAnyLocalHost()

SocketAddress BLOCXX_NAMESPACE::SocketAddress::getAnyLocalHost ( UInt16  port = 0)
static

Do a DNS lookup on a hostname and return a list of all addresses that map to that hostname.

Parameters
hostThe hostname
portThe port
Returns
An Array of SocketAddresses for the host and port Get an SocketAddress appropriate for referring to the local host
Parameters
portThe port
Returns
An SocketAddress representing the local machine

Definition at line 316 of file SocketAddress.cpp.

◆ getByName()

SocketAddress BLOCXX_NAMESPACE::SocketAddress::getByName ( const String host,
unsigned short  port = 0 
)
static

Do a DNS lookup on a hostname and return an SocketAddress for that host.

Parameters
hostThe hostname
portThe port
Returns
An SocketAddress for the host and port
Exceptions
UnknownHostException

Definition at line 184 of file SocketAddress.cpp.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::doListenIPv4().

◆ getFromNativeForm() [1/3]

SocketAddress BLOCXX_NAMESPACE::SocketAddress::getFromNativeForm ( const InetAddress_t nativeForm,
UInt16  nativePort,
const String hostname 
)
staticprivate

Definition at line 267 of file SocketAddress.cpp.

References m_inetNativeAddress.

Referenced by SocketAddress().

◆ getFromNativeForm() [2/3]

SocketAddress BLOCXX_NAMESPACE::SocketAddress::getFromNativeForm ( const InetSocketAddress_t nativeForm)
staticprivate

Definition at line 249 of file SocketAddress.cpp.

◆ getFromNativeForm() [3/3]

SocketAddress BLOCXX_NAMESPACE::SocketAddress::getFromNativeForm ( const UnixSocketAddress_t nativeForm)
staticprivate

Definition at line 258 of file SocketAddress.cpp.

References m_UDSNativeAddress.

◆ getInetAddress()

const InetSocketAddress_t * BLOCXX_NAMESPACE::SocketAddress::getInetAddress ( ) const

Get a pointer to the InetSocketAddress_t precondition: getType() == INET.

Definition at line 299 of file SocketAddress.cpp.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::doListenIPv4().

◆ getName()

const String BLOCXX_NAMESPACE::SocketAddress::getName ( ) const

Returns the hostname (FQDN) of the address.

Returns
The hostname of the address.

Definition at line 438 of file SocketAddress.cpp.

◆ getNativeForm()

const SocketAddress_t * BLOCXX_NAMESPACE::SocketAddress::getNativeForm ( ) const

Definition at line 281 of file SocketAddress.cpp.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::doListenUDS().

◆ getNativeFormSize()

size_t BLOCXX_NAMESPACE::SocketAddress::getNativeFormSize ( ) const

Definition at line 448 of file SocketAddress.cpp.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::doListenUDS().

◆ getPort()

UInt16 BLOCXX_NAMESPACE::SocketAddress::getPort ( ) const

Get the port associated with the address.

Returns
The port

Definition at line 403 of file SocketAddress.cpp.

◆ getType()

AddressType BLOCXX_NAMESPACE::SocketAddress::getType ( ) const
inline

◆ getUDS()

SocketAddress BLOCXX_NAMESPACE::SocketAddress::getUDS ( const String filename)
static

Definition at line 132 of file SocketAddress.cpp.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::doListenUDS().

◆ getUnixAddress()

const UnixSocketAddress_t * BLOCXX_NAMESPACE::SocketAddress::getUnixAddress ( ) const

Get a pointer to the UnixSocketAddress_t precondition: getType() == UDS.

Definition at line 308 of file SocketAddress.cpp.

◆ toString()

const String BLOCXX_NAMESPACE::SocketAddress::toString ( ) const

Returns the IP address and the port with a colon in between.

Returns
The IP and port seperated by a colon.

Definition at line 476 of file SocketAddress.cpp.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::close().

Member Data Documentation

◆ ALL_LOCAL_ADDRESSES

const char *const BLOCXX_NAMESPACE::SocketAddress::ALL_LOCAL_ADDRESSES = "0.0.0.0"
static

Definition at line 88 of file SocketAddress.hpp.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::doListenIPv4().

◆ m_address

String BLOCXX_NAMESPACE::SocketAddress::m_address
private

Definition at line 186 of file SocketAddress.hpp.

◆ m_inetNativeAddress

InetSocketAddress_t BLOCXX_NAMESPACE::SocketAddress::m_inetNativeAddress
private

Definition at line 189 of file SocketAddress.hpp.

Referenced by getFromNativeForm().

◆ m_name

String BLOCXX_NAMESPACE::SocketAddress::m_name
private

Definition at line 185 of file SocketAddress.hpp.

◆ m_nativeSize

size_t BLOCXX_NAMESPACE::SocketAddress::m_nativeSize
private

Definition at line 187 of file SocketAddress.hpp.

◆ m_type

AddressType BLOCXX_NAMESPACE::SocketAddress::m_type
private

Definition at line 195 of file SocketAddress.hpp.

◆ m_UDSNativeAddress

UnixSocketAddress_t BLOCXX_NAMESPACE::SocketAddress::m_UDSNativeAddress
private

Definition at line 192 of file SocketAddress.hpp.

Referenced by getFromNativeForm().


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