net/Resolver: replace with more advanced implementation

The new implementation is copied from another project and is
BSD-licensed.  It is exception-safe and can parse IPv6 scope ids with
interface names.
This commit is contained in:
Max Kellermann
2018-08-21 08:26:12 +02:00
parent eee91aa4ea
commit 4a1e885c0a
9 changed files with 611 additions and 104 deletions

View File

@@ -27,6 +27,7 @@
#include "net/SocketError.hxx"
#include "net/UniqueSocketDescriptor.hxx"
#include "net/Resolver.hxx"
#include "net/AddressInfo.hxx"
#include "net/ToString.hxx"
#include "event/SocketMonitor.hxx"
#include "fs/AllocatedPath.hxx"
@@ -369,12 +370,9 @@ void
ServerSocket::AddHost(const char *hostname, unsigned port)
{
#ifdef HAVE_TCP
struct addrinfo *ai = resolve_host_port(hostname, port,
AI_PASSIVE, SOCK_STREAM);
AtScopeExit(ai) { freeaddrinfo(ai); };
for (const struct addrinfo *i = ai; i != nullptr; i = i->ai_next)
AddAddress(SocketAddress(i->ai_addr, i->ai_addrlen));
for (const auto &i : Resolve(hostname, port,
AI_PASSIVE, SOCK_STREAM))
AddAddress(i);
++next_serial;
#else /* HAVE_TCP */