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, IPPROTO_IP);
168 if (connect(fd, &res->dst.sa, sizeof(res->dst)) < 0) {
173 if (getsockname(fd, &res->src.sa, &sl) < 0) {
178 res->reachable = TRUE;
184 unsigned char addr[NS_IN6ADDRSZ];
189 static const struct gai_table gai_labels[] = {
191 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
196 .addr = { 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
201 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
206 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
207 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
211 /* Variations from RFC 3484, matching glibc behaviour */
212 .addr = { 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
217 .addr = { 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
222 .addr = { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
228 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
235 static const struct gai_table gai_precedences[] = {
237 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
242 .addr = { 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
247 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
252 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
253 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
257 .addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
264 static unsigned char v4mapped[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
265 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 };
267 static gboolean mask_compare(const unsigned char *one,
268 const unsigned char *two, int mask)
271 if (memcmp(one, two, mask / 8))
278 if (mask && ((*one ^ *two) >> (8 - mask)))
284 static int match_gai_table(struct sockaddr *sa, const struct gai_table *tbl)
286 struct sockaddr_in *sin = (void *)sa;
287 struct sockaddr_in6 *sin6 = (void *)sa;
290 if (sa->sa_family == AF_INET) {
292 memcpy(v4mapped+12, &sin->sin_addr, NS_INADDRSZ);
294 addr = &sin6->sin6_addr;
297 if (mask_compare(addr, tbl->addr, tbl->mask))
303 #define DQUAD(_a,_b,_c,_d) ( ((_a)<<24) | ((_b)<<16) | ((_c)<<8) | (_d) )
304 #define V4MATCH(addr, a,b,c,d, m) ( ((addr) ^ DQUAD(a,b,c,d)) >> (32 - (m)) )
306 #define RFC3484_SCOPE_LINK 2
307 #define RFC3484_SCOPE_SITE 5
308 #define RFC3484_SCOPE_GLOBAL 14
310 static int addr_scope(struct sockaddr *sa)
312 if (sa->sa_family == AF_INET) {
313 struct sockaddr_in *sin = (void *)sa;
314 guint32 addr = ntohl(sin->sin_addr.s_addr);
316 if (V4MATCH(addr, 169,254,0,0, 16) ||
317 V4MATCH(addr, 127,0,0,0, 8))
318 return RFC3484_SCOPE_LINK;
321 if (V4MATCH(addr, 10,0,0,0, 8) ||
322 V4MATCH(addr, 172,16,0,0, 12) ||
323 V4MATCH(addr, 192,168,0,0, 16))
324 return RFC3484_SCOPE_SITE;
327 return RFC3484_SCOPE_GLOBAL;
329 struct sockaddr_in6 *sin6 = (void *)sa;
331 /* Multicast addresses have a 4-bit scope field */
332 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
333 return sin6->sin6_addr.s6_addr[1] & 0xf;
335 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) ||
336 IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
337 return RFC3484_SCOPE_LINK;
339 if (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
340 return RFC3484_SCOPE_SITE;
342 return RFC3484_SCOPE_GLOBAL;
346 static int rfc3484_compare(const void *__one, const void *__two)
348 const struct sort_result *one = __one;
349 const struct sort_result *two = __two;
351 /* Rule 1: Avoid unusable destinations */
352 if (one->reachable && !two->reachable)
354 else if (two->reachable && !one->reachable)
357 /* Rule 2: Prefer matching scope */
358 if (one->dst_scope == one->src_scope &&
359 two->dst_scope != two->src_scope)
361 else if (two->dst_scope == two->src_scope &&
362 one->dst_scope != one->src_scope)
365 /* Rule 3: Avoid deprecated addresses */
367 /* Rule 4: Prefer home addresses */
369 /* Rule 5: Prefer matching label */
370 if (one->dst_label == one->src_label &&
371 two->dst_label != two->src_label)
373 else if (two->dst_label == two->src_label &&
374 one->dst_label != one->src_label)
377 /* Rule 6: Prefer higher precedence */
378 if (one->precedence > two->precedence)
380 else if (two->precedence > one->precedence)
383 /* Rule 7: Prefer native transport */
385 /* Rule 8: Prefer smaller scope */
386 if (one->dst_scope != two->dst_scope)
387 return one->dst_scope - two->dst_scope;
389 /* Rule 9: Use longest matching prefix */
390 if (one->dst.sa.sa_family == AF_INET) {
392 * Rule 9 is meaningless and counterproductive for Legacy IP
393 * unless perhaps we can tell that it's actually on the local
394 * subnet. But we don't (yet) have local interface config
395 * information, so do nothing here for Legacy IP for now.
400 for (i = 0; i < 4; i++) {
401 guint32 cmp_one, cmp_two;
403 cmp_one = one->src.sin6.sin6_addr.s6_addr32[i] ^
404 one->dst.sin6.sin6_addr.s6_addr32[i];
405 cmp_two = two->src.sin6.sin6_addr.s6_addr32[i] ^
406 two->dst.sin6.sin6_addr.s6_addr32[i];
408 if (!cmp_two && !cmp_one)
411 if (cmp_one && !cmp_two)
413 if (cmp_two && !cmp_one)
416 /* g_bit_storage() is effectively fls() */
417 cmp_one = g_bit_storage(ntohl(cmp_one));
418 cmp_two = g_bit_storage(ntohl(cmp_two));
420 if (cmp_one == cmp_two)
423 return cmp_one - cmp_two;
428 /* Rule 10: Otherwise, leave the order unchanged */
435 static void rfc3484_sort_results(struct resolv_lookup *lookup)
439 for (i = 0; i < lookup->nr_results; i++) {
440 struct sort_result *res = &lookup->results[i];
442 res->precedence = match_gai_table(&res->dst.sa,
444 res->dst_label = match_gai_table(&res->dst.sa, gai_labels);
445 res->src_label = match_gai_table(&res->src.sa, gai_labels);
446 res->dst_scope = addr_scope(&res->dst.sa);
447 res->src_scope = addr_scope(&res->src.sa);
450 qsort(lookup->results, lookup->nr_results,
451 sizeof(struct sort_result), rfc3484_compare);
454 static void sort_and_return_results(struct resolv_lookup *lookup)
457 GResolvResultStatus status;
458 char **results = g_try_new0(char *, lookup->nr_results + 1);
464 rfc3484_sort_results(lookup);
466 for (i = 0; i < lookup->nr_results; i++) {
467 if (lookup->results[i].dst.sa.sa_family == AF_INET) {
468 if (inet_ntop(AF_INET,
469 &lookup->results[i].dst.sin.sin_addr,
470 buf, sizeof(buf)) == NULL)
472 } else if (lookup->results[i].dst.sa.sa_family == AF_INET6) {
473 if (inet_ntop(AF_INET6,
474 &lookup->results[i].dst.sin6.sin6_addr,
475 buf, sizeof(buf)) == NULL)
480 results[n++] = strdup(buf);
485 status = lookup->ipv4_status;
487 if (status == G_RESOLV_RESULT_STATUS_SUCCESS)
488 status = lookup->ipv6_status;
490 lookup->result_func(status, results, lookup->result_data);
493 g_queue_remove(lookup->resolv->lookup_queue, lookup);
494 destroy_lookup(lookup);
497 static gboolean query_timeout(gpointer user_data)
499 struct resolv_query *query = user_data;
500 struct resolv_lookup *lookup = query->lookup;
501 GResolv *resolv = query->resolv;
505 if (query == lookup->ipv4_query) {
506 lookup->ipv4_status = G_RESOLV_RESULT_STATUS_NO_RESPONSE;
507 lookup->ipv4_query = NULL;
508 } else if (query == lookup->ipv6_query) {
509 lookup->ipv6_status = G_RESOLV_RESULT_STATUS_NO_RESPONSE;
510 lookup->ipv6_query = NULL;
513 if (lookup->ipv4_query == NULL && lookup->ipv4_query == NULL)
514 sort_and_return_results(lookup);
516 destroy_query(query);
517 g_queue_remove(resolv->query_queue, query);
522 static void free_nameserver(struct resolv_nameserver *nameserver)
524 if (nameserver == NULL)
527 if (nameserver->udp_watch > 0)
528 g_source_remove(nameserver->udp_watch);
530 if (nameserver->udp_channel != NULL)
531 g_io_channel_unref(nameserver->udp_channel);
533 g_free(nameserver->address);
537 static void flush_nameservers(GResolv *resolv)
541 for (list = g_list_first(resolv->nameserver_list);
542 list; list = g_list_next(list))
543 free_nameserver(list->data);
545 g_list_free(resolv->nameserver_list);
546 resolv->nameserver_list = NULL;
549 static int send_query(GResolv *resolv, const unsigned char *buf, int len)
553 if (resolv->nameserver_list == NULL)
556 for (list = g_list_first(resolv->nameserver_list);
557 list; list = g_list_next(list)) {
558 struct resolv_nameserver *nameserver = list->data;
561 if (nameserver->udp_channel == NULL)
564 sk = g_io_channel_unix_get_fd(nameserver->udp_channel);
566 sent = send(sk, buf, len, 0);
574 static gint compare_lookup_id(gconstpointer a, gconstpointer b)
576 const struct resolv_lookup *lookup = a;
577 guint id = GPOINTER_TO_UINT(b);
588 static gint compare_query_msgid(gconstpointer a, gconstpointer b)
590 const struct resolv_query *query = a;
591 uint16_t msgid = GPOINTER_TO_UINT(b);
593 if (query->msgid < msgid)
596 if (query->msgid > msgid)
602 static void add_result(struct resolv_lookup *lookup, int family,
605 int n = lookup->nr_results++;
606 lookup->results = g_realloc(lookup->results,
607 sizeof(struct sort_result) * (n + 1));
609 memset(&lookup->results[n], 0, sizeof(struct sort_result));
611 lookup->results[n].dst.sa.sa_family = family;
612 if (family == AF_INET)
613 memcpy(&lookup->results[n].dst.sin.sin_addr,
616 memcpy(&lookup->results[n].dst.sin6.sin6_addr,
620 static void parse_response(struct resolv_nameserver *nameserver,
621 const unsigned char *buf, int len)
623 GResolv *resolv = nameserver->resolv;
624 GResolvResultStatus status;
625 struct resolv_query *query;
626 struct resolv_lookup *lookup;
632 debug(resolv, "response from %s", nameserver->address);
634 ns_initparse(buf, len, &msg);
636 rcode = ns_msg_getflag(msg, ns_f_rcode);
637 count = ns_msg_count(msg, ns_s_an);
639 debug(resolv, "msg id: 0x%04x rcode: %d count: %d",
640 ns_msg_id(msg), rcode, count);
644 status = G_RESOLV_RESULT_STATUS_SUCCESS;
647 status = G_RESOLV_RESULT_STATUS_FORMAT_ERROR;
650 status = G_RESOLV_RESULT_STATUS_SERVER_FAILURE;
653 status = G_RESOLV_RESULT_STATUS_NAME_ERROR;
656 status = G_RESOLV_RESULT_STATUS_NOT_IMPLEMENTED;
659 status = G_RESOLV_RESULT_STATUS_REFUSED;
662 status = G_RESOLV_RESULT_STATUS_ERROR;
666 list = g_queue_find_custom(resolv->query_queue,
667 GUINT_TO_POINTER(ns_msg_id(msg)), compare_query_msgid);
672 lookup = query->lookup;
674 if (query == lookup->ipv6_query) {
675 lookup->ipv6_status = status;
676 lookup->ipv6_query = NULL;
677 } else if (query == lookup->ipv4_query) {
678 lookup->ipv4_status = status;
679 lookup->ipv4_query = NULL;
682 for (i = 0; i < count; i++) {
683 ns_parserr(&msg, ns_s_an, i, &rr);
685 if (ns_rr_class(rr) != ns_c_in)
688 g_assert(offsetof(struct sockaddr_in, sin_addr) ==
689 offsetof(struct sockaddr_in6, sin6_flowinfo));
691 if (ns_rr_type(rr) == ns_t_a &&
692 ns_rr_rdlen(rr) == NS_INADDRSZ) {
693 add_result(lookup, AF_INET, ns_rr_rdata(rr));
694 } else if (ns_rr_type(rr) == ns_t_aaaa &&
695 ns_rr_rdlen(rr) == NS_IN6ADDRSZ) {
696 add_result(lookup, AF_INET6, ns_rr_rdata(rr));
700 if (lookup->ipv4_query == NULL && lookup->ipv6_query == NULL)
701 sort_and_return_results(lookup);
703 destroy_query(query);
704 g_queue_remove(resolv->query_queue, query);
707 static gboolean received_udp_data(GIOChannel *channel, GIOCondition cond,
710 struct resolv_nameserver *nameserver = user_data;
711 unsigned char buf[4096];
714 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
715 nameserver->udp_watch = 0;
719 sk = g_io_channel_unix_get_fd(nameserver->udp_channel);
721 len = recv(sk, buf, sizeof(buf), 0);
725 parse_response(nameserver, buf, len);
730 static int connect_udp_channel(struct resolv_nameserver *nameserver)
732 struct addrinfo hints, *rp;
736 memset(&hints, 0, sizeof(hints));
737 hints.ai_family = AF_UNSPEC;
738 hints.ai_socktype = SOCK_DGRAM;
739 hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV | AI_NUMERICHOST;
741 sprintf(portnr, "%d", nameserver->port);
742 err = getaddrinfo(nameserver->address, portnr, &hints, &rp);
747 * Do not blindly copy this code elsewhere; it doesn't loop over the
748 * results using ->ai_next as it should. That's OK in *this* case
749 * because it was a numeric lookup; we *know* there's only one.
754 sk = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
760 if (connect(sk, rp->ai_addr, rp->ai_addrlen) < 0) {
768 nameserver->udp_channel = g_io_channel_unix_new(sk);
769 if (nameserver->udp_channel == NULL) {
774 g_io_channel_set_close_on_unref(nameserver->udp_channel, TRUE);
776 nameserver->udp_watch = g_io_add_watch(nameserver->udp_channel,
777 G_IO_IN | G_IO_NVAL | G_IO_ERR | G_IO_HUP,
778 received_udp_data, nameserver);
783 GResolv *g_resolv_new(int index)
790 resolv = g_try_new0(GResolv, 1);
794 resolv->ref_count = 1;
796 resolv->result_family = AF_UNSPEC;
798 resolv->next_lookup_id = 1;
800 resolv->query_queue = g_queue_new();
801 if (resolv->query_queue == NULL) {
806 resolv->lookup_queue = g_queue_new();
807 if (resolv->lookup_queue == NULL) {
808 g_queue_free(resolv->query_queue);
813 resolv->index = index;
814 resolv->nameserver_list = NULL;
816 res_ninit(&resolv->res);
821 GResolv *g_resolv_ref(GResolv *resolv)
826 g_atomic_int_inc(&resolv->ref_count);
831 void g_resolv_unref(GResolv *resolv)
833 struct resolv_query *query;
838 if (g_atomic_int_dec_and_test(&resolv->ref_count) == FALSE)
841 while ((query = g_queue_pop_head(resolv->query_queue)))
842 destroy_query(query);
844 g_queue_free(resolv->query_queue);
845 g_queue_free(resolv->lookup_queue);
847 flush_nameservers(resolv);
849 res_nclose(&resolv->res);
854 void g_resolv_set_debug(GResolv *resolv, GResolvDebugFunc func,
860 resolv->debug_func = func;
861 resolv->debug_data = user_data;
864 gboolean g_resolv_add_nameserver(GResolv *resolv, const char *address,
865 uint16_t port, unsigned long flags)
867 struct resolv_nameserver *nameserver;
872 nameserver = g_try_new0(struct resolv_nameserver, 1);
873 if (nameserver == NULL)
876 nameserver->address = g_strdup(address);
877 nameserver->port = port;
878 nameserver->flags = flags;
880 if (connect_udp_channel(nameserver) < 0) {
881 free_nameserver(nameserver);
885 nameserver->resolv = resolv;
887 resolv->nameserver_list = g_list_append(resolv->nameserver_list,
890 debug(resolv, "setting nameserver %s", address);
895 void g_resolv_flush_nameservers(GResolv *resolv)
900 flush_nameservers(resolv);
903 static gint add_query(struct resolv_lookup *lookup, const char *hostname, int type)
905 struct resolv_query *query = g_try_new0(struct resolv_query, 1);
906 unsigned char buf[4096];
912 len = res_mkquery(ns_o_query, hostname, ns_c_in, type,
913 NULL, 0, NULL, buf, sizeof(buf));
915 query->msgid = buf[0] << 8 | buf[1];
917 if (send_query(lookup->resolv, buf, len) < 0) {
922 query->resolv = lookup->resolv;
923 query->lookup = lookup;
925 g_queue_push_tail(lookup->resolv->query_queue, query);
927 query->timeout = g_timeout_add_seconds(5, query_timeout, query);
929 if (type == ns_t_aaaa)
930 lookup->ipv6_query = query;
932 lookup->ipv4_query = query;
937 guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname,
938 GResolvResultFunc func, gpointer user_data)
940 struct resolv_lookup *lookup;
942 debug(resolv, "lookup hostname %s", hostname);
947 if (resolv->nameserver_list == NULL) {
950 for (i = 0; i < resolv->res.nscount; i++) {
952 int family = resolv->res.nsaddr_list[i].sin_family;
953 void *sa_addr = &resolv->res.nsaddr_list[i].sin_addr;
955 if (family != AF_INET &&
956 resolv->res._u._ext.nsaddrs[i]) {
958 sa_addr = &resolv->res._u._ext.nsaddrs[i]->sin6_addr;
961 if (family != AF_INET && family != AF_INET6)
964 if (inet_ntop(family, sa_addr, buf, sizeof(buf)))
965 g_resolv_add_nameserver(resolv, buf, 53, 0);
968 if (resolv->nameserver_list == NULL)
969 g_resolv_add_nameserver(resolv, "127.0.0.1", 53, 0);
972 lookup = g_try_new0(struct resolv_lookup, 1);
976 lookup->resolv = resolv;
977 lookup->result_func = func;
978 lookup->result_data = user_data;
979 lookup->id = resolv->next_lookup_id++;
981 if (resolv->result_family != AF_INET6) {
982 if (add_query(lookup, hostname, ns_t_a)) {
988 if (resolv->result_family != AF_INET) {
989 if (add_query(lookup, hostname, ns_t_aaaa)) {
990 if (resolv->result_family != AF_INET6) {
991 destroy_query(lookup->ipv4_query);
992 g_queue_remove(resolv->query_queue,
1001 g_queue_push_tail(resolv->lookup_queue, lookup);
1005 gboolean g_resolv_cancel_lookup(GResolv *resolv, guint id)
1009 list = g_queue_find_custom(resolv->lookup_queue,
1010 GUINT_TO_POINTER(id), compare_lookup_id);
1015 destroy_lookup(list->data);
1016 g_queue_remove(resolv->query_queue, list->data);
1021 gboolean g_resolv_set_address_family(GResolv *resolv, int family)
1026 if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6)
1029 resolv->result_family = family;