Nets v3.0.0
SocketAddress Struct Referencefinal

Socket IP address instance handle. More...

#include <socket.hpp>

Public Member Functions

 SocketAddress (const SocketAddress &)=delete
 SocketAddress (SocketAddress &&r) noexcept
SocketAddress & operator= (SocketAddress &)=delete
SocketAddress & operator= (SocketAddress &&r) noexcept
 SocketAddress (SocketFamily family=IP_V6_SOCKET_FAMILY)
 Creates a new any socket IP address instance.
 SocketAddress (const char *host, const char *service)
 Creates a new socket IP address instance.
 ~SocketAddress ()
 Destroys socket IP address instance.
SocketAddress createCopy () const noexcept
 Creates a new socket IP address copy instance.
void destroy () noexcept
 Destroys socket IP address instance.
SocketAddress_TgetInstance () const noexcept
 Returns socket IP address view instance.
SocketFamily getFamily () const noexcept
 Returns socket IP address family type.
size_t getIpSize () const noexcept
 Returns socket IP address byte array size.
bool isAny () const noexcept
 Returns true if socket IP address is any address.
bool isLoopback () const noexcept
 Returns true if socket IP address is loopback address.
bool isMappedV4 () const noexcept
 Returns true if socket IP address is IPv4 mapped IPv6.
const uint8_tgetIP () const noexcept
 Returns socket IP address byte array.
void setIP (const uint8_t *ip) noexcept
 Sets socket IP address byte array.
uint16_t getPort () const noexcept
 Returns socket IP address port number.
void setPort (uint16_t port) noexcept
 Sets socket IP address port number.
void getHost (char *host, size_t length) const noexcept
 Returns socket IP address numeric host name.
void getHost (std::string &host) const
 Returns socket IP address numeric host name.
void getService (char *service, size_t length) const noexcept
 Returns socket IP address numeric service name.
void getService (std::string &service) const
 Returns socket IP address numeric service name.
void getHostService (char *host, size_t hostLength, char *service, size_t serviceLength) const noexcept
 Returns socket IP address numeric host and service name.
void getHostService (std::string &host, std::string &service) const
 Returns socket IP address numeric host and service name.
 operator bool () const noexcept
 Returns true if socket IP address view is not null.

Static Public Member Functions

static void destroy (SocketAddressView *socketAddresses, size_t addressCount) noexcept
 Destroys resolved socket IP address array.
static NetsResult resolve (const char *host, const char *service, SocketFamily family, SocketType type, SocketAddressView *&socketAddresses, size_t &addressCount) noexcept
 Resolves a new socket IP address array. (Blocking call).
static void copy (SocketAddressView sourceAddress, SocketAddressView destinationAddress) noexcept
 Copies source socket IP address to the destination.
static int compare (SocketAddressView a, SocketAddressView b) noexcept
 Compares two socket IP addresses.

Protected Attributes

SocketAddress_Tinstance = nullptr

Detailed Description

Socket IP address instance handle.

See the socket.h

Constructor & Destructor Documentation

◆ SocketAddress() [1/2]

SocketAddress ( SocketFamily family = IP_V6_SOCKET_FAMILY)
inline

Creates a new any socket IP address instance.

See the createAnySocketAddress().

Parameters
familysocket IP address family type
Exceptions
Errorwith a NetsResult string on failure.

◆ SocketAddress() [2/2]

SocketAddress ( const char * host,
const char * service )
inline

Creates a new socket IP address instance.

See the createSocketAddress().

Parameters
[in]hostsocket IP address host name string
[in]servicesocket IP address service name string (port)
Exceptions
Errorwith a NetsResult string on failure.

◆ ~SocketAddress()

~SocketAddress ( )
inline

Destroys socket IP address instance.

See the destroySocketAddress().

Member Function Documentation

◆ createCopy()

SocketAddress createCopy ( ) const
inlinenoexcept

Creates a new socket IP address copy instance.

See the createSocketAddressCopy().

◆ destroy() [1/2]

void destroy ( )
inlinenoexceptinherited

Destroys socket IP address instance.

See the destroySocketAddress().

◆ destroy() [2/2]

void destroy ( SocketAddressView * socketAddresses,
size_t addressCount )
inlinestaticnoexceptinherited

Destroys resolved socket IP address array.

See the destroySocketAddresses().

