net/SocketAddress: add method HasPort()

This commit is contained in:
Max Kellermann 2022-11-30 11:18:22 +01:00 committed by Max Kellermann
parent e3ef0929f1
commit d9b1f2fefa
2 changed files with 17 additions and 0 deletions

View File

@ -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.
*/

View File

@ -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.
*/