46 #ifndef __sockpp_inet6_addr_h 47 #define __sockpp_inet6_addr_h 70 static constexpr
size_t SZ =
sizeof(sockaddr_in6);
88 const in6_addr ANY IN6ADDR_ANY_INIT;
108 std::memcpy(&addr_, &addr, SZ);
122 std::memcpy(&addr_, &addr, SZ);
135 const in6_addr LOOPBACK IN6ADDR_LOOPBACK_INIT;
137 addr.
create(LOOPBACK, port);
159 void create(
const in6_addr& addr, in_port_t
port);
166 void create(
const std::string& saddr, in_port_t port);
172 in6_addr
address()
const {
return addr_.sin6_addr; }
183 return addr_.sin6_addr.s6_addr[i];
189 in_port_t
port()
const {
return ntohs(addr_.sin6_port); }
196 socklen_t
size()
const override {
return socklen_t(SZ); }
202 return reinterpret_cast<const sockaddr*
>(&addr_);
209 return reinterpret_cast<sockaddr*
>(&addr_);
249 #endif // __sockpp_inet6_addr_h Generic socket address.
Definition: sock_address.h:64
static in6_addr resolve_name(const std::string &saddr)
Attempts to resolve the host name into a 32-bit internet address.
static inet6_address loopback(in_port_t port)
Creates an address on the loopback (localhost) interface.
Definition: inet6_address.h:134
virtual sockaddr * sockaddr_ptr()=0
Gets a pointer to this object cast to a sockaddr.
inet6_address(const std::string &saddr, in_port_t port)
Constructs an address using the name of the host and the specified port.
Definition: inet6_address.h:98
static constexpr sa_family_t ADDRESS_FAMILY
The address family for this type of address.
Definition: inet6_address.h:74
socklen_t size() const override
Gets the size of this structure.
Definition: inet6_address.h:196
bool is_set() const
Checks if the address is set to some value.
std::ostream & operator<<(std::ostream &os, const inet6_address &addr)
Stream inserter for the address.
in_port_t port() const
Gets the port number.
Definition: inet6_address.h:189
in6_addr address() const
Gets 128-bit IPv6 address.
Definition: inet6_address.h:172
std::string to_string() const
Gets a printable string for the address.
const sockaddr_in6 * sockaddr_in6_ptr() const
Gets a const pointer to this object cast to a sockaddr_in6.
Definition: inet6_address.h:216
inet6_address(const sockaddr_storage &addr)
Constructs the address by copying the specified structure.
Definition: inet6_address.h:107
void create(const in6_addr &addr, in_port_t port)
Creates the socket address using the specified host address and port number.
uint8_t operator[](int i) const
Gets a byte of the 128-bit IPv6 Address.
Definition: inet6_address.h:182
const sockaddr * sockaddr_ptr() const override
Gets a pointer to this object cast to a sockaddr.
Definition: inet6_address.h:201
Definition: acceptor.h:51
inet6_address(const sock_address &addr)
Constructs the address by copying the specified structure.
Definition: inet6_address.h:114
inet6_address(const inet6_address &addr)
Constructs the address by copying the specified address.
Definition: inet6_address.h:128
inet6_address(const sockaddr_in6 &addr)
Constructs the address by copying the specified structure.
Definition: inet6_address.h:121
inet6_address(in_port_t port)
Constructs an address for any iface using the specified port.
Definition: inet6_address.h:87
Class that represents an internet (IPv6) address.
Definition: inet6_address.h:64
inet6_address()
Constructs an empty address.
Definition: inet6_address.h:80
sockaddr * sockaddr_ptr() override
Gets a pointer to this object cast to a sockaddr.
Definition: inet6_address.h:208
Generic address class for sockpp.
sockaddr_in6 * sockaddr_in6_ptr()
Gets a pointer to this object cast to a sockaddr_in6.
Definition: inet6_address.h:221