Git init
[profile/ivi/libsoup2.4.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         g_object_unref (addr);
24
25         nlookups--;
26         if (nlookups == 0)
27                 g_main_loop_quit (loop);
28 }
29
30 static void
31 usage (void)
32 {
33         fprintf (stderr, "Usage: dns hostname ...\n");
34         exit (1);
35 }
36
37 int
38 main (int argc, char **argv)
39 {
40         SoupAddress *addr;
41         int i;
42
43         if (argc < 2)
44                 usage ();
45
46         g_thread_init (NULL);
47         g_type_init ();
48
49         for (i = 1; i < argc; i++) {
50                 addr = soup_address_new (argv[i], 0);
51                 if (!addr) {
52                         fprintf (stderr, "Could not parse address %s\n", argv[1]);
53                         exit (1);
54                 }
55
56                 soup_address_resolve_async (addr, NULL, NULL,
57                                             resolve_callback, NULL);
58                 nlookups++;
59         }
60
61         loop = g_main_loop_new (NULL, TRUE);
62         g_main_loop_run (loop);
63         g_main_loop_unref (loop);
64
65         return 0;
66 }