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

@@ -19,20 +19,13 @@
#include "config.h"
#include "net/Resolver.hxx"
#include "net/AddressInfo.hxx"
#include "net/ToString.hxx"
#include "net/SocketAddress.hxx"
#include "Log.hxx"
#include <exception>
#ifdef _WIN32
#include <ws2tcpip.h>
#include <winsock.h>
#else
#include <sys/socket.h>
#include <netdb.h>
#endif
#include <stdio.h>
#include <stdlib.h>
@@ -43,15 +36,10 @@ try {
return EXIT_FAILURE;
}
struct addrinfo *ai =
resolve_host_port(argv[1], 80, AI_PASSIVE, SOCK_STREAM);
for (const struct addrinfo *i = ai; i != NULL; i = i->ai_next) {
const auto s = ToString({i->ai_addr, i->ai_addrlen});
printf("%s\n", s.c_str());
for (const auto &i : Resolve(argv[1], 80, AI_PASSIVE, SOCK_STREAM)) {
printf("%s\n", ToString(i).c_str());
}
freeaddrinfo(ai);
return EXIT_SUCCESS;
} catch (...) {
LogError(std::current_exception());