Magnificent7 / Hackathon
Embed: (wiki syntax)

« Back to documentation index

SocketAddress Class Reference

SocketAddress Class Reference

SocketAddress class. More...

#include <SocketAddress.h>

Public Member Functions

template<typename S >
 SocketAddress (S *stack, const char *host, uint16_t port=0)
 Create a SocketAddress from a hostname and port.
 SocketAddress (nsapi_addr_t addr=nsapi_addr_t(), uint16_t port=0)
 Create a SocketAddress from a raw IP address 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.
void 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 IP address.
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.

Detailed Description

SocketAddress class.

Representation of an IP address and port pair.

Definition at line 32 of file SocketAddress.h.


Constructor & Destructor Documentation

SocketAddress ( S *  stack,
const char *  host,
uint16_t  port = 0 
)

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

Parameters:
stackNetwork stack to use for DNS resolution
hostHostname to resolve
portOptional 16-bit port

Definition at line 46 of file SocketAddress.h.

SocketAddress ( nsapi_addr_t  addr = nsapi_addr_t(),
uint16_t  port = 0 
)

Create a SocketAddress from a raw IP address and port.

Parameters:
addrRaw IP address
portOptional 16-bit port

Definition at line 146 of file SocketAddress.cpp.

SocketAddress ( const char *  addr,
uint16_t  port = 0 
)

Create a SocketAddress from an IP address and port.

Parameters:
hostNull-terminated representation of the IP address
portOptional 16-bit port

Definition at line 153 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

Definition at line 160 of file SocketAddress.cpp.

SocketAddress ( const SocketAddress addr )

Create a SocketAddress from another SocketAddress.

Parameters:
addressSocketAddress to copy

Definition at line 167 of file SocketAddress.cpp.


Member Function Documentation

nsapi_addr_t get_addr (  ) const

Get the raw IP address.

Returns:
Raw IP address

Definition at line 233 of file SocketAddress.cpp.

const char * get_ip_address (  ) const

Get the IP address.

Returns:
Null-terminated representation of the IP Address

Definition at line 208 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

Definition at line 228 of file SocketAddress.cpp.

uint16_t get_port (  ) const

Get the port.

Returns:
The 16-bit port

Definition at line 238 of file SocketAddress.cpp.

operator bool ( void   ) const

Test if address is zero.

Returns:
True if address is not zero

Definition at line 243 of file SocketAddress.cpp.

void set_addr ( nsapi_addr_t  addr )

Set the raw IP address.

Parameters:
addrRaw IP address

Definition at line 197 of file SocketAddress.cpp.

void set_ip_address ( const char *  addr )

Set the IP address.

Parameters:
addrNull-terminated represention of the IP address

Definition at line 174 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

Definition at line 189 of file SocketAddress.cpp.

void set_port ( uint16_t  port )

Set the port.

Parameters:
port16-bit port

Definition at line 203 of file SocketAddress.cpp.