net/SocketAddress: add method IsV6Any()

This commit is contained in:
Max Kellermann 2017-05-17 12:22:59 +02:00
parent c629ac7168
commit 3bcabad28c
2 changed files with 14 additions and 0 deletions

View File

@ -48,6 +48,14 @@ SocketAddress::operator==(SocketAddress other) const noexcept
#ifdef HAVE_TCP
bool
SocketAddress::IsV6Any() const noexcept
{
return GetFamily() == AF_INET6 &&
memcmp(&((const struct sockaddr_in6 *)(const void *)GetAddress())->sin6_addr,
&in6addr_any, sizeof(in6addr_any)) == 0;
}
unsigned
SocketAddress::GetPort() const noexcept
{

View File

@ -95,6 +95,12 @@ public:
}
#ifdef HAVE_TCP
/**
* Is this the IPv6 wildcard address (in6addr_any)?
*/
gcc_pure
bool IsV6Any() const noexcept;
/**
* Extract the port number. Returns 0 if not applicable.
*/