net/AddressInfo: add MakeAddrInfo()

This commit is contained in:
Max Kellermann 2020-01-28 22:27:48 +01:00 committed by Max Kellermann
parent 36cad54ccd
commit 50de3a7886
2 changed files with 12 additions and 5 deletions

View File

@ -40,6 +40,17 @@
#include <netdb.h>
#endif
constexpr struct addrinfo
MakeAddrInfo(int flags, int family, int socktype, int protocol=0) noexcept
{
struct addrinfo ai{};
ai.ai_flags = flags;
ai.ai_family = family;
ai.ai_socktype = socktype;
ai.ai_protocol = protocol;
return ai;
}
class AddressInfo : addrinfo {
/* this class cannot be instantiated, it can only be cast from
a struct addrinfo pointer */

View File

@ -149,10 +149,6 @@ Resolve(const char *host_and_port, int default_port,
AddressInfoList
Resolve(const char *host_port, unsigned default_port, int flags, int socktype)
{
struct addrinfo hints{};
hints.ai_flags = flags;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = socktype;
const auto hints = MakeAddrInfo(flags, AF_UNSPEC, socktype);
return Resolve(host_port, default_port, &hints);
}