2011-09-20 20:51:46 +02:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2011-09-20 20:51:46 +02:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2015-02-10 21:46:23 +01:00
|
|
|
#include "net/Resolver.hxx"
|
2015-07-22 10:03:36 +02:00
|
|
|
#include "net/ToString.hxx"
|
2015-02-10 20:30:10 +01:00
|
|
|
#include "net/SocketAddress.hxx"
|
2013-09-27 22:31:24 +02:00
|
|
|
#include "Log.hxx"
|
2013-08-10 18:02:44 +02:00
|
|
|
|
2016-10-28 10:36:05 +02:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2017-12-12 10:22:20 +01:00
|
|
|
#ifdef _WIN32
|
2011-09-20 20:51:46 +02:00
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#include <winsock.h>
|
|
|
|
#else
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
|
2014-01-07 23:57:39 +01:00
|
|
|
#include <stdio.h>
|
2011-09-20 20:51:46 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
2016-10-28 10:36:05 +02:00
|
|
|
try {
|
2011-09-20 20:51:46 +02:00
|
|
|
if (argc != 2) {
|
2013-12-24 14:44:08 +01:00
|
|
|
fprintf(stderr, "Usage: run_resolver HOST\n");
|
2011-09-20 20:51:46 +02:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct addrinfo *ai =
|
2016-10-28 10:36:05 +02:00
|
|
|
resolve_host_port(argv[1], 80, AI_PASSIVE, SOCK_STREAM);
|
2011-09-20 20:51:46 +02:00
|
|
|
|
|
|
|
for (const struct addrinfo *i = ai; i != NULL; i = i->ai_next) {
|
2015-07-22 10:20:57 +02:00
|
|
|
const auto s = ToString({i->ai_addr, i->ai_addrlen});
|
2013-12-24 14:44:08 +01:00
|
|
|
printf("%s\n", s.c_str());
|
2011-09-20 20:51:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
freeaddrinfo(ai);
|
|
|
|
return EXIT_SUCCESS;
|
2016-10-28 10:36:05 +02:00
|
|
|
} catch (const std::runtime_error &e) {
|
|
|
|
LogError(e);
|
|
|
|
return EXIT_FAILURE;
|
2011-09-20 20:51:46 +02:00
|
|
|
}
|