14 #ifndef THRILL_NET_TCP_SOCKET_ADDRESS_HEADER 15 #define THRILL_NET_TCP_SOCKET_ADDRESS_HEADER 17 #include <netinet/in.h> 18 #include <sys/socket.h> 43 static constexpr
bool debug =
false;
64 memset(&sockaddr_, 0,
sizeof(sockaddr_));
80 return &sockaddr_.generic;
85 return &sockaddr_.generic;
91 sockaddr()->sa_family == AF_INET ?
sizeof(sockaddr_.in) :
92 sockaddr()->sa_family == AF_INET6 ?
sizeof(sockaddr_.in6) :
99 return (
sockaddr()->sa_family == AF_INET) ||
100 (
sockaddr()->sa_family == AF_INET6);
105 return (
sockaddr()->sa_family == AF_INET);
110 return (
sockaddr()->sa_family == AF_INET6);
115 return &sockaddr_.in;
121 return &sockaddr_.in;
126 return &sockaddr_.in6;
132 return &sockaddr_.in6;
142 friend std::ostream&
operator << (std::ostream& os,
147 if (
sockaddr()->sa_family == AF_INET) {
150 else if (
sockaddr()->sa_family == AF_INET6) {
159 if (
sockaddr()->sa_family == AF_INET) {
162 else if (
sockaddr()->sa_family == AF_INET6) {
169 bool Resolve(
const char* hostname,
170 const char* servicename =
nullptr);
175 const char* servicename =
nullptr);
182 const char* defaultservice);
186 static std::vector<SocketAddress>
187 ResolveAll(
const char* hostname,
const char* servicename =
nullptr);
239 explicit IPv4Address(
const char* ipstring, uint16_t port = 0);
266 memcpy(&
sockaddr_.
in6.sin6_addr, addr, 16 *
sizeof(uint8_t));
287 explicit IPv6Address(
const char* ipstring, uint16_t port = 0);
296 #endif // !THRILL_NET_TCP_SOCKET_ADDRESS_HEADER const struct sockaddr * sockaddr() const
Return pointer to enclosed address as a generic sockattr struct.
static SocketAddress ResolveOne(const char *hostname, const char *servicename=nullptr)
IPv6Address(struct in6_addr &addr, uint16_t port)
Create an IPv4 address object with initialized address and port parts.
IPv6Address(uint8_t addr[16], uint16_t port)
Create an IPv6 address object with initialized address and port parts.
static SocketAddress ResolveWithPort(const char *hostname, const char *defaultservice)
IPv4Address(struct in_addr &addr, uint16_t port)
Create an IPv4 address object with initialized address and port parts.
const struct sockaddr_in * sockaddr_in() const
bool Resolve(const char *hostname, const char *servicename=nullptr)
void SetPort(uint16_t port)
Change the currently set port address.
const struct sockaddr_in6 * sockaddr_in6() const
SocketAddress is a super class used to unify the two different IPv4 and IPv6 socket address represent...
SocketAddress()
Create empty invalid address object by clearing all bytes.
IPv6 Subclass of SocketAddress for direct initialization from a known IPv6 address, known either in binary format, numerals, or in some IPv6 format.
bool IsIPv6() const
Returns true if the enclosed socket address is a IPv6 address.
IPv6Address()
Create uninitialized IPv6 address.
union thrill::net::tcp::SocketAddress::SockAddrUnion sockaddr_
IPv4 Subclass of SocketAddress for direct initialization from a known IPv4 address, known either in binary format, numerals, or as "ddd.ddd.ddd.ddd" format.
static std::vector< SocketAddress > ResolveAll(const char *hostname, const char *servicename=nullptr)
friend std::ostream & operator<<(std::ostream &os, const SocketAddress &sa)
Make the socket address ostream-able: outputs address:port.
IPv4Address(struct sockaddr_in &sa)
Create an IPv4 address object and copy the given sockaddr_in structure.
uint16_t GetPort() const
Return the currently set port address in host byte-order.
IPv4Address(uint32_t addr, uint16_t port)
Create an IPv4 address object with initialized address and port parts.
const char * GetResolveError() const
struct sockaddr_in * sockaddr_in()
Cast the enclosed sockaddr into the sockaddr_in IPv4 structure.
IPv4Address(uint16_t port)
Create an IPv4 address and initialize only the port part.
std::string ToStringHost() const
Return the enclosed socket address as a string without the port number.
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
socklen_t socklen() const
Return total length of enclosed sockaddr structure.
IPv4Address()
Create uninitialized IPv4 address.
static constexpr bool debug
bool IsIPv4() const
Returns true if the enclosed socket address is a IPv4 address.
struct sockaddr * sockaddr()
Return pointer to enclosed address as a generic sockattr struct.
std::string ToStringHostPort() const
Return the enclosed socket address as a string with the port number.
struct sockaddr_in6 * sockaddr_in6()
Cast the enclosed sockaddr into the sockaddr_in6 IPv6 structure.
IPv6Address(uint16_t port)
Create an IPv6 address and initialize only the port part.
IPv6Address(struct sockaddr_in6 &sa)
Create an IPv4 address object and copy the given sockaddr_in structure.