31#include <sptk5/Strings.h>
32#include <sptk5/threads/Locks.h>
37#include <netinet/in.h>
56 mutable SharedMutex m_mutex;
59 std::array<uint8_t,
sizeof(sockaddr_in6)> m_address {};
67 return *(sockaddr*) m_address.data();
74 const sockaddr& any()
const
76 return *(
const sockaddr*) m_address.data();
85 return *(sockaddr_in*) m_address.data();
92 const sockaddr_in& ip_v4()
const
94 return *(
const sockaddr_in*) m_address.data();
101 sockaddr_in6& ip_v6()
103 return *(sockaddr_in6*) m_address.data();
110 const sockaddr_in6& ip_v6()
const
112 return *(
const sockaddr_in6*) m_address.data();
118 void getHostAddress();
124 void setPort(uint16_t p);
150 explicit
Host(const sockaddr_in* addressAndPort);
156 explicit
Host(const sockaddr_in6* addressAndPort);
192 bool operator==(const
Host& other) const;
199 bool operator!=(const
Host& other) const;
244 memcpy(&address, &m_address,
sizeof(address));
253 memcpy(&address, &m_address,
sizeof(address));
256 void setHostNameFromAddress(socklen_t addressLen);
259using SHost = std::shared_ptr<Host>;
280 return strcasecmp(s1.
toString(
true).c_str(), s2.
toString(
true).c_str()) > 0;
Case-insensitive host compare class.
Definition: Host.h:268
bool operator()(const Host &s1, const Host &s2) const
Compare method.
Definition: Host.h:275
void port(uint16_t p)
Definition: Host.h:215
String toString(bool forceAddress=false) const
void getAddress(sockaddr_in6 &address) const
Definition: Host.h:250
void getAddress(sockaddr_in &address) const
Definition: Host.h:241
uint16_t port() const
Definition: Host.h:224