add SOUP_MAINTAINER_FLAGS here too.
[platform/upstream/libsoup.git] / tests / dns.c
1 #include <config.h>
2
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 #include "libsoup/soup-address.h"
7
8 static GMainLoop *loop;
9 static int nlookups = 0;
10
11 static void
12 resolve_callback (SoupAddress *addr, guint status, gpointer data)
13 {
14         if (status == SOUP_STATUS_OK) {
15                 printf ("Name:    %s\n", soup_address_get_name (addr));
16                 printf ("Address: %s\n", soup_address_get_physical (addr));
17         } else {
18                 printf ("Name:    %s\n", soup_address_get_name (addr));
19                 printf ("Error:   %s\n", soup_status_get_phrase (status));
20         }
21         printf ("\n");
22
23         nlookups--;
24         if (nlookups == 0)
25                 g_main_loop_quit (loop);
26 }
27
28 static void
29 usage (void)
30 {
31         fprintf (stderr, "Usage: dns hostname ...\n");
32         exit (1);
33 }
34
35 int
36 main (int argc, char **argv)
37 {
38         SoupAddress *addr;
39         int i;
40
41         if (argc < 2)
42                 usage ();
43
44         g_thread_init (NULL);
45         g_type_init ();
46
47         for (i = 1; i < argc; i++) {
48                 addr = soup_address_new (argv[i], 0);
49                 if (!addr) {
50                         fprintf (stderr, "Could not parse address %s\n", argv[1]);
51                         exit (1);
52                 }
53
54                 soup_address_resolve_async (addr, NULL, NULL,
55                                             resolve_callback, NULL);
56                 nlookups++;
57         }
58
59         loop = g_main_loop_new (NULL, TRUE);
60         g_main_loop_run (loop);
61         g_main_loop_unref (loop);
62
63         return 0;
64 }