net/AddressInfo: add methods IsInet(), IsTCP()

This commit is contained in:
Max Kellermann 2024-01-05 22:44:16 +01:00 committed by Max Kellermann
parent c04490bd52
commit b15b2125e2

View File

@ -1,8 +1,7 @@
// SPDX-License-Identifier: BSD-2-Clause
// author: Max Kellermann <max.kellermann@gmail.com>
#ifndef NET_ADDRESS_INFO_HXX
#define NET_ADDRESS_INFO_HXX
#pragma once
#include "SocketAddress.hxx"
@ -45,6 +44,14 @@ public:
return ai_protocol;
}
constexpr bool IsInet() const noexcept {
return ai_family == AF_INET || ai_family == AF_INET6;
}
constexpr bool IsTCP() const noexcept {
return IsInet() && GetType() == SOCK_STREAM;
}
constexpr operator SocketAddress() const noexcept {
return {ai_addr, (SocketAddress::size_type)ai_addrlen};
}
@ -130,5 +137,3 @@ public:
return const_iterator(nullptr);
}
};
#endif