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. More... | |
SocketAddress (nsapi_addr_t addr=nsapi_addr_t(), 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 () | |
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 (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... | |
SocketAddress & | operator= (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... | |
SocketAddress class.
Representation of an IP address and port pair.
Definition at line 35 of file SocketAddress.h.
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
S | Type of the Network stack |
stack | Network stack to use for DNS resolution |
host | Hostname to resolve |
port | Optional 16-bit port, defaults to 0 |
Definition at line 56 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.
addr | Raw IP address |
port | Optional 16-bit port, defaults to 0 |
SocketAddress | ( | const char * | addr, |
uint16_t | port = 0 |
||
) |
Create a SocketAddress from an IP address and port.
addr | Null-terminated representation of the IP address |
port | Optional 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.
bytes | Raw IP address in big-endian order |
version | IP address version, NSAPI_IPv4 or NSAPI_IPv6 |
port | Optional 16-bit port, defaults to 0 |
SocketAddress | ( | const SocketAddress & | addr | ) |
Create a SocketAddress from another SocketAddress.
addr | SocketAddress to copy |
~SocketAddress | ( | ) |
Destructor.
nsapi_addr_t get_addr | ( | ) | const |
Get the raw IP address.
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.
const void* get_ip_bytes | ( | ) | const |
Get the raw IP bytes.
nsapi_version_t get_ip_version | ( | ) | const |
Get the IP address version.
uint16_t get_port | ( | ) | const |
Get the port.
operator bool | ( | ) | const |
Test if address is zero.
SocketAddress& operator= | ( | const SocketAddress & | addr | ) |
Copy address from another SocketAddress.
addr | SocketAddress to copy |
void set_addr | ( | nsapi_addr_t | addr | ) |
Set the raw IP address.
addr | Raw IP address |
bool set_ip_address | ( | const char * | addr | ) |
Set the IP address.
addr | Null-terminated represention of the IP address |
void set_ip_bytes | ( | const void * | bytes, |
nsapi_version_t | version | ||
) |
Set the raw IP bytes and IP version.
bytes | Raw IP address in big-endian order |
version | IP address version, NSAPI_IPv4 or NSAPI_IPv6 |
void set_port | ( | uint16_t | port | ) |
Set the port.
port | 16-bit port |
|
friend |
Compare two addresses for equality.
|
friend |
Compare two addresses for equality.