5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <gresolv/gresolv.h>
32 static GMainLoop *main_loop = NULL;
34 static void resolv_debug(const char *str, void *data)
36 g_print("%s: %s\n", (const char *) data, str);
39 static void sig_term(int sig)
41 g_main_loop_quit(main_loop);
44 int main(int argc, char *argv[])
51 printf("missing argument\n");
55 resolv = g_resolv_new(index);
57 printf("failed to create resolver\n");
61 g_resolv_set_debug(resolv, resolv_debug, "RESOLV");
63 main_loop = g_main_loop_new(NULL, FALSE);
68 for (i = 2; i < argc; i++)
69 g_resolv_add_nameserver(resolv, argv[i], 53, 0);
71 g_resolv_add_nameserver(resolv, "127.0.0.1", 53, 0);
73 g_resolv_lookup_hostname(resolv, argv[1]);
75 memset(&sa, 0, sizeof(sa));
76 sa.sa_handler = sig_term;
77 sigaction(SIGINT, &sa, NULL);
78 sigaction(SIGTERM, &sa, NULL);
80 g_main_loop_run(main_loop);
82 g_resolv_unref(resolv);
84 g_main_loop_unref(main_loop);