47 #ifndef __sockpp_inet_addr_h 48 #define __sockpp_inet_addr_h 71 static constexpr
size_t SZ =
sizeof(sockaddr_in);
89 create(in_addr_t(INADDR_ANY), port);
113 std::memcpy(&addr_, &addr, SZ);
145 static in_addr_t
resolve_name(
const std::string& saddr);
160 void create(
const std::string& saddr, in_port_t port);
165 in_addr_t
address()
const {
return ntohl(addr_.sin_addr.s_addr); }
173 return ((
const uint8_t*)&addr)[i];
179 in_port_t
port()
const {
return ntohs(addr_.sin_port); }
186 socklen_t
size()
const override {
return socklen_t(SZ); }
192 return reinterpret_cast<const sockaddr*
>(&addr_);
199 return reinterpret_cast<sockaddr*
>(&addr_);
206 return static_cast<const sockaddr_in*
>(&addr_);
213 return static_cast<sockaddr_in*
>(&addr_);
241 #endif // __sockpp_inet_addr_h Generic socket address.
Definition: sock_address.h:64
static in_addr_t resolve_name(const std::string &saddr)
Attempts to resolve the host name into a 32-bit internet address.
virtual sockaddr * sockaddr_ptr()=0
Gets a pointer to this object cast to a sockaddr.
static constexpr sa_family_t ADDRESS_FAMILY
The address family for this type of address.
Definition: inet_address.h:75
inet_address(const sockaddr &addr)
Constructs the address by copying the specified structure.
Definition: inet_address.h:112
std::string to_string() const
Gets a printable string for the address.
inet_address(in_port_t port)
Constructs an address for any iface using the specified port.
Definition: inet_address.h:88
uint8_t operator[](int i) const
Gets a byte of the 32-bit Internet Address.
Definition: inet_address.h:171
sockaddr_in * sockaddr_in_ptr()
Gets a pointer to this object cast to a sockaddr_in.
Definition: inet_address.h:212
std::ostream & operator<<(std::ostream &os, const inet6_address &addr)
Stream inserter for the address.
in_addr_t address() const
Gets the 32-bit internet address.
Definition: inet_address.h:165
inet_address(const sock_address &addr)
Constructs the address by copying the specified structure.
Definition: inet_address.h:119
void create(in_addr_t addr, in_port_t port)
Creates the socket address using the specified host address and port number.
sockaddr * sockaddr_ptr() override
Gets a pointer to this object cast to a sockaddr.
Definition: inet_address.h:198
inet_address(const sockaddr_in &addr)
Constructs the address by copying the specified structure.
Definition: inet_address.h:126
inet_address(uint32_t addr, in_port_t port)
Constructs an address for the specified host using the specified port.
Definition: inet_address.h:97
Definition: acceptor.h:51
socklen_t size() const override
Gets the size of this structure.
Definition: inet_address.h:186
in_port_t port() const
Gets the port number.
Definition: inet_address.h:179
Class that represents an internet (IPv4) address.
Definition: inet_address.h:65
inet_address(const std::string &saddr, in_port_t port)
Constructs an address using the name of the host and the specified port.
Definition: inet_address.h:105
inet_address(const inet_address &addr)
Constructs the address by copying the specified address.
Definition: inet_address.h:131
bool is_set() const
Checks if the address is set to some value.
const sockaddr_in * sockaddr_in_ptr() const
Gets a const pointer to this object cast to a sockaddr_in.
Definition: inet_address.h:205
inet_address()
Constructs an empty address.
Definition: inet_address.h:81
Generic address class for sockpp.
const sockaddr * sockaddr_ptr() const override
Gets a pointer to this object cast to a sockaddr.
Definition: inet_address.h:191