net/SocketAddress: add GetSteadyPart()
This commit is contained in:
parent
ba3b422ce5
commit
ede7434901
@ -107,4 +107,41 @@ SocketAddress::GetPort() const noexcept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr ConstBuffer<void>
|
||||||
|
GetSteadyPart(const struct sockaddr_in &address) noexcept
|
||||||
|
{
|
||||||
|
return {&address.sin_addr, sizeof(address.sin_addr)};
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr ConstBuffer<void>
|
||||||
|
GetSteadyPart(const struct sockaddr_in6 &address) noexcept
|
||||||
|
{
|
||||||
|
return {&address.sin6_addr, sizeof(address.sin6_addr)};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ConstBuffer<void>
|
||||||
|
SocketAddress::GetSteadyPart() const noexcept
|
||||||
|
{
|
||||||
|
if (IsNull())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
switch (GetFamily()) {
|
||||||
|
#ifdef HAVE_UN
|
||||||
|
case AF_LOCAL:
|
||||||
|
return GetLocalRaw().ToVoid();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_TCP
|
||||||
|
case AF_INET:
|
||||||
|
return ::GetSteadyPart(*(const struct sockaddr_in *)(const void *)GetAddress());
|
||||||
|
|
||||||
|
case AF_INET6:
|
||||||
|
return ::GetSteadyPart(*(const struct sockaddr_in6 *)(const void *)GetAddress());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
default:
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template<typename T> struct ConstBuffer;
|
||||||
struct StringView;
|
struct StringView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,6 +128,16 @@ public:
|
|||||||
unsigned GetPort() const noexcept;
|
unsigned GetPort() const noexcept;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a buffer pointing to the "steady" portion of the
|
||||||
|
* address, i.e. without volatile parts like the port number.
|
||||||
|
* This buffer is useful for hashing the address, but not so
|
||||||
|
* much for anything else. Returns nullptr if the address is
|
||||||
|
* not supported.
|
||||||
|
*/
|
||||||
|
gcc_pure
|
||||||
|
ConstBuffer<void> GetSteadyPart() const noexcept;
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
bool operator==(const SocketAddress other) const noexcept;
|
bool operator==(const SocketAddress other) const noexcept;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user