summaryrefslogtreecommitdiff
path: root/tests/dns.c
blob: f59406479c6e137c761e3815bdd225b71b1d0cd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

#include "test-utils.h"

static GMainLoop *loop;
static int nlookups = 0;

static void
resolve_callback (SoupAddress *addr, guint status, gpointer data)
{
	if (status == SOUP_STATUS_OK) {
		g_print ("Name:    %s\n", soup_address_get_name (addr));
		g_print ("Address: %s\n", soup_address_get_physical (addr));
	} else {
		g_print ("Name:    %s\n", soup_address_get_name (addr));
		g_print ("Error:   %s\n", soup_status_get_phrase (status));
	}
	g_print ("\n");

	g_object_unref (addr);

	nlookups--;
	if (nlookups == 0)
		g_main_loop_quit (loop);
}

static void
usage (void)
{
	g_printerr ("Usage: dns hostname ...\n");
	exit (1);
}

int
main (int argc, char **argv)
{
	SoupAddress *addr;
	int i;

	if (argc < 2)
		usage ();

	g_type_init ();

	for (i = 1; i < argc; i++) {
		addr = soup_address_new (argv[i], 0);
		if (!addr) {
			g_printerr ("Could not parse address %s\n", argv[1]);
			exit (1);
		}

		soup_address_resolve_async (addr, NULL, NULL,
					    resolve_callback, NULL);
		nlookups++;
	}

	loop = g_main_loop_new (NULL, TRUE);
	g_main_loop_run (loop);
	g_main_loop_unref (loop);

	return 0;
}