From cc89f8fbacd851d6d0601dbb9422ff07cdbc6af2 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 22 Sep 2010 13:13:37 +0900 Subject: [PATCH] Read nameservers from /etc/resolv.conf if none are specified --- gresolv/gresolv.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gresolv/gresolv.c b/gresolv/gresolv.c index bab1810..afd0653 100644 --- a/gresolv/gresolv.c +++ b/gresolv/gresolv.c @@ -66,6 +66,8 @@ struct _GResolv { int index; GList *nameserver_list; + struct __res_state res; + GResolvDebugFunc debug_func; gpointer debug_data; }; @@ -357,6 +359,8 @@ GResolv *g_resolv_new(int index) resolv->index = index; resolv->nameserver_list = NULL; + res_ninit(&resolv->res); + return resolv; } @@ -387,6 +391,8 @@ void g_resolv_unref(GResolv *resolv) flush_nameservers(resolv); + res_nclose(&resolv->res); + g_free(resolv); } @@ -451,6 +457,19 @@ guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname, if (resolv == NULL) return 0; + if (resolv->nameserver_list == NULL) { + int i; + + for (i = 0; i < resolv->res.nscount; i++) { + struct sockaddr_in *addr = &resolv->res.nsaddr_list[i]; + g_resolv_add_nameserver(resolv, + inet_ntoa(addr->sin_addr), 53, 0); + } + + if (resolv->nameserver_list == NULL) + g_resolv_add_nameserver(resolv, "127.0.0.1", 53, 0); + } + query = g_try_new0(struct resolv_query, 1); if (query == NULL) return 0; -- 2.7.4