Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions | Friends
SocketAddress Class Reference

SocketAddress class. More...

#include <SocketAddress.h>

Public Member Functions

constexpr SocketAddress ()=default
 Create an unspecified SocketAddress. More...
 
 SocketAddress (const nsapi_addr_t &addr, uint16_t port=0)
 Create a SocketAddress from a raw IP address and port. More...
 
 SocketAddress (const char *addr, uint16_t port=0)
 Create a SocketAddress from an IP address and port. More...
 
 SocketAddress (const void *bytes, nsapi_version_t version, uint16_t port=0)
 Create a SocketAddress from raw IP bytes, IP version, and port. More...
 
 SocketAddress (const SocketAddress &addr)
 Create a SocketAddress from another SocketAddress. More...
 
 ~SocketAddress ()=default
 Destructor. More...
 
bool set_ip_address (const char *addr)
 Set the IP address. More...
 
void set_ip_bytes (const void *bytes, nsapi_version_t version)
 Set the raw IP bytes and IP version. More...
 
void set_addr (const nsapi_addr_t &addr)
 Set the raw IP address. More...
 
void set_port (uint16_t port)
 Set the port. More...
 
const char * get_ip_address () const
 Get the human-readable IP address. More...
 
const void * get_ip_bytes () const
 Get the raw IP bytes. More...
 
nsapi_version_t get_ip_version () const
 Get the IP address version. More...
 
nsapi_addr_t get_addr () const
 Get the raw IP address. More...
 
uint16_t get_port () const
 Get the port. More...
 
 operator bool () const
 Test if address is zero. More...
 
SocketAddressoperator= (const SocketAddress &addr)
 Copy address from another SocketAddress. More...
 

Friends

bool operator== (const SocketAddress &a, const SocketAddress &b)
 Compare two addresses for equality. More...
 
bool operator!= (const SocketAddress &a, const SocketAddress &b)
 Compare two addresses for equality. More...
 

Detailed Description

SocketAddress class.

Representation of an IP address and port pair.

Definition at line 37 of file SocketAddress.h.

Constructor & Destructor Documentation

constexpr SocketAddress ( )
default

Create an unspecified SocketAddress.

SocketAddress ( const nsapi_addr_t addr,
uint16_t  port = 0 
)

Create a SocketAddress from a raw IP address and port.

Note
To construct from a host name, use NetworkInterface::gethostbyname
Parameters
addrRaw IP address
portOptional 16-bit port, defaults to 0
SocketAddress ( const char *  addr,
uint16_t  port = 0 
)

Create a SocketAddress from an IP address and port.

Parameters
addrNull-terminated representation of the IP address
portOptional 16-bit port, defaults to 0
SocketAddress ( const void *  bytes,
nsapi_version_t  version,
uint16_t  port = 0 
)

Create a SocketAddress from raw IP bytes, IP version, and port.

Parameters
bytesRaw IP address in big-endian order
versionIP address version, NSAPI_IPv4 or NSAPI_IPv6
portOptional 16-bit port, defaults to 0
SocketAddress ( const SocketAddress addr)

Create a SocketAddress from another SocketAddress.

Parameters
addrSocketAddress to copy
~SocketAddress ( )
default

Destructor.

Member Function Documentation

nsapi_addr_t get_addr ( ) const

Get the raw IP address.

Returns
Raw IP address

Definition at line 137 of file SocketAddress.h.

const char* get_ip_address ( ) const

Get the human-readable IP address.

Allocates memory for a string and converts binary address to human-readable format. String is freed in the destructor.

Returns
Null-terminated representation of the IP Address
const void* get_ip_bytes ( ) const

Get the raw IP bytes.

Returns
Raw IP address in big-endian order

Definition at line 119 of file SocketAddress.h.

nsapi_version_t get_ip_version ( ) const

Get the IP address version.

Returns
IP address version, NSAPI_IPv4 or NSAPI_IPv6

Definition at line 128 of file SocketAddress.h.

uint16_t get_port ( ) const

Get the port.

Returns
The 16-bit port

Definition at line 146 of file SocketAddress.h.

operator bool ( ) const
explicit

Test if address is zero.

Returns
True if address is not zero
SocketAddress& operator= ( const SocketAddress addr)

Copy address from another SocketAddress.

Parameters
addrSocketAddress to copy
Return values
SocketAddressreference to this address
void set_addr ( const nsapi_addr_t addr)

Set the raw IP address.

Parameters
addrRaw IP address
bool set_ip_address ( const char *  addr)

Set the IP address.

Parameters
addrNull-terminated represention of the IP address
Returns
True if address is a valid representation of an IP address, otherwise False and SocketAddress is set to null
void set_ip_bytes ( const void *  bytes,
nsapi_version_t  version 
)

Set the raw IP bytes and IP version.

Parameters
bytesRaw IP address in big-endian order
versionIP address version, NSAPI_IPv4 or NSAPI_IPv6
void set_port ( uint16_t  port)

Set the port.

Parameters
port16-bit port

Definition at line 101 of file SocketAddress.h.

Friends And Related Function Documentation

bool operator!= ( const SocketAddress a,
const SocketAddress b 
)
friend

Compare two addresses for equality.

Returns
True if both addresses are not equal
bool operator== ( const SocketAddress a,
const SocketAddress b 
)
friend

Compare two addresses for equality.

Returns
True if both addresses are equal
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.