3 * Resolver library with GLib integration
5 * Copyright (C) 2009-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
32 #include <sys/types.h>
33 #include <sys/socket.h>
35 #include <arpa/inet.h>
36 #include <arpa/nameser.h>
49 struct sockaddr_in sin;
50 struct sockaddr_in6 sin6;
54 struct sockaddr_in sin;
55 struct sockaddr_in6 sin6;
61 struct resolv_lookup {
66 struct sort_result *results;
68 struct resolv_query *ipv4_query;
69 struct resolv_query *ipv6_query;
74 GResolvResultFunc result_func;
85 struct resolv_lookup *lookup;
88 struct resolv_nameserver {
95 GIOChannel *udp_channel;
104 guint next_lookup_id;
105 GQueue *lookup_queue;
109 GList *nameserver_list;
111 struct __res_state res;
113 GResolvDebugFunc debug_func;
117 static inline void debug(GResolv *resolv, const char *format, ...)
122 if (resolv->debug_func == NULL)
125 va_start(ap, format);
127 if (vsnprintf(str, sizeof(str), format, ap) > 0)
128 resolv->debug_func(str, resolv->debug_data);
133 static void destroy_query(struct resolv_query *query)
135 if (query->timeout > 0)
136 g_source_remove(query->timeout);
141 static void destroy_lookup(struct resolv_lookup *lookup)
143 if (lookup->ipv4_query != NULL) {
144 g_queue_remove(lookup->resolv->query_queue,
146 destroy_query(lookup->ipv4_query);
149 if (lookup->ipv6_query != NULL) {
150 g_queue_remove(lookup->resolv->query_queue,
152 destroy_query(lookup->ipv6_query);
155 g_free(lookup->results);
159 static void find_srcaddr(struct sort_result *res)
161 socklen_t sl = sizeof(res->src);
164 fd = socket(res->dst.sa.sa_family, SOCK_DGRAM | SOCK_CLOEXEC,
169 if (connect(fd, &res->dst.sa, sizeof(res->dst)) < 0) {
174 if (getsockname(fd, &res->src.sa, &sl) < 0) {
179 res->reachable = TRUE;
185 unsigned char addr[NS_IN6ADDRSZ];
190 static const struct gai_table gai_labels[] = {
192 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
197 .addr = { 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
202 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
203 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
207 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
208 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
212 /* Variations from RFC 3484, matching glibc behaviour */
213 .addr = { 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
218 .addr = { 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
223 .addr = { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
229 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
236 static const struct gai_table gai_precedences[] = {
238 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
243 .addr = { 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
248 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
253 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
258 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
265 static unsigned char v4mapped[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 };
268 static gboolean mask_compare(const unsigned char *one,
269 const unsigned char *two, int mask)
272 if (memcmp(one, two, mask / 8))
279 if (mask && ((*one ^ *two) >> (8 - mask)))
285 static int match_gai_table(struct sockaddr *sa, const struct gai_table *tbl)
287 struct sockaddr_in *sin = (void *)sa;
288 struct sockaddr_in6 *sin6 = (void *)sa;
291 if (sa->sa_family == AF_INET) {
293 memcpy(v4mapped+12, &sin->sin_addr, NS_INADDRSZ);
295 addr = &sin6->sin6_addr;
298 if (mask_compare(addr, tbl->addr, tbl->mask))
304 #define DQUAD(_a,_b,_c,_d) ( ((_a)<<24) | ((_b)<<16) | ((_c)<<8) | (_d) )
305 #define V4MATCH(addr, a,b,c,d, m) ( ((addr) ^ DQUAD(a,b,c,d)) >> (32 - (m)) )
307 #define RFC3484_SCOPE_LINK 2
308 #define RFC3484_SCOPE_SITE 5
309 #define RFC3484_SCOPE_GLOBAL 14
311 static int addr_scope(struct sockaddr *sa)
313 if (sa->sa_family == AF_INET) {
314 struct sockaddr_in *sin = (void *)sa;
315 guint32 addr = ntohl(sin->sin_addr.s_addr);
317 if (V4MATCH(addr, 169,254,0,0, 16) ||
318 V4MATCH(addr, 127,0,0,0, 8))
319 return RFC3484_SCOPE_LINK;
322 if (V4MATCH(addr, 10,0,0,0, 8) ||
323 V4MATCH(addr, 172,16,0,0, 12) ||
324 V4MATCH(addr, 192,168,0,0, 16))
325 return RFC3484_SCOPE_SITE;
328 return RFC3484_SCOPE_GLOBAL;
330 struct sockaddr_in6 *sin6 = (void *)sa;
332 /* Multicast addresses have a 4-bit scope field */
333 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
334 return sin6->sin6_addr.s6_addr[1] & 0xf;
336 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) ||
337 IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
338 return RFC3484_SCOPE_LINK;
340 if (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
341 return RFC3484_SCOPE_SITE;
343 return RFC3484_SCOPE_GLOBAL;
347 static int rfc3484_compare(const void *__one, const void *__two)
349 const struct sort_result *one = __one;
350 const struct sort_result *two = __two;
352 /* Rule 1: Avoid unusable destinations */
353 if (one->reachable && !two->reachable)
355 else if (two->reachable && !one->reachable)
358 /* Rule 2: Prefer matching scope */
359 if (one->dst_scope == one->src_scope &&
360 two->dst_scope != two->src_scope)
362 else if (two->dst_scope == two->src_scope &&
363 one->dst_scope != one->src_scope)
366 /* Rule 3: Avoid deprecated addresses */
368 /* Rule 4: Prefer home addresses */
370 /* Rule 5: Prefer matching label */
371 if (one->dst_label == one->src_label &&
372 two->dst_label != two->src_label)
374 else if (two->dst_label == two->src_label &&
375 one->dst_label != one->src_label)
378 /* Rule 6: Prefer higher precedence */
379 if (one->precedence > two->precedence)
381 else if (two->precedence > one->precedence)
384 /* Rule 7: Prefer native transport */
386 /* Rule 8: Prefer smaller scope */
387 if (one->dst_scope != two->dst_scope)
388 return one->dst_scope - two->dst_scope;
390 /* Rule 9: Use longest matching prefix */
391 if (one->dst.sa.sa_family == AF_INET) {
393 * Rule 9 is meaningless and counterproductive for Legacy IP
394 * unless perhaps we can tell that it's actually on the local
395 * subnet. But we don't (yet) have local interface config
396 * information, so do nothing here for Legacy IP for now.
401 for (i = 0; i < 4; i++) {
402 guint32 cmp_one, cmp_two;
404 cmp_one = one->src.sin6.sin6_addr.s6_addr32[i] ^
405 one->dst.sin6.sin6_addr.s6_addr32[i];
406 cmp_two = two->src.sin6.sin6_addr.s6_addr32[i] ^
407 two->dst.sin6.sin6_addr.s6_addr32[i];
409 if (!cmp_two && !cmp_one)
412 if (cmp_one && !cmp_two)
414 if (cmp_two && !cmp_one)
417 /* g_bit_storage() is effectively fls() */
418 cmp_one = g_bit_storage(ntohl(cmp_one));
419 cmp_two = g_bit_storage(ntohl(cmp_two));
421 if (cmp_one == cmp_two)
424 return cmp_one - cmp_two;
429 /* Rule 10: Otherwise, leave the order unchanged */
436 static void rfc3484_sort_results(struct resolv_lookup *lookup)
440 for (i = 0; i < lookup->nr_results; i++) {
441 struct sort_result *res = &lookup->results[i];
443 res->precedence = match_gai_table(&res->dst.sa,
445 res->dst_label = match_gai_table(&res->dst.sa, gai_labels);
446 res->src_label = match_gai_table(&res->src.sa, gai_labels);
447 res->dst_scope = addr_scope(&res->dst.sa);
448 res->src_scope = addr_scope(&res->src.sa);
451 qsort(lookup->results, lookup->nr_results,
452 sizeof(struct sort_result), rfc3484_compare);
455 static void sort_and_return_results(struct resolv_lookup *lookup)
457 char buf[INET6_ADDRSTRLEN + 1];
458 GResolvResultStatus status;
459 char **results = g_try_new0(char *, lookup->nr_results + 1);
465 memset(buf, 0, INET6_ADDRSTRLEN + 1);
467 rfc3484_sort_results(lookup);
469 for (i = 0; i < lookup->nr_results; i++) {
470 if (lookup->results[i].dst.sa.sa_family == AF_INET) {
471 if (inet_ntop(AF_INET,
472 &lookup->results[i].dst.sin.sin_addr,
473 buf, sizeof(buf) - 1) == NULL)
475 } else if (lookup->results[i].dst.sa.sa_family == AF_INET6) {
476 if (inet_ntop(AF_INET6,
477 &lookup->results[i].dst.sin6.sin6_addr,
478 buf, sizeof(buf) - 1) == NULL)
483 results[n++] = strdup(buf);
488 status = lookup->ipv4_status;
490 if (status == G_RESOLV_RESULT_STATUS_SUCCESS)
491 status = lookup->ipv6_status;
493 lookup->result_func(status, results, lookup->result_data);
496 g_queue_remove(lookup->resolv->lookup_queue, lookup);
497 destroy_lookup(lookup);
500 static gboolean query_timeout(gpointer user_data)
502 struct resolv_query *query = user_data;
503 struct resolv_lookup *lookup = query->lookup;
504 GResolv *resolv = query->resolv;
508 if (query == lookup->ipv4_query) {
509 lookup->ipv4_status = G_RESOLV_RESULT_STATUS_NO_RESPONSE;
510 lookup->ipv4_query = NULL;
511 } else if (query == lookup->ipv6_query) {
512 lookup->ipv6_status = G_RESOLV_RESULT_STATUS_NO_RESPONSE;
513 lookup->ipv6_query = NULL;
516 if (lookup->ipv4_query == NULL && lookup->ipv4_query == NULL)
517 sort_and_return_results(lookup);
519 destroy_query(query);
520 g_queue_remove(resolv->query_queue, query);
525 static void free_nameserver(struct resolv_nameserver *nameserver)
527 if (nameserver == NULL)
530 if (nameserver->udp_watch > 0)
531 g_source_remove(nameserver->udp_watch);
533 if (nameserver->udp_channel != NULL)
534 g_io_channel_unref(nameserver->udp_channel);
536 g_free(nameserver->address);
540 static void flush_nameservers(GResolv *resolv)
544 for (list = g_list_first(resolv->nameserver_list);
545 list; list = g_list_next(list))
546 free_nameserver(list->data);
548 g_list_free(resolv->nameserver_list);
549 resolv->nameserver_list = NULL;
552 static int send_query(GResolv *resolv, const unsigned char *buf, int len)
556 if (resolv->nameserver_list == NULL)
559 for (list = g_list_first(resolv->nameserver_list);
560 list; list = g_list_next(list)) {
561 struct resolv_nameserver *nameserver = list->data;
564 if (nameserver->udp_channel == NULL)
567 sk = g_io_channel_unix_get_fd(nameserver->udp_channel);
569 sent = send(sk, buf, len, 0);
577 static gint compare_lookup_id(gconstpointer a, gconstpointer b)
579 const struct resolv_lookup *lookup = a;
580 guint id = GPOINTER_TO_UINT(b);
591 static gint compare_query_msgid(gconstpointer a, gconstpointer b)
593 const struct resolv_query *query = a;
594 uint16_t msgid = GPOINTER_TO_UINT(b);
596 if (query->msgid < msgid)
599 if (query->msgid > msgid)
605 static void add_result(struct resolv_lookup *lookup, int family,
608 int n = lookup->nr_results++;
609 lookup->results = g_realloc(lookup->results,
610 sizeof(struct sort_result) * (n + 1));
612 memset(&lookup->results[n], 0, sizeof(struct sort_result));
614 lookup->results[n].dst.sa.sa_family = family;
615 if (family == AF_INET)
616 memcpy(&lookup->results[n].dst.sin.sin_addr,
619 memcpy(&lookup->results[n].dst.sin6.sin6_addr,
623 static void parse_response(struct resolv_nameserver *nameserver,
624 const unsigned char *buf, int len)
626 GResolv *resolv = nameserver->resolv;
627 GResolvResultStatus status;
628 struct resolv_query *query;
629 struct resolv_lookup *lookup;
635 debug(resolv, "response from %s", nameserver->address);
637 ns_initparse(buf, len, &msg);
639 rcode = ns_msg_getflag(msg, ns_f_rcode);
640 count = ns_msg_count(msg, ns_s_an);
642 debug(resolv, "msg id: 0x%04x rcode: %d count: %d",
643 ns_msg_id(msg), rcode, count);
647 status = G_RESOLV_RESULT_STATUS_SUCCESS;
650 status = G_RESOLV_RESULT_STATUS_FORMAT_ERROR;
653 status = G_RESOLV_RESULT_STATUS_SERVER_FAILURE;
656 status = G_RESOLV_RESULT_STATUS_NAME_ERROR;
659 status = G_RESOLV_RESULT_STATUS_NOT_IMPLEMENTED;
662 status = G_RESOLV_RESULT_STATUS_REFUSED;
665 status = G_RESOLV_RESULT_STATUS_ERROR;
669 list = g_queue_find_custom(resolv->query_queue,
670 GUINT_TO_POINTER(ns_msg_id(msg)), compare_query_msgid);
675 lookup = query->lookup;
677 if (query == lookup->ipv6_query) {
678 lookup->ipv6_status = status;
679 lookup->ipv6_query = NULL;
680 } else if (query == lookup->ipv4_query) {
681 lookup->ipv4_status = status;
682 lookup->ipv4_query = NULL;
685 for (i = 0; i < count; i++) {
686 ns_parserr(&msg, ns_s_an, i, &rr);
688 if (ns_rr_class(rr) != ns_c_in)
691 g_assert(offsetof(struct sockaddr_in, sin_addr) ==
692 offsetof(struct sockaddr_in6, sin6_flowinfo));
694 if (ns_rr_type(rr) == ns_t_a &&
695 ns_rr_rdlen(rr) == NS_INADDRSZ) {
696 add_result(lookup, AF_INET, ns_rr_rdata(rr));
697 } else if (ns_rr_type(rr) == ns_t_aaaa &&
698 ns_rr_rdlen(rr) == NS_IN6ADDRSZ) {
699 add_result(lookup, AF_INET6, ns_rr_rdata(rr));
703 if (lookup->ipv4_query == NULL && lookup->ipv6_query == NULL)
704 sort_and_return_results(lookup);
706 destroy_query(query);
707 g_queue_remove(resolv->query_queue, query);
710 static gboolean received_udp_data(GIOChannel *channel, GIOCondition cond,
713 struct resolv_nameserver *nameserver = user_data;
714 unsigned char buf[4096];
717 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
718 nameserver->udp_watch = 0;
722 sk = g_io_channel_unix_get_fd(nameserver->udp_channel);
724 len = recv(sk, buf, sizeof(buf), 0);
728 parse_response(nameserver, buf, len);
733 static int connect_udp_channel(struct resolv_nameserver *nameserver)
735 struct addrinfo hints, *rp;
739 memset(&hints, 0, sizeof(hints));
740 hints.ai_family = AF_UNSPEC;
741 hints.ai_socktype = SOCK_DGRAM;
742 hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV | AI_NUMERICHOST;
744 sprintf(portnr, "%d", nameserver->port);
745 err = getaddrinfo(nameserver->address, portnr, &hints, &rp);
750 * Do not blindly copy this code elsewhere; it doesn't loop over the
751 * results using ->ai_next as it should. That's OK in *this* case
752 * because it was a numeric lookup; we *know* there's only one.
757 sk = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
763 if (connect(sk, rp->ai_addr, rp->ai_addrlen) < 0) {
771 nameserver->udp_channel = g_io_channel_unix_new(sk);
772 if (nameserver->udp_channel == NULL) {
777 g_io_channel_set_close_on_unref(nameserver->udp_channel, TRUE);
779 nameserver->udp_watch = g_io_add_watch(nameserver->udp_channel,
780 G_IO_IN | G_IO_NVAL | G_IO_ERR | G_IO_HUP,
781 received_udp_data, nameserver);
786 GResolv *g_resolv_new(int index)
793 resolv = g_try_new0(GResolv, 1);
797 resolv->ref_count = 1;
799 resolv->result_family = AF_UNSPEC;
801 resolv->next_lookup_id = 1;
803 resolv->query_queue = g_queue_new();
804 if (resolv->query_queue == NULL) {
809 resolv->lookup_queue = g_queue_new();
810 if (resolv->lookup_queue == NULL) {
811 g_queue_free(resolv->query_queue);
816 resolv->index = index;
817 resolv->nameserver_list = NULL;
819 res_ninit(&resolv->res);
824 GResolv *g_resolv_ref(GResolv *resolv)
829 g_atomic_int_inc(&resolv->ref_count);
834 void g_resolv_unref(GResolv *resolv)
836 struct resolv_query *query;
841 if (g_atomic_int_dec_and_test(&resolv->ref_count) == FALSE)
844 while ((query = g_queue_pop_head(resolv->query_queue)))
845 destroy_query(query);
847 g_queue_free(resolv->query_queue);
848 g_queue_free(resolv->lookup_queue);
850 flush_nameservers(resolv);
852 res_nclose(&resolv->res);
857 void g_resolv_set_debug(GResolv *resolv, GResolvDebugFunc func,
863 resolv->debug_func = func;
864 resolv->debug_data = user_data;
867 gboolean g_resolv_add_nameserver(GResolv *resolv, const char *address,
868 uint16_t port, unsigned long flags)
870 struct resolv_nameserver *nameserver;
875 nameserver = g_try_new0(struct resolv_nameserver, 1);
876 if (nameserver == NULL)
879 nameserver->address = g_strdup(address);
880 nameserver->port = port;
881 nameserver->flags = flags;
883 if (connect_udp_channel(nameserver) < 0) {
884 free_nameserver(nameserver);
888 nameserver->resolv = resolv;
890 resolv->nameserver_list = g_list_append(resolv->nameserver_list,
893 debug(resolv, "setting nameserver %s", address);
898 void g_resolv_flush_nameservers(GResolv *resolv)
903 flush_nameservers(resolv);
906 static gint add_query(struct resolv_lookup *lookup, const char *hostname, int type)
908 struct resolv_query *query = g_try_new0(struct resolv_query, 1);
909 unsigned char buf[4096];
915 len = res_mkquery(ns_o_query, hostname, ns_c_in, type,
916 NULL, 0, NULL, buf, sizeof(buf));
918 query->msgid = buf[0] << 8 | buf[1];
920 if (send_query(lookup->resolv, buf, len) < 0) {
925 query->resolv = lookup->resolv;
926 query->lookup = lookup;
928 g_queue_push_tail(lookup->resolv->query_queue, query);
930 query->timeout = g_timeout_add_seconds(5, query_timeout, query);
932 if (type == ns_t_aaaa)
933 lookup->ipv6_query = query;
935 lookup->ipv4_query = query;
940 guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname,
941 GResolvResultFunc func, gpointer user_data)
943 struct resolv_lookup *lookup;
945 debug(resolv, "lookup hostname %s", hostname);
950 if (resolv->nameserver_list == NULL) {
953 for (i = 0; i < resolv->res.nscount; i++) {
955 int family = resolv->res.nsaddr_list[i].sin_family;
956 void *sa_addr = &resolv->res.nsaddr_list[i].sin_addr;
958 if (family != AF_INET &&
959 resolv->res._u._ext.nsaddrs[i]) {
961 sa_addr = &resolv->res._u._ext.nsaddrs[i]->sin6_addr;
964 if (family != AF_INET && family != AF_INET6)
967 if (inet_ntop(family, sa_addr, buf, sizeof(buf)))
968 g_resolv_add_nameserver(resolv, buf, 53, 0);
971 if (resolv->nameserver_list == NULL)
972 g_resolv_add_nameserver(resolv, "127.0.0.1", 53, 0);
975 lookup = g_try_new0(struct resolv_lookup, 1);
979 lookup->resolv = resolv;
980 lookup->result_func = func;
981 lookup->result_data = user_data;
982 lookup->id = resolv->next_lookup_id++;
984 if (resolv->result_family != AF_INET6) {
985 if (add_query(lookup, hostname, ns_t_a)) {
991 if (resolv->result_family != AF_INET) {
992 if (add_query(lookup, hostname, ns_t_aaaa)) {
993 if (resolv->result_family != AF_INET6) {
994 destroy_query(lookup->ipv4_query);
995 g_queue_remove(resolv->query_queue,
1004 g_queue_push_tail(resolv->lookup_queue, lookup);
1008 gboolean g_resolv_cancel_lookup(GResolv *resolv, guint id)
1012 list = g_queue_find_custom(resolv->lookup_queue,
1013 GUINT_TO_POINTER(id), compare_lookup_id);
1018 destroy_lookup(list->data);
1019 g_queue_remove(resolv->query_queue, list->data);
1024 gboolean g_resolv_set_address_family(GResolv *resolv, int family)
1029 if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6)
1032 resolv->result_family = family;