Parameters
[in]socketAddressessocket IP address array
addressCountsocket address count

◆ getFamily()

SocketFamily getFamily ( ) const
inlinenoexceptinherited

Returns socket IP address family type.

See the getSocketAddressFamily().

◆ getIpSize()

size_t getIpSize ( ) const
inlinenoexceptinherited

Returns socket IP address byte array size.

See the getSocketAddressIpSize().

◆ isAny()

bool isAny ( ) const
inlinenoexceptinherited

Returns true if socket IP address is any address.

See the isSocketAddressAny().

◆ isLoopback()

bool isLoopback ( ) const
inlinenoexceptinherited

Returns true if socket IP address is loopback address.

See the isSocketAddressLoopback().

◆ isMappedV4()

bool isMappedV4 ( ) const
inlinenoexceptinherited

Returns true if socket IP address is IPv4 mapped IPv6.

See the isSocketAddressMappedV4().

◆ getIP()

const uint8_t * getIP ( ) const
inlinenoexceptinherited

Returns socket IP address byte array.

See the getSocketAddressIP().

◆ setIP()

void setIP ( const uint8_t * ip)
inlinenoexceptinherited

Sets socket IP address byte array.

See the setSocketAddressIP().

Parameters
[in]iptarget IP address byte array

◆ getPort()

uint16_t getPort ( ) const
inlinenoexceptinherited

Returns socket IP address port number.

See the getSocketAddressPort().

◆ setPort()

void setPort ( uint16_t port)
inlinenoexceptinherited

Sets socket IP address port number.

See the setSocketAddressPort().

Parameters
porttarget IP address port number

◆ getHost() [1/2]

void getHost ( char * host,
size_t length ) const
inlinenoexceptinherited

Returns socket IP address numeric host name.

See the getSocketAddressHost().

Parameters
[out]hostpointer to the host name string
lengthhost name string length (including null terminator)

◆ getHost() [2/2]

void getHost ( std::string & host) const
inlineinherited

Returns socket IP address numeric host name.

See the getSocketAddressHost().

Parameters
[out]hosttarget host name string

◆ getService() [1/2]

void getService ( char * service,
size_t length ) const
inlinenoexceptinherited

Returns socket IP address numeric service name.

See the getSocketAddressService().

Parameters
[out]servicepointer to the service name string
lengthservice name string length (including null terminator)

◆ getService() [2/2]

void getService ( std::string & service) const
inlineinherited

Returns socket IP address numeric service name.

See the getSocketAddressService().

Parameters
[out]servicetarget service name string

◆ getHostService() [1/2]

void getHostService ( char * host,
size_t hostLength,
char * service,
size_t serviceLength ) const
inlinenoexceptinherited

Returns socket IP address numeric host and service name.

See the getSocketAddressHostService().

Parameters
[out]hostpointer to the host name string
hostLengthhost name string length (including null terminator)
[out]servicepointer to the service name string
serviceLengthservice name string length (including null terminator)

◆ getHostService() [2/2]

void getHostService ( std::string & host,
std::string & service ) const
inlineinherited

Returns socket IP address numeric host and service name.

See the getSocketAddressHostService().

Parameters
[out]hosttarget host name string
[out]servicetarget service name string

◆ resolve()

NetsResult resolve ( const char * host,
const char * service,
SocketFamily family,
SocketType type,
SocketAddressView *& socketAddresses,
size_t & addressCount )
inlinestaticnoexceptinherited

Resolves a new socket IP address array. (Blocking call).

See the resolveSocketAddresses().

Warning
This may be a slow running operation!
Returns
The operation NetsResult code.
Parameters
[in]hostsocket IP address host name string
[in]servicesocket IP address service name string (port)
familysocket IP address family type
typesocket communication protocol type
[out]socketAddressesreference to the socket address array
[out]addressCountreference to the socket address count

◆ copy()

void copy ( SocketAddressView sourceAddress,
SocketAddressView destinationAddress )
inlinestaticnoexceptinherited

Copies source socket IP address to the destination.

See the copySocketAddress().

Parameters
sourceAddresssource socket address instance
destinationAddressdestination socket address instance

◆ compare()

int compare ( SocketAddressView a,
SocketAddressView b )
inlinestaticnoexceptinherited

Compares two socket IP addresses.

See the compareSocketAddress().

Parameters
[in]afirst socket address instance
[in]bsecond socket address instance