From d9b1f2fefafe63ff53a11491c1c69dc3cf5d2176 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 30 Nov 2022 11:18:22 +0100 Subject: [PATCH] net/SocketAddress: add method HasPort() --- src/net/AllocatedSocketAddress.hxx | 8 ++++++++ src/net/SocketAddress.hxx | 9 +++++++++ 2 files changed, 17 insertions(+) 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. */