run_resolver.cxx 1.56 KB
Newer Older
1
/*
2
 * Copyright 2003-2016 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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"
21
#include "net/Resolver.hxx"
22
#include "net/ToString.hxx"
23
#include "net/SocketAddress.hxx"
24
#include "Log.hxx"
25

26 27
#include <stdexcept>

28 29 30 31 32 33 34 35
#ifdef WIN32
#include <ws2tcpip.h>
#include <winsock.h>
#else
#include <sys/socket.h>
#include <netdb.h>
#endif

36
#include <stdio.h>
37 38 39
#include <stdlib.h>

int main(int argc, char **argv)
40
try {
41
	if (argc != 2) {
42
		fprintf(stderr, "Usage: run_resolver HOST\n");
43 44 45 46
		return EXIT_FAILURE;
	}

	struct addrinfo *ai =
47
		resolve_host_port(argv[1], 80, AI_PASSIVE, SOCK_STREAM);
48 49

	for (const struct addrinfo *i = ai; i != NULL; i = i->ai_next) {
50
		const auto s = ToString({i->ai_addr, i->ai_addrlen});
51
		printf("%s\n", s.c_str());
52 53 54 55
	}

	freeaddrinfo(ai);
	return EXIT_SUCCESS;
56 57 58
} catch (const std::runtime_error &e) {
	LogError(e);
	return EXIT_FAILURE;
59
}