diff --git a/src/net/AllocatedSocketAddress.hxx b/src/net/AllocatedSocketAddress.hxx index 0c2de69b4..eb2433af5 100644 --- a/src/net/AllocatedSocketAddress.hxx +++ b/src/net/AllocatedSocketAddress.hxx @@ -175,6 +175,14 @@ public: return ((SocketAddress)*this).IsV4Mapped(); } + /** + * Does the address family support port numbers? + */ + [[gnu::pure]] + bool HasPort() const noexcept { + return ((SocketAddress)*this).HasPort(); + } + /** * Extract the port number. Returns 0 if not applicable. */ diff --git a/src/net/SocketAddress.hxx b/src/net/SocketAddress.hxx index 9d5297e21..184eb4714 100644 --- a/src/net/SocketAddress.hxx +++ b/src/net/SocketAddress.hxx @@ -163,6 +163,15 @@ public: [[gnu::pure]] IPv4Address UnmapV4() const noexcept; + /** + * Does the address family support port numbers? + */ + [[gnu::pure]] + bool HasPort() const noexcept { + return !IsNull() && + (GetFamily() == AF_INET || GetFamily() == AF_INET6); + } + /** * Extract the port number. Returns 0 if not applicable. */