Fork for fixes

Embed: (wiki syntax)

« Back to documentation index

SocketAddress Class Reference

SocketAddress Class Reference
[Netsocket]

SocketAddress class. More...

#include <SocketAddress.h>

Public Member Functions

template<typename S >
 MBED_DEPRECATED_SINCE ("mbed-os-5.1.3","Constructors hide possible errors. Replaced by ""NetworkInterface::gethostbyname.") SocketAddress(S *stack
 Create a SocketAddress from a hostname and port.
 SocketAddress (const char *addr, uint16_t port=0)
 Create a SocketAddress from an IP address and port.
 SocketAddress (const void *bytes, nsapi_version_t version, uint16_t port=0)
 Create a SocketAddress from raw IP bytes, IP version, and port.
 SocketAddress (const SocketAddress &addr)
 Create a SocketAddress from another SocketAddress.
 ~SocketAddress ()
 Destructor.
bool set_ip_address (const char *addr)
 Set the IP address.
void set_ip_bytes (const void *bytes, nsapi_version_t version)
 Set the raw IP bytes and IP version.
void set_addr (nsapi_addr_t addr)
 Set the raw IP address.
void set_port (uint16_t port)
 Set the port.
const char * get_ip_address () const
 Get the human-readable IP address.
const void * get_ip_bytes () const
 Get the raw IP bytes.
nsapi_version_t get_ip_version () const
 Get the IP address version.
nsapi_addr_t get_addr () const
 Get the raw IP address.
uint16_t get_port () const
 Get the port.
 operator bool () const
 Test if address is zero.
SocketAddressoperator= (const SocketAddress &addr)
 Copy address from another SocketAddress.

Friends

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

Detailed Description

SocketAddress class.

Representation of an IP address and port pair.

Definition at line 35 of file SocketAddress.h.


Constructor & Destructor Documentation

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
Note:
Parameters:
@retval

Definition at line 49 of file SocketAddress.cpp.

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
Note:
Parameters:
@retval

Definition at line 63 of file SocketAddress.cpp.

SocketAddress ( const SocketAddress addr )

Create a SocketAddress from another SocketAddress.

Parameters:
addrSocketAddress to copy
Note:
Parameters:
@retval

Definition at line 77 of file SocketAddress.cpp.

~SocketAddress (  )

Destructor.

Note:
Parameters:
@retval

Definition at line 344 of file SocketAddress.cpp.


Member Function Documentation

nsapi_addr_t get_addr (  ) const

Get the raw IP address.

Returns:
Raw IP address
Note:
Parameters:
@retval

Definition at line 225 of file SocketAddress.cpp.

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
Note:
Parameters:
@retval

Definition at line 177 of file SocketAddress.cpp.

const void * get_ip_bytes (  ) const

Get the raw IP bytes.

Returns:
Raw IP address in big-endian order
Note:
Parameters:
@retval

Definition at line 203 of file SocketAddress.cpp.

nsapi_version_t get_ip_version (  ) const

Get the IP address version.

Returns:
IP address version, NSAPI_IPv4 or NSAPI_IPv6
Note:
Parameters:
@retval

Definition at line 214 of file SocketAddress.cpp.

uint16_t get_port (  ) const

Get the port.

Returns:
The 16-bit port
Note:
Parameters:
@retval

Definition at line 236 of file SocketAddress.cpp.

MBED_DEPRECATED_SINCE ( "mbed-os-5.1.3"  ,
"Constructors hide possible errors. Replaced by ""NetworkInterface::gethostbyname."   
)

Create a SocketAddress from a hostname and port.

The hostname may be either a domain name or an IP address. If the hostname is an IP address, no network transactions will be performed.

On failure, the IP address and port will be set to zero

Template Parameters:
SType of the Network stack
Parameters:
stackNetwork stack to use for DNS resolution
hostHostname to resolve
portOptional 16-bit port, defaults to 0
operator bool (  ) const

Test if address is zero.

Returns:
True if address is not zero
Note:
Parameters:
@retval

Definition at line 247 of file SocketAddress.cpp.

SocketAddress & operator= ( const SocketAddress addr )

Copy address from another SocketAddress.

Parameters:
addrSocketAddress to copy
Note:
Parameters:
@retval

Definition at line 279 of file SocketAddress.cpp.

void set_addr ( nsapi_addr_t  addr )

Set the raw IP address.

Parameters:
addrRaw IP address
Note:
Parameters:
@retval

Definition at line 153 of file SocketAddress.cpp.

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
Note:
Parameters:
@retval

Definition at line 104 of file SocketAddress.cpp.

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
Note:
Parameters:
@retval

Definition at line 130 of file SocketAddress.cpp.

void set_port ( uint16_t  port )

Set the port.

Parameters:
port16-bit port
Note:
Parameters:
@retval

Definition at line 166 of file SocketAddress.cpp.


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
Note:
Parameters:
@retval

Definition at line 321 of file SocketAddress.cpp.

bool operator== ( const SocketAddress a,
const SocketAddress b 
) [friend]

Compare two addresses for equality.

Returns:
True if both addresses are equal
Note:
Parameters:
@retval

Definition at line 294 of file SocketAddress.cpp.