Socket address (IPv4 or IPv6 address and port).
More...
#include <address.hpp>
|
| static std::vector< Address > | resolve (const std::string &host, uint16_t port, SocketType type, bool passive=false, int family=AF_UNSPEC) |
Socket address (IPv4 or IPv6 address and port).
The address is copied in a sockaddr_storage : it does not depend on getaddrinfo result lifetime.
- Author
- Vincent Lachenal
- Since
- 0.2
◆ Address() [1/2]
| anch::network::Address::Address |
( |
| ) |
|
|
noexcept |
Address default constructor (address is not set)
◆ Address() [2/2]
| anch::network::Address::Address |
( |
const sockaddr * | address, |
|
|
socklen_t | length ) |
Address constructor
- Parameters
-
| address | the address to copy |
| length | the address length |
- Exceptions
-
| std::invalid_argument | length is greater than sockaddr_storage |
◆ data()
| const sockaddr * anch::network::Address::data |
( |
| ) |
const |
|
noexcept |
Raw address getter
- Returns
- the address
◆ getFamily()
| int anch::network::Address::getFamily |
( |
| ) |
const |
|
noexcept |
Address family getter
- Returns
AF_INET , AF_INET6 (or AF_UNSPEC when address is not set)
◆ getHost()
| std::string anch::network::Address::getHost |
( |
| ) |
const |
Numeric host getter
- Returns
- the numeric host (
127.0.0.1 or ::1 for example)
◆ getPort()
| uint16_t anch::network::Address::getPort |
( |
| ) |
const |
|
noexcept |
Port getter
- Returns
- the port
◆ operator==()
| bool anch::network::Address::operator== |
( |
const Address & | other | ) |
const |
|
noexcept |
Check if addresses are equals (same bytes)
- Parameters
-
| other | the address to compare to |
- Returns
true when addresses are equals, false otherwise
◆ resolve()
| std::vector< Address > anch::network::Address::resolve |
( |
const std::string & | host, |
|
|
uint16_t | port, |
|
|
SocketType | type, |
|
|
bool | passive = false, |
|
|
int | family = AF_UNSPEC ) |
|
static |
Resolve host name (with getaddrinfo )
- Parameters
-
| host | the host name or numeric address ; empty for loopback address (or any address when passive ) |
| port | the port |
| type | the socket type |
| passive | true for addresses to bind, false for addresses to connect to |
| family | the address family (AF_UNSPEC , AF_INET or AF_INET6 ; IPv4 addresses are mapped for AF_INET6 ) |
- Returns
- the addresses (at least one)
- Exceptions
-
◆ size()
| socklen_t anch::network::Address::size |
( |
| ) |
const |
|
noexcept |
Raw address length getter
- Returns
- the length
◆ toString()
| std::string anch::network::Address::toString |
( |
| ) |
const |
String representation: host:port ([host]:port for IPv6)
- Returns
- the string representation
The documentation for this class was generated from the following file: