![]() |
Mbed OS Reference
|
Representation of an IP (v4 or v6) address and port pair. More...
#include <SocketAddress.h>
Public Member Functions | |
| constexpr | SocketAddress ()=default |
| Create an empty SocketAddress. | |
| SocketAddress (const nsapi_addr_t &addr, 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. | |
| SocketAddress (SocketAddress &&addr)=default | |
| Create a SocketAddress by moving another SocketAddress. | |
| ~SocketAddress ()=default | |
| 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 (const 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 or empty. | |
| bool | is_empty () const |
| SocketAddress & | operator= (const SocketAddress &addr) |
| Copy address from another SocketAddress. | |
Representation of an IP (v4 or v6) address and port pair.
Each SocketAddress contains the IP address bytes and the port number. Also, when the IP address is first used as a string (e.g. for get_ip_address() ), a character string is allocated on the heap via a unique_ptr inside the SocketAddress. This character string as long as the SocketAddress does, but not longer.
Definition at line 40 of file SocketAddress.h.
|
constexprdefault |
Create an empty SocketAddress.
| SocketAddress | ( | const nsapi_addr_t & | addr, |
| 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.
If the string is not a parseable IP address, an empty SocketAddress is returned (see is_empty() below).
| addr | Null-terminated string 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 |
|
default |
Create a SocketAddress by moving another SocketAddress.
This transfers ownership of the string data, if allocated.
| addr | SocketAddress to move from |
|
default |
Destructor.
| 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_addr | ( | const nsapi_addr_t & | addr | ) |
Set the raw IP address.
| addr | Raw IP address |
| void set_port | ( | uint16_t | port | ) |
| 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.
Definition at line 137 of file SocketAddress.h.
| nsapi_version_t get_ip_version | ( | ) | const |
Get the IP address version.
Definition at line 146 of file SocketAddress.h.
| nsapi_addr_t get_addr | ( | ) | const |
| uint16_t get_port | ( | ) | const |
|
explicit |
Test if address is zero or empty.
| bool is_empty | ( | ) | const |
Definition at line 179 of file SocketAddress.h.
| SocketAddress & operator= | ( | const SocketAddress & | addr | ) |
Copy address from another SocketAddress.
| addr | SocketAddress to copy |
| SocketAddress | reference to this address |