Thrill
0.1
|
SocketAddress is a super class used to unify the two different IPv4 and IPv6 socket address representation.
It is derived into IPv4Address and IPv6Address only for direct initialization, in general one just uses SocketAddress("localhost:1234") for appropriate resolution into a sockaddr. The SocketAddress object can then be given to various Connect(), Bind() and similar functions of Socket.
Definition at line 41 of file socket_address.hpp.
#include <socket_address.hpp>
Classes | |
union | SockAddrUnion |
Public Member Functions | |
SocketAddress () | |
Create empty invalid address object by clearing all bytes. More... | |
SocketAddress (struct sockaddr *sa, socklen_t salen) | |
Create a socket address object with the given sockaddr data. More... | |
SocketAddress (const std::string &hostport) | |
SocketAddress (const char *hostname, const char *servicename) | |
uint16_t | GetPort () const |
Return the currently set port address in host byte-order. More... | |
const char * | GetResolveError () const |
bool | IsIPv4 () const |
Returns true if the enclosed socket address is a IPv4 address. More... | |
bool | IsIPv6 () const |
Returns true if the enclosed socket address is a IPv6 address. More... | |
bool | IsValid () const |
bool | Resolve (const char *hostname, const char *servicename=nullptr) |
void | SetPort (uint16_t port) |
Change the currently set port address. More... | |
struct sockaddr * | sockaddr () |
Return pointer to enclosed address as a generic sockattr struct. More... | |
const struct sockaddr * | sockaddr () const |
Return pointer to enclosed address as a generic sockattr struct. More... | |
struct sockaddr_in * | sockaddr_in () |
Cast the enclosed sockaddr into the sockaddr_in IPv4 structure. More... | |
const struct sockaddr_in * | sockaddr_in () const |
struct sockaddr_in6 * | sockaddr_in6 () |
Cast the enclosed sockaddr into the sockaddr_in6 IPv6 structure. More... | |
const struct sockaddr_in6 * | sockaddr_in6 () const |
socklen_t | socklen () const |
Return total length of enclosed sockaddr structure. More... | |
std::string | ToStringHost () const |
Return the enclosed socket address as a string without the port number. More... | |
std::string | ToStringHostPort () const |
Return the enclosed socket address as a string with the port number. More... | |
Static Public Member Functions | |
static std::vector< SocketAddress > | ResolveAll (const char *hostname, const char *servicename=nullptr) |
static SocketAddress | ResolveOne (const char *hostname, const char *servicename=nullptr) |
static SocketAddress | ResolveWithPort (const char *hostname, const char *defaultservice) |
Protected Attributes | |
union thrill::net::tcp::SocketAddress::SockAddrUnion | sockaddr_ |
Private Attributes | |
int | resolve_error_ |
Static Private Attributes | |
static constexpr bool | debug = false |
Friends | |
std::ostream & | operator<< (std::ostream &os, const SocketAddress &sa) |
Make the socket address ostream-able: outputs address:port. More... | |
|
inline |
Create empty invalid address object by clearing all bytes.
Definition at line 62 of file socket_address.hpp.
References SocketAddress::sockaddr().
Referenced by SocketAddress::Resolve(), SocketAddress::ResolveAll(), and SocketAddress::ResolveOne().
SocketAddress | ( | struct sockaddr * | sa, |
socklen_t | salen | ||
) |
Create a socket address object with the given sockaddr data.
Definition at line 30 of file socket_address.cpp.
References SocketAddress::sockaddr_.
|
explicit |
Create a socket address object and resolve the given host:port using getaddrinfo(). Check result with IsValid().
Definition at line 35 of file socket_address.cpp.
References SocketAddress::Resolve().
SocketAddress | ( | const char * | hostname, |
const char * | servicename | ||
) |
Create a socket address object and resolve the given host name using getaddrinfo(). Check result with IsValid().
Definition at line 50 of file socket_address.cpp.
References SocketAddress::Resolve().
|
inline |
Return the currently set port address in host byte-order.
Definition at line 146 of file socket_address.hpp.
References SocketAddress::sockaddr(), SocketAddress::sockaddr_in(), and SocketAddress::sockaddr_in6().
Referenced by SocketAddress::ToStringHostPort().
const char * GetResolveError | ( | ) | const |
Return textual message of the last error occurring in the resolve method.
Definition at line 113 of file socket_address.cpp.
References SocketAddress::resolve_error_.
Referenced by SocketAddress::SetPort().
|
inline |
Returns true if the enclosed socket address is a IPv4 address.
Definition at line 104 of file socket_address.hpp.
References SocketAddress::sockaddr().
|
inline |
Returns true if the enclosed socket address is a IPv6 address.
Definition at line 109 of file socket_address.hpp.
References SocketAddress::sockaddr().
|
inline |
Returns true if the enclosed socket address is a valid IPv4 or IPv6 address.
Definition at line 98 of file socket_address.hpp.
References SocketAddress::sockaddr().
Referenced by Socket::bind(), Socket::connect(), and SocketAddress::Resolve().
bool Resolve | ( | const char * | hostname, |
const char * | servicename = nullptr |
||
) |
Resolve the given host name using getaddrinfo() and replace this object with the first socket address if found.
Definition at line 88 of file socket_address.cpp.
References SocketAddress::IsValid(), SocketAddress::resolve_error_, SocketAddress::sockaddr_, and SocketAddress::SocketAddress().
Referenced by SocketAddress::SetPort(), and SocketAddress::SocketAddress().
|
static |
Resolve the given host name using getaddrinfo() and return all resulting socket addresses as a vector.
Definition at line 156 of file socket_address.cpp.
References SocketAddress::SocketAddress().
Referenced by SocketAddress::SetPort().
|
static |
Resolve the given host name using getaddrinfo() and return only the first socket address if found.
Definition at line 118 of file socket_address.cpp.
References SocketAddress::SocketAddress().
Referenced by SocketAddress::ResolveWithPort(), and SocketAddress::SetPort().
|
static |
Parse the address for a :port notation and then resolve the given host name using getaddrinfo() and return only the first socket address if found. Uses defaultservice if no port is found in the hostname.
Definition at line 141 of file socket_address.cpp.
References SocketAddress::ResolveOne().
Referenced by SocketAddress::SetPort().
|
inline |
Change the currently set port address.
Definition at line 158 of file socket_address.hpp.
References SocketAddress::GetResolveError(), SocketAddress::Resolve(), SocketAddress::ResolveAll(), SocketAddress::ResolveOne(), SocketAddress::ResolveWithPort(), SocketAddress::sockaddr(), SocketAddress::sockaddr_in(), and SocketAddress::sockaddr_in6().
|
inline |
Return pointer to enclosed address as a generic sockattr struct.
Definition at line 79 of file socket_address.hpp.
Referenced by Socket::bind(), Socket::connect(), SocketAddress::GetPort(), SocketAddress::IsIPv4(), SocketAddress::IsIPv6(), SocketAddress::IsValid(), Socket::sendto(), SocketAddress::SetPort(), SocketAddress::SocketAddress(), SocketAddress::socklen(), and SocketAddress::ToStringHost().
|
inline |
Return pointer to enclosed address as a generic sockattr struct.
Definition at line 84 of file socket_address.hpp.
|
inline |
Cast the enclosed sockaddr into the sockaddr_in IPv4 structure.
Definition at line 114 of file socket_address.hpp.
Referenced by SocketAddress::GetPort(), IPv4Address::IPv4Address(), SocketAddress::SetPort(), and SocketAddress::ToStringHost().
|
inline |
Cast the enclosed sockaddr into the sockaddr_in IPv4 structure. Const version.
Definition at line 120 of file socket_address.hpp.
|
inline |
Cast the enclosed sockaddr into the sockaddr_in6 IPv6 structure.
Definition at line 125 of file socket_address.hpp.
Referenced by SocketAddress::GetPort(), IPv6Address::IPv6Address(), SocketAddress::SetPort(), and SocketAddress::ToStringHost().
|
inline |
Cast the enclosed sockaddr into the sockaddr_in6 IPv6 structure. Const version.
Definition at line 131 of file socket_address.hpp.
References SocketAddress::operator<<, SocketAddress::ToStringHost(), and SocketAddress::ToStringHostPort().
|
inline |
Return total length of enclosed sockaddr structure.
Definition at line 89 of file socket_address.hpp.
References SocketAddress::sockaddr().
Referenced by Socket::bind(), Socket::connect(), and Socket::sendto().
std::string ToStringHost | ( | ) | const |
Return the enclosed socket address as a string without the port number.
Definition at line 54 of file socket_address.cpp.
References sLOG, SocketAddress::sockaddr(), SocketAddress::sockaddr_in(), and SocketAddress::sockaddr_in6().
Referenced by SocketAddress::sockaddr_in6(), and SocketAddress::ToStringHostPort().
std::string ToStringHostPort | ( | ) | const |
Return the enclosed socket address as a string with the port number.
Definition at line 80 of file socket_address.cpp.
References SocketAddress::GetPort(), thrill::mem::to_string(), and SocketAddress::ToStringHost().
Referenced by Connection::GetPeerAddress(), thrill::net::tcp::operator<<(), and SocketAddress::sockaddr_in6().
|
friend |
Make the socket address ostream-able: outputs address:port.
Definition at line 84 of file socket_address.cpp.
Referenced by SocketAddress::sockaddr_in6().
|
staticprivate |
Definition at line 43 of file socket_address.hpp.
|
private |
Return value of the last getaddrinfo() call. Used to output nice user messages.
Definition at line 58 of file socket_address.hpp.
Referenced by SocketAddress::GetResolveError(), and SocketAddress::Resolve().
|
protected |