net/IPv6Address: add method GetPortBE()

This commit is contained in:
Max Kellermann 2024-08-19 22:45:40 +02:00 committed by Max Kellermann
parent 7f25ede888
commit dbb2b29271
1 changed files with 11 additions and 1 deletions

View File

@ -132,8 +132,18 @@ public:
return address.sin6_family == AF_INET6; return address.sin6_family == AF_INET6;
} }
/**
* @return the port number in network byte order
*/
constexpr uint16_t GetPortBE() const noexcept {
return address.sin6_port;
}
/**
* @return the port number in host byte order
*/
constexpr uint16_t GetPort() const noexcept { constexpr uint16_t GetPort() const noexcept {
return FromBE16(address.sin6_port); return FromBE16(GetPortBE());
} }
void SetPort(uint16_t port) noexcept { void SetPort(uint16_t port) noexcept {