3 * Resolver library with GLib integration
5 * Copyright (C) 2009-2012 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
32 #include <sys/types.h>
33 #include <sys/socket.h>
35 #include <arpa/inet.h>
36 #include <arpa/nameser.h>
50 struct sockaddr_in sin;
51 struct sockaddr_in6 sin6;
55 struct sockaddr_in sin;
56 struct sockaddr_in6 sin6;
62 struct resolv_lookup {
67 struct sort_result *results;
69 struct resolv_query *ipv4_query;
70 struct resolv_query *ipv6_query;
75 GResolvResultFunc result_func;
86 struct resolv_lookup *lookup;
89 struct resolv_nameserver {
96 GIOChannel *udp_channel;
105 guint next_lookup_id;
106 GQueue *lookup_queue;
110 GList *nameserver_list;
112 struct __res_state res;
114 GResolvDebugFunc debug_func;
118 static inline void debug(GResolv *resolv, const char *format, ...)
123 if (resolv->debug_func == NULL)
126 va_start(ap, format);
128 if (vsnprintf(str, sizeof(str), format, ap) > 0)
129 resolv->debug_func(str, resolv->debug_data);
134 static void destroy_query(struct resolv_query *query)
136 if (query->timeout > 0)
137 g_source_remove(query->timeout);
142 static void destroy_lookup(struct resolv_lookup *lookup)
144 if (lookup->ipv4_query != NULL) {
145 g_queue_remove(lookup->resolv->query_queue,
147 destroy_query(lookup->ipv4_query);
150 if (lookup->ipv6_query != NULL) {
151 g_queue_remove(lookup->resolv->query_queue,
153 destroy_query(lookup->ipv6_query);
156 g_free(lookup->results);
160 static void find_srcaddr(struct sort_result *res)
162 socklen_t sl = sizeof(res->src);
165 fd = socket(res->dst.sa.sa_family, SOCK_DGRAM | SOCK_CLOEXEC,
170 if (connect(fd, &res->dst.sa, sizeof(res->dst)) < 0) {
175 if (getsockname(fd, &res->src.sa, &sl) < 0) {
180 res->reachable = TRUE;
186 unsigned char addr[NS_IN6ADDRSZ];
191 static const struct gai_table gai_labels[] = {
193 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
198 .addr = { 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
203 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
204 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
208 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
213 /* Variations from RFC 3484, matching glibc behaviour */
214 .addr = { 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
219 .addr = { 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
224 .addr = { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
230 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
237 static const struct gai_table gai_precedences[] = {
239 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
244 .addr = { 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
249 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
254 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
259 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
266 static unsigned char v4mapped[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
267 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 };
269 static gboolean mask_compare(const unsigned char *one,
270 const unsigned char *two, int mask)
273 if (memcmp(one, two, mask / 8))
280 if (mask && ((*one ^ *two) >> (8 - mask)))
286 static int match_gai_table(struct sockaddr *sa, const struct gai_table *tbl)
288 struct sockaddr_in *sin = (void *)sa;
289 struct sockaddr_in6 *sin6 = (void *)sa;
292 if (sa->sa_family == AF_INET) {
294 memcpy(v4mapped+12, &sin->sin_addr, NS_INADDRSZ);
296 addr = &sin6->sin6_addr;
299 if (mask_compare(addr, tbl->addr, tbl->mask))
305 #define DQUAD(_a,_b,_c,_d) ( ((_a)<<24) | ((_b)<<16) | ((_c)<<8) | (_d) )
306 #define V4MATCH(addr, a,b,c,d, m) ( ((addr) ^ DQUAD(a,b,c,d)) >> (32 - (m)) )
308 #define RFC3484_SCOPE_LINK 2
309 #define RFC3484_SCOPE_SITE 5
310 #define RFC3484_SCOPE_GLOBAL 14
312 static int addr_scope(struct sockaddr *sa)
314 if (sa->sa_family == AF_INET) {
315 struct sockaddr_in *sin = (void *)sa;
316 guint32 addr = ntohl(sin->sin_addr.s_addr);
318 if (V4MATCH(addr, 169,254,0,0, 16) ||
319 V4MATCH(addr, 127,0,0,0, 8))
320 return RFC3484_SCOPE_LINK;
323 if (V4MATCH(addr, 10,0,0,0, 8) ||
324 V4MATCH(addr, 172,16,0,0, 12) ||
325 V4MATCH(addr, 192,168,0,0, 16))
326 return RFC3484_SCOPE_SITE;
329 return RFC3484_SCOPE_GLOBAL;
331 struct sockaddr_in6 *sin6 = (void *)sa;
333 /* Multicast addresses have a 4-bit scope field */
334 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
335 return sin6->sin6_addr.s6_addr[1] & 0xf;
337 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) ||
338 IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
339 return RFC3484_SCOPE_LINK;
341 if (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
342 return RFC3484_SCOPE_SITE;
344 return RFC3484_SCOPE_GLOBAL;
348 static int rfc3484_compare(const void *__one, const void *__two)
350 const struct sort_result *one = __one;
351 const struct sort_result *two = __two;
353 /* Rule 1: Avoid unusable destinations */
354 if (one->reachable && !two->reachable)
356 else if (two->reachable && !one->reachable)
359 /* Rule 2: Prefer matching scope */
360 if (one->dst_scope == one->src_scope &&
361 two->dst_scope != two->src_scope)
363 else if (two->dst_scope == two->src_scope &&
364 one->dst_scope != one->src_scope)
367 /* Rule 3: Avoid deprecated addresses */
369 /* Rule 4: Prefer home addresses */
371 /* Rule 5: Prefer matching label */
372 if (one->dst_label == one->src_label &&
373 two->dst_label != two->src_label)
375 else if (two->dst_label == two->src_label &&
376 one->dst_label != one->src_label)
379 /* Rule 6: Prefer higher precedence */
380 if (one->precedence > two->precedence)
382 else if (two->precedence > one->precedence)
385 /* Rule 7: Prefer native transport */
387 /* Rule 8: Prefer smaller scope */
388 if (one->dst_scope != two->dst_scope)
389 return one->dst_scope - two->dst_scope;
391 /* Rule 9: Use longest matching prefix */
392 if (one->dst.sa.sa_family == AF_INET) {
394 * Rule 9 is meaningless and counterproductive for Legacy IP
395 * unless perhaps we can tell that it's actually on the local
396 * subnet. But we don't (yet) have local interface config
397 * information, so do nothing here for Legacy IP for now.
402 for (i = 0; i < 4; i++) {
403 guint32 cmp_one, cmp_two;
405 cmp_one = one->src.sin6.sin6_addr.s6_addr32[i] ^
406 one->dst.sin6.sin6_addr.s6_addr32[i];
407 cmp_two = two->src.sin6.sin6_addr.s6_addr32[i] ^
408 two->dst.sin6.sin6_addr.s6_addr32[i];
410 if (!cmp_two && !cmp_one)
413 if (cmp_one && !cmp_two)
415 if (cmp_two && !cmp_one)
418 /* g_bit_storage() is effectively fls() */
419 cmp_one = g_bit_storage(ntohl(cmp_one));
420 cmp_two = g_bit_storage(ntohl(cmp_two));
422 if (cmp_one == cmp_two)
425 return cmp_one - cmp_two;
430 /* Rule 10: Otherwise, leave the order unchanged */
437 static void rfc3484_sort_results(struct resolv_lookup *lookup)
441 for (i = 0; i < lookup->nr_results; i++) {
442 struct sort_result *res = &lookup->results[i];
444 res->precedence = match_gai_table(&res->dst.sa,
446 res->dst_label = match_gai_table(&res->dst.sa, gai_labels);
447 res->src_label = match_gai_table(&res->src.sa, gai_labels);
448 res->dst_scope = addr_scope(&res->dst.sa);
449 res->src_scope = addr_scope(&res->src.sa);
452 qsort(lookup->results, lookup->nr_results,
453 sizeof(struct sort_result), rfc3484_compare);
456 static void sort_and_return_results(struct resolv_lookup *lookup)
458 char buf[INET6_ADDRSTRLEN + 1];
459 GResolvResultStatus status;
460 char **results = g_try_new0(char *, lookup->nr_results + 1);
466 memset(buf, 0, INET6_ADDRSTRLEN + 1);
468 rfc3484_sort_results(lookup);
470 for (i = 0; i < lookup->nr_results; i++) {
471 if (lookup->results[i].dst.sa.sa_family == AF_INET) {
472 if (inet_ntop(AF_INET,
473 &lookup->results[i].dst.sin.sin_addr,
474 buf, sizeof(buf) - 1) == NULL)
476 } else if (lookup->results[i].dst.sa.sa_family == AF_INET6) {
477 if (inet_ntop(AF_INET6,
478 &lookup->results[i].dst.sin6.sin6_addr,
479 buf, sizeof(buf) - 1) == NULL)
484 results[n++] = strdup(buf);
489 status = lookup->ipv4_status;
491 if (status == G_RESOLV_RESULT_STATUS_SUCCESS)
492 status = lookup->ipv6_status;
494 g_queue_remove(lookup->resolv->lookup_queue, lookup);
496 lookup->result_func(status, results, lookup->result_data);
499 destroy_lookup(lookup);
502 static gboolean query_timeout(gpointer user_data)
504 struct resolv_query *query = user_data;
505 struct resolv_lookup *lookup = query->lookup;
506 GResolv *resolv = query->resolv;
510 if (query == lookup->ipv4_query) {
511 lookup->ipv4_status = G_RESOLV_RESULT_STATUS_NO_RESPONSE;
512 lookup->ipv4_query = NULL;
513 } else if (query == lookup->ipv6_query) {
514 lookup->ipv6_status = G_RESOLV_RESULT_STATUS_NO_RESPONSE;
515 lookup->ipv6_query = NULL;
518 g_queue_remove(resolv->query_queue, query);
520 if (lookup->ipv4_query == NULL && lookup->ipv4_query == NULL)
521 sort_and_return_results(lookup);
523 destroy_query(query);
528 static void free_nameserver(struct resolv_nameserver *nameserver)
530 if (nameserver == NULL)
533 if (nameserver->udp_watch > 0)
534 g_source_remove(nameserver->udp_watch);
536 if (nameserver->udp_channel != NULL)
537 g_io_channel_unref(nameserver->udp_channel);
539 g_free(nameserver->address);
543 static void flush_nameservers(GResolv *resolv)
547 for (list = g_list_first(resolv->nameserver_list);
548 list; list = g_list_next(list))
549 free_nameserver(list->data);
551 g_list_free(resolv->nameserver_list);
552 resolv->nameserver_list = NULL;
555 static int send_query(GResolv *resolv, const unsigned char *buf, int len)
559 if (resolv->nameserver_list == NULL)
562 for (list = g_list_first(resolv->nameserver_list);
563 list; list = g_list_next(list)) {
564 struct resolv_nameserver *nameserver = list->data;
567 if (nameserver->udp_channel == NULL)
570 sk = g_io_channel_unix_get_fd(nameserver->udp_channel);
572 sent = send(sk, buf, len, 0);
580 static gint compare_lookup_id(gconstpointer a, gconstpointer b)
582 const struct resolv_lookup *lookup = a;
583 guint id = GPOINTER_TO_UINT(b);
594 static gint compare_query_msgid(gconstpointer a, gconstpointer b)
596 const struct resolv_query *query = a;
597 uint16_t msgid = GPOINTER_TO_UINT(b);
599 if (query->msgid < msgid)
602 if (query->msgid > msgid)
608 static void add_result(struct resolv_lookup *lookup, int family,
611 int n = lookup->nr_results++;
612 lookup->results = g_try_realloc(lookup->results,
613 sizeof(struct sort_result) * (n + 1));
614 if (lookup->results == NULL)
617 memset(&lookup->results[n], 0, sizeof(struct sort_result));
619 lookup->results[n].dst.sa.sa_family = family;
620 if (family == AF_INET)
621 memcpy(&lookup->results[n].dst.sin.sin_addr,
624 memcpy(&lookup->results[n].dst.sin6.sin6_addr,
628 static void parse_response(struct resolv_nameserver *nameserver,
629 const unsigned char *buf, int len)
631 GResolv *resolv = nameserver->resolv;
632 GResolvResultStatus status;
633 struct resolv_query *query;
634 struct resolv_lookup *lookup;
640 debug(resolv, "response from %s", nameserver->address);
642 #if defined TIZEN_EXT
643 if (ns_initparse(buf, len, &msg) == -1)
646 ns_initparse(buf, len, &msg);
649 rcode = ns_msg_getflag(msg, ns_f_rcode);
650 count = ns_msg_count(msg, ns_s_an);
652 debug(resolv, "msg id: 0x%04x rcode: %d count: %d",
653 ns_msg_id(msg), rcode, count);
657 status = G_RESOLV_RESULT_STATUS_SUCCESS;
660 status = G_RESOLV_RESULT_STATUS_FORMAT_ERROR;
663 status = G_RESOLV_RESULT_STATUS_SERVER_FAILURE;
666 status = G_RESOLV_RESULT_STATUS_NAME_ERROR;
669 status = G_RESOLV_RESULT_STATUS_NOT_IMPLEMENTED;
672 status = G_RESOLV_RESULT_STATUS_REFUSED;
675 status = G_RESOLV_RESULT_STATUS_ERROR;
679 list = g_queue_find_custom(resolv->query_queue,
680 GUINT_TO_POINTER(ns_msg_id(msg)), compare_query_msgid);
685 lookup = query->lookup;
687 if (query == lookup->ipv6_query) {
688 lookup->ipv6_status = status;
689 lookup->ipv6_query = NULL;
690 } else if (query == lookup->ipv4_query) {
691 lookup->ipv4_status = status;
692 lookup->ipv4_query = NULL;
695 for (i = 0; i < count; i++) {
696 #if defined TIZEN_EXT
697 if (ns_parserr(&msg, ns_s_an, i, &rr) == -1)
700 ns_parserr(&msg, ns_s_an, i, &rr);
703 if (ns_rr_class(rr) != ns_c_in)
706 g_assert(offsetof(struct sockaddr_in, sin_addr) ==
707 offsetof(struct sockaddr_in6, sin6_flowinfo));
709 if (ns_rr_type(rr) == ns_t_a &&
710 ns_rr_rdlen(rr) == NS_INADDRSZ) {
711 add_result(lookup, AF_INET, ns_rr_rdata(rr));
712 } else if (ns_rr_type(rr) == ns_t_aaaa &&
713 ns_rr_rdlen(rr) == NS_IN6ADDRSZ) {
714 add_result(lookup, AF_INET6, ns_rr_rdata(rr));
718 g_queue_remove(resolv->query_queue, query);
720 if (lookup->ipv4_query == NULL && lookup->ipv6_query == NULL)
721 sort_and_return_results(lookup);
723 destroy_query(query);
726 static gboolean received_udp_data(GIOChannel *channel, GIOCondition cond,
729 struct resolv_nameserver *nameserver = user_data;
730 unsigned char buf[4096];
733 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
734 nameserver->udp_watch = 0;
738 sk = g_io_channel_unix_get_fd(nameserver->udp_channel);
740 len = recv(sk, buf, sizeof(buf), 0);
744 parse_response(nameserver, buf, len);
749 static int connect_udp_channel(struct resolv_nameserver *nameserver)
751 struct addrinfo hints, *rp;
755 memset(&hints, 0, sizeof(hints));
756 hints.ai_family = AF_UNSPEC;
757 hints.ai_socktype = SOCK_DGRAM;
758 hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV | AI_NUMERICHOST;
760 sprintf(portnr, "%d", nameserver->port);
761 err = getaddrinfo(nameserver->address, portnr, &hints, &rp);
766 * Do not blindly copy this code elsewhere; it doesn't loop over the
767 * results using ->ai_next as it should. That's OK in *this* case
768 * because it was a numeric lookup; we *know* there's only one.
773 sk = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
780 * If nameserver points to localhost ip, their is no need to
781 * bind the socket on any interface.
783 if (nameserver->resolv->index > 0 &&
784 strncmp(nameserver->address, "127.0.0.1", 9) != 0) {
785 char interface[IF_NAMESIZE];
787 memset(interface, 0, IF_NAMESIZE);
788 if (if_indextoname(nameserver->resolv->index,
789 interface) != NULL) {
790 if (setsockopt(sk, SOL_SOCKET, SO_BINDTODEVICE,
791 interface, IF_NAMESIZE) < 0) {
799 if (connect(sk, rp->ai_addr, rp->ai_addrlen) < 0) {
807 nameserver->udp_channel = g_io_channel_unix_new(sk);
808 if (nameserver->udp_channel == NULL) {
813 g_io_channel_set_close_on_unref(nameserver->udp_channel, TRUE);
815 nameserver->udp_watch = g_io_add_watch(nameserver->udp_channel,
816 G_IO_IN | G_IO_NVAL | G_IO_ERR | G_IO_HUP,
817 received_udp_data, nameserver);
822 GResolv *g_resolv_new(int index)
829 resolv = g_try_new0(GResolv, 1);
833 resolv->ref_count = 1;
835 resolv->result_family = AF_UNSPEC;
837 resolv->next_lookup_id = 1;
839 resolv->query_queue = g_queue_new();
840 if (resolv->query_queue == NULL) {
845 resolv->lookup_queue = g_queue_new();
846 if (resolv->lookup_queue == NULL) {
847 g_queue_free(resolv->query_queue);
852 resolv->index = index;
853 resolv->nameserver_list = NULL;
855 res_ninit(&resolv->res);
860 GResolv *g_resolv_ref(GResolv *resolv)
865 __sync_fetch_and_add(&resolv->ref_count, 1);
870 void g_resolv_unref(GResolv *resolv)
872 struct resolv_query *query;
877 if (__sync_fetch_and_sub(&resolv->ref_count, 1) != 1)
880 while ((query = g_queue_pop_head(resolv->query_queue)))
881 destroy_query(query);
883 g_queue_free(resolv->query_queue);
884 g_queue_free(resolv->lookup_queue);
886 flush_nameservers(resolv);
888 res_nclose(&resolv->res);
893 void g_resolv_set_debug(GResolv *resolv, GResolvDebugFunc func,
899 resolv->debug_func = func;
900 resolv->debug_data = user_data;
903 gboolean g_resolv_add_nameserver(GResolv *resolv, const char *address,
904 uint16_t port, unsigned long flags)
906 struct resolv_nameserver *nameserver;
911 nameserver = g_try_new0(struct resolv_nameserver, 1);
912 if (nameserver == NULL)
915 nameserver->address = g_strdup(address);
916 nameserver->port = port;
917 nameserver->flags = flags;
918 nameserver->resolv = resolv;
920 if (connect_udp_channel(nameserver) < 0) {
921 free_nameserver(nameserver);
925 resolv->nameserver_list = g_list_append(resolv->nameserver_list,
928 debug(resolv, "setting nameserver %s", address);
933 void g_resolv_flush_nameservers(GResolv *resolv)
938 flush_nameservers(resolv);
941 static gint add_query(struct resolv_lookup *lookup, const char *hostname, int type)
943 struct resolv_query *query = g_try_new0(struct resolv_query, 1);
944 unsigned char buf[4096];
950 len = res_mkquery(ns_o_query, hostname, ns_c_in, type,
951 NULL, 0, NULL, buf, sizeof(buf));
953 query->msgid = buf[0] << 8 | buf[1];
955 if (send_query(lookup->resolv, buf, len) < 0) {
960 query->resolv = lookup->resolv;
961 query->lookup = lookup;
963 g_queue_push_tail(lookup->resolv->query_queue, query);
965 query->timeout = g_timeout_add_seconds(5, query_timeout, query);
967 if (type == ns_t_aaaa)
968 lookup->ipv6_query = query;
970 lookup->ipv4_query = query;
975 guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname,
976 GResolvResultFunc func, gpointer user_data)
978 struct resolv_lookup *lookup;
980 debug(resolv, "lookup hostname %s", hostname);
985 if (resolv->nameserver_list == NULL) {
988 for (i = 0; i < resolv->res.nscount; i++) {
990 int family = resolv->res.nsaddr_list[i].sin_family;
991 void *sa_addr = &resolv->res.nsaddr_list[i].sin_addr;
993 if (family != AF_INET &&
994 resolv->res._u._ext.nsaddrs[i]) {
996 sa_addr = &resolv->res._u._ext.nsaddrs[i]->sin6_addr;
999 if (family != AF_INET && family != AF_INET6)
1002 if (inet_ntop(family, sa_addr, buf, sizeof(buf)))
1003 g_resolv_add_nameserver(resolv, buf, 53, 0);
1006 if (resolv->nameserver_list == NULL)
1007 g_resolv_add_nameserver(resolv, "127.0.0.1", 53, 0);
1010 lookup = g_try_new0(struct resolv_lookup, 1);
1014 lookup->resolv = resolv;
1015 lookup->result_func = func;
1016 lookup->result_data = user_data;
1017 lookup->id = resolv->next_lookup_id++;
1019 if (resolv->result_family != AF_INET6) {
1020 if (add_query(lookup, hostname, ns_t_a)) {
1026 if (resolv->result_family != AF_INET) {
1027 if (add_query(lookup, hostname, ns_t_aaaa)) {
1028 if (resolv->result_family != AF_INET6) {
1029 destroy_query(lookup->ipv4_query);
1030 g_queue_remove(resolv->query_queue,
1031 lookup->ipv4_query);
1039 g_queue_push_tail(resolv->lookup_queue, lookup);
1043 gboolean g_resolv_cancel_lookup(GResolv *resolv, guint id)
1047 list = g_queue_find_custom(resolv->lookup_queue,
1048 GUINT_TO_POINTER(id), compare_lookup_id);
1053 destroy_lookup(list->data);
1054 g_queue_remove(resolv->query_queue, list->data);
1059 gboolean g_resolv_set_address_family(GResolv *resolv, int family)
1064 if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6)
1067 resolv->result_family = family;