diff --git a/src/net/AddressInfo.hxx b/src/net/AddressInfo.hxx index cd34197bb..1e6350b75 100644 --- a/src/net/AddressInfo.hxx +++ b/src/net/AddressInfo.hxx @@ -40,6 +40,17 @@ #include #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 */ diff --git a/src/net/Resolver.cxx b/src/net/Resolver.cxx index a4fb5f387..d3c94c142 100644 --- a/src/net/Resolver.cxx +++ b/src/net/Resolver.cxx @@ -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); }