Address
#include <icy/net/address.h>
class AddressDefined in src/net/include/icy/net/address.h:29
Friends
| Name | Description |
|---|---|
operator<< inline |
operator<<
inline
friend inline std::ostream & operator<<(std::ostream & stream, const Address & addr)Defined in src/net/include/icy/net/address.h:132
Public Methods
| Return | Name | Description |
|---|---|---|
Address | Creates a wildcard (all zero) IPv4 Address. | |
Address | Creates an Address from an IP address and a port number. | |
Address | Creates an Address by copying another one. | |
Address | Creates an Address from a native socket address. | |
Address | Creates an Address from an IP address and a service name or port number. | |
Address explicit | Creates an Address from an IP address or host name and a port number/service name. Host name/address and port number must be separated by a colon. In case of an IPv6 address, the address part must be enclosed in brackets. | |
~Address noexcept | Destroys the Address. | |
Address & | operator= | Assigns another Address. |
void | swap | Swaps the Address with another one. |
std::string | host const | Returns the host IP address. |
uint16_t | port const | Returns the port number. |
socklen_t | length const | Returns the length of the internal native socket address. |
const struct sockaddr * | addr const | Returns a pointer to the internal native socket address. |
int | af const | Returns the address family (AF_INET or AF_INET6) of the address. |
std::string | toString const | Returns a string representation of the address. |
Address::Family | family const | Returns the address family of the host's address. |
bool | valid const | Returns true when the port is set and the address is valid ie. not wildcard. |
bool | operator< const | Compares two addresses for ordering (by family then port). |
bool | operator== const | Returns true if the host and port of both addresses are equal. |
bool | operator!= const | Returns true if the host or port of the addresses differ. |
Address
Address()Defined in src/net/include/icy/net/address.h:40
Creates a wildcard (all zero) IPv4 Address.
Address
Address(const std::string & host, uint16_t port)Defined in src/net/include/icy/net/address.h:46
Creates an Address from an IP address and a port number.
The IP address must either be a domain name, or it must be in dotted decimal (IPv4) or hex string (IPv6) format.
Address
Address(const Address & addr)Defined in src/net/include/icy/net/address.h:49
Creates an Address by copying another one.
Address
Address(const struct sockaddr * addr, socklen_t length)Defined in src/net/include/icy/net/address.h:52
Creates an Address from a native socket address.
Address
Address(const std::string & host, const std::string & port)Defined in src/net/include/icy/net/address.h:62
Creates an Address from an IP address and a service name or port number.
The IP address must either be a domain name, or it must be in dotted decimal (IPv4) or hex string (IPv6) format.
The given port must either be a decimal port number, or a service name.
Address
explicit
explicit Address(const std::string & hostAndPort)Defined in src/net/include/icy/net/address.h:73
Creates an Address from an IP address or host name and a port number/service name. Host name/address and port number must be separated by a colon. In case of an IPv6 address, the address part must be enclosed in brackets.
Examples: 192.168.1.10:80
0state.com:8080
~Address
noexcept
~Address() noexceptDefined in src/net/include/icy/net/address.h:76
Destroys the Address.
operator=
Address & operator=(const Address & addr)Defined in src/net/include/icy/net/address.h:79
Assigns another Address.
swap
void swap(Address & addr)Defined in src/net/include/icy/net/address.h:82
Swaps the Address with another one.
host
const
std::string host() constDefined in src/net/include/icy/net/address.h:85
Returns the host IP address.
port
const
uint16_t port() constDefined in src/net/include/icy/net/address.h:88
Returns the port number.
length
const
socklen_t length() constDefined in src/net/include/icy/net/address.h:91
Returns the length of the internal native socket address.
addr
const
const struct sockaddr * addr() constDefined in src/net/include/icy/net/address.h:94
Returns a pointer to the internal native socket address.
af
const
int af() constDefined in src/net/include/icy/net/address.h:97
Returns the address family (AF_INET or AF_INET6) of the address.
toString
const
std::string toString() constDefined in src/net/include/icy/net/address.h:100
Returns a string representation of the address.
family
const
Address::Family family() constDefined in src/net/include/icy/net/address.h:103
Returns the address family of the host's address.
valid
const
bool valid() constDefined in src/net/include/icy/net/address.h:107
Returns true when the port is set and the address is valid ie. not wildcard.
operator<
const
bool operator<(const Address & addr) constDefined in src/net/include/icy/net/address.h:122
Compares two addresses for ordering (by family then port).
Returns
true if this address is less than addr.
Parameters
| Parameter | Type | Description |
|---|---|---|
addr | const Address & | The address to compare against. |
operator==
const
bool operator==(const Address & addr) constDefined in src/net/include/icy/net/address.h:126
Returns true if the host and port of both addresses are equal.
Parameters
| Parameter | Type | Description |
|---|---|---|
addr | const Address & | The address to compare against. |
operator!=
const
bool operator!=(const Address & addr) constDefined in src/net/include/icy/net/address.h:130
Returns true if the host or port of the addresses differ.
Parameters
| Parameter | Type | Description |
|---|---|---|
addr | const Address & | The address to compare against. |
Public Static Methods
| Return | Name | Description |
|---|---|---|
uint16_t | resolveService static | Resolves a service name or decimal port string to a port number. |
bool | validateIP static | Returns true if the given string is a valid IPv4 or IPv6 address. |
resolveService
static
static uint16_t resolveService(const std::string & service)Defined in src/net/include/icy/net/address.h:112
Resolves a service name or decimal port string to a port number.
Returns
The resolved port number in host byte order.
Parameters
| Parameter | Type | Description |
|---|---|---|
service | const std::string & | Service name (e.g. "http") or decimal port string (e.g. "80"). |
validateIP
static
static bool validateIP(std::string_view address)Defined in src/net/include/icy/net/address.h:117
Returns true if the given string is a valid IPv4 or IPv6 address.
Returns
true if the address parses as a valid IP address, false otherwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
address | std::string_view | The string to validate. |
Protected Methods
| Return | Name | Description |
|---|---|---|
void | init |
init
void init(const std::string & host, uint16_t port)Defined in src/net/include/icy/net/address.h:139
Public Types
| Name | Description |
|---|---|
Family | Possible address families for IP addresses. |
Family
enum FamilyDefined in src/net/include/icy/net/address.h:33
Possible address families for IP addresses.
| Value | Description |
|---|---|
IPv4 | |
IPv6 |
Private Attributes
| Return | Name | Description |
|---|---|---|
std::shared_ptr< AddressBase > | _base |
_base
std::shared_ptr< AddressBase > _base