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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- */
/* Lac - Library for asynchronous communication
* Copyright (C) 2002 Søren Sandmann (sandmann@daimi.au.dk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <lac.h>
#include <string.h>
static int n_outstanding;
static GMainLoop *main_loop;
static void
name_callback (const gchar *name, gpointer data, const GError *err)
{
gchar *addr_str = data;
if (err)
{
g_print ("reverse %s: %s\n", addr_str, err->message);
}
else
{
g_print ("reverse %s: %s\n", addr_str, name);
}
g_free (addr_str);
}
static void
callback (const GPtrArray *addresses, gpointer data, const GError *err)
{
gchar *name = data;
if (err)
{
g_print ("%s: %s\n", name, err->message);
}
else
{
int i;
if (addresses->len == 0)
g_print ("this should not happen\n");
for (i = 0; i < addresses->len; ++i)
{
gchar *addr = lac_address_to_str (addresses->pdata[i]);
g_print ("%s: %s\n", name, addr);
lac_dns_get_name (addresses->pdata[i], name_callback, addr);
}
}
if (!strstr (name, "again"))
{
gchar *tmp;
n_outstanding += 2;
lac_dns_get_addresses (name, callback, g_strdup_printf ("%s again", name));
tmp = g_ascii_strup (name, -1);
lac_dns_get_addresses (tmp, callback, g_strdup_printf ("%s (UPPER) again", name));
g_free (tmp);
}
if (--n_outstanding == 0)
g_main_quit (main_loop);
g_free (name);
}
int
main (int argc, char *argv[])
{
int i;
main_loop = g_main_loop_new (NULL, TRUE);
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR |
G_LOG_LEVEL_CRITICAL);
lac_set_verbose (TRUE);
if (argc > 1)
{
for (i = 1; i < argc; ++i)
{
++n_outstanding;
lac_dns_get_addresses (argv[i], callback, g_strdup (argv[i]));
}
}
else
{
g_print ("usage %s <names>\n", argv[0]);
return 1;
}
g_assert (main_loop);
#if 0
g_timeout_add (200, g_main_loop_quit, main_loop);
#endif
g_main_loop_run (main_loop);
return 0;
}
|