2 * A rewrite of Darren Reeds original res.c As there is nothing
3 * left of Darrens original code, this is now licensed by the hybrid group.
4 * (Well, some of the function names are the same, and bits of the structs..)
5 * You can use it where it is useful, free even. Buy us a beer and stuff.
7 * The authors takes no responsibility for any damage or loss
8 * of property which results from the use of this software.
10 * July 1999 - Rewrote a bunch of stuff here. Change hostent builder code,
11 * added callbacks and reference counting of returned hostents.
12 * --Bleep (Thomas Helvey <tomh@inxpress.net>)
14 * This was all needlessly complicated for irc. Simplified. No more hostent
15 * All we really care about is the IP -> hostname mappings. Thats all.
17 * Apr 28, 2003 --cryogen and Dianora
19 * DNS server flooding lessened, AAAA-or-A lookup removed, ip6.int support
20 * removed, various robustness fixes
22 * 2006 --jilles and nenolod
24 * Resend queries to other servers if the DNS server replies with an error or
25 * an invalid response. Also, avoid servers that return errors or invalid
28 * October 2012 --mr_flea
30 * ircd-ratbox changes for random IDs merged back in.
32 * January 2016 --kaniini
41 #error this code needs to be able to address individual octets
44 static PF res_readreply
;
46 #define MAXPACKET 1024 /* rfc sez 512 but we expand names so ... */
47 #define RES_MAXALIASES 35 /* maximum aliases allowed */
48 #define RES_MAXADDRS 35 /* maximum addresses allowed */
49 #define AR_TTL 600 /* TTL in seconds for dns cache entries */
51 /* RFC 1104/1105 wasn't very helpful about what these fields
52 * should be named, so for now, we'll just name them this way.
53 * we probably should look at what named calls them or something.
55 #define TYPE_SIZE (size_t)2
56 #define CLASS_SIZE (size_t)2
57 #define TTL_SIZE (size_t)4
58 #define RDLENGTH_SIZE (size_t)2
59 #define ANSWER_FIXED_SIZE (TYPE_SIZE + CLASS_SIZE + TTL_SIZE + RDLENGTH_SIZE)
62 struct in6_addr ipv6_addr
;
64 struct in_addr ipv4_addr
;
72 char queryname
[IRCD_RES_HOSTLEN
+ 1]; /* name currently being queried */
73 char retries
; /* retry counter */
74 char sends
; /* number of sends (>1 means resent) */
77 int lastns
; /* index of last server sent to */
78 struct rb_sockaddr_storage addr
;
80 struct DNSQuery
*query
; /* query callback for this request */
83 static rb_fde_t
*res_fd
;
84 static rb_dlink_list request_list
= { NULL
, NULL
, 0 };
85 static int ns_failure_count
[IRCD_MAXNS
]; /* timeouts and invalid/failed replies */
87 static void rem_request(struct reslist
*request
);
88 static struct reslist
*make_request(struct DNSQuery
*query
);
89 static void gethost_byname_type_fqdn(const char *name
, struct DNSQuery
*query
,
91 static void do_query_name(struct DNSQuery
*query
, const char *name
, struct reslist
*request
, int);
92 static void do_query_number(struct DNSQuery
*query
, const struct rb_sockaddr_storage
*,
93 struct reslist
*request
);
94 static void query_name(struct reslist
*request
);
95 static int send_res_msg(const char *buf
, int len
, int count
);
96 static void resend_query(struct reslist
*request
);
97 static int check_question(struct reslist
*request
, HEADER
* header
, char *buf
, char *eob
);
98 static int proc_answer(struct reslist
*request
, HEADER
* header
, char *, char *);
99 static struct reslist
*find_id(int id
);
100 static struct DNSReply
*make_dnsreply(struct reslist
*request
);
101 static int generate_random_port(void);
102 static uint16_t generate_random_id(void);
108 #define RES_MIN(a, b) ((a) < (b) ? (a) : (b))
111 random_socket(int family
)
117 struct rb_sockaddr_storage sockaddr
;
118 F
= rb_socket(family
, SOCK_DGRAM
, 0, "UDP resolver socket");
122 memset(&sockaddr
, 0, sizeof(sockaddr
));
124 SET_SS_FAMILY(&sockaddr
, family
);
127 if(family
== AF_INET6
)
129 struct sockaddr_in6
*in6
= (struct sockaddr_in6
*)&sockaddr
;
130 memcpy(&in6
->sin6_addr
, &ipv6_addr
, sizeof(struct in6_addr
));
131 len
= (rb_socklen_t
) sizeof(struct sockaddr_in6
);
136 struct sockaddr_in
*in
= (struct sockaddr_in
*)&sockaddr
;
137 in
->sin_addr
.s_addr
= ipv4_addr
.s_addr
;
138 len
= (rb_socklen_t
) sizeof(struct sockaddr_in
);
141 for(i
= 0; i
< 10; i
++)
143 nport
= htons(generate_random_port());
145 if(family
== AF_INET
)
146 ((struct sockaddr_in
*)&sockaddr
)->sin_port
= nport
;
149 ((struct sockaddr_in6
*)&sockaddr
)->sin6_port
= nport
;
152 if(bind(rb_get_fd(F
), (struct sockaddr
*)&sockaddr
, len
) == 0)
162 * looks up "inp" in irc_nsaddr_list[]
164 * server ID or -1 for not found
166 * paul vixie, 29may94
167 * revised for ircd, cryogen(stu) may03
168 * slightly modified for charybdis, mr_flea oct12
170 static int res_ourserver(const struct rb_sockaddr_storage
*inp
)
173 const struct sockaddr_in6
*v6
;
174 const struct sockaddr_in6
*v6in
= (const struct sockaddr_in6
*)inp
;
176 const struct sockaddr_in
*v4
;
177 const struct sockaddr_in
*v4in
= (const struct sockaddr_in
*)inp
;
180 for (ns
= 0; ns
< irc_nscount
; ns
++)
182 const struct rb_sockaddr_storage
*srv
= &irc_nsaddr_list
[ns
];
184 if (srv
->ss_family
!= inp
->ss_family
)
188 v6
= (const struct sockaddr_in6
*)srv
;
190 v4
= (const struct sockaddr_in
*)srv
;
192 /* could probably just memcmp(srv, inp, srv.ss_len) here
193 * but we'll err on the side of caution - stu
195 switch (srv
->ss_family
)
199 if (v6
->sin6_port
== v6in
->sin6_port
)
200 if ((memcmp(&v6
->sin6_addr
.s6_addr
, &v6in
->sin6_addr
.s6_addr
,
201 sizeof(struct in6_addr
)) == 0) ||
202 (memcmp(&v6
->sin6_addr
.s6_addr
, &in6addr_any
,
203 sizeof(struct in6_addr
)) == 0))
210 if (v4
->sin_port
== v4in
->sin_port
)
211 if ((v4
->sin_addr
.s_addr
== INADDR_ANY
)
212 || (v4
->sin_addr
.s_addr
== v4in
->sin_addr
.s_addr
))
226 * timeout_query_list - Remove queries from the list which have been
227 * there too long without being resolved.
229 static time_t timeout_query_list(time_t now
)
232 rb_dlink_node
*next_ptr
;
233 struct reslist
*request
;
234 time_t next_time
= 0;
237 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, request_list
.head
)
240 timeout
= request
->sentat
+ request
->timeout
;
244 ns_failure_count
[request
->lastns
]++;
245 request
->sentat
= now
;
246 request
->timeout
+= request
->timeout
;
247 resend_query(request
);
250 if ((next_time
== 0) || timeout
< next_time
)
256 return (next_time
> now
) ? next_time
: (now
+ AR_TTL
);
260 * timeout_resolver - check request list
262 static void timeout_resolver(void *notused
)
264 timeout_query_list(rb_current_time());
267 static struct ev_entry
*timeout_resolver_ev
= NULL
;
270 * start_resolver - do everything we need to read the resolv.conf file
271 * and initialize the resolver file descriptor if needed
273 static void start_resolver(void)
278 for (i
= 0; i
< irc_nscount
; i
++)
279 ns_failure_count
[i
] = 0;
283 if ((res_fd
= rb_socket(irc_nsaddr_list
[0].ss_family
, SOCK_DGRAM
, 0,
284 "UDP resolver socket")) == NULL
)
287 /* At the moment, the resolver FD data is global .. */
288 rb_setselect(res_fd
, RB_SELECT_READ
, res_readreply
, NULL
);
289 timeout_resolver_ev
= rb_event_add("timeout_resolver", timeout_resolver
, NULL
, 1);
294 * init_resolver - initialize resolver and resolver library
296 void init_resolver(void)
299 srand48(rb_current_time());
305 * restart_resolver - reread resolv.conf, reopen socket
307 void restart_resolver(void)
311 rb_event_delete(timeout_resolver_ev
); /* -ddosen */
316 * add_local_domain - Add the domain to hostname, if it is missing
317 * (as suggested by eps@TOASTER.SFSU.EDU)
319 void add_local_domain(char *hname
, size_t size
)
321 /* try to fix up unqualified names */
322 if (strchr(hname
, '.') == NULL
)
326 size_t len
= strlen(hname
);
328 if ((strlen(irc_domain
) + len
+ 2) < size
)
331 strcpy(hname
+ len
, irc_domain
);
338 * rem_request - remove a request from the list.
339 * This must also free any memory that has been allocated for
340 * temporary storage of DNS results.
342 static void rem_request(struct reslist
*request
)
344 rb_dlinkDelete(&request
->node
, &request_list
);
345 rb_free(request
->name
);
350 * make_request - Create a DNS request record for the server.
352 static struct reslist
*make_request(struct DNSQuery
*query
)
354 struct reslist
*request
= rb_malloc(sizeof(struct reslist
));
356 request
->sentat
= rb_current_time();
357 request
->retries
= 3;
358 request
->timeout
= 4; /* start at 4 and exponential inc. */
359 request
->query
= query
;
362 * generate a unique id
363 * NOTE: we don't have to worry about converting this to and from
364 * network byte order, the nameserver does not interpret this value
365 * and returns it unchanged
367 * we generate an id per request now (instead of per send) to allow
368 * late replies to be used.
370 request
->id
= generate_random_id();
372 rb_dlinkAdd(request
, &request
->node
, &request_list
);
378 * retryfreq - determine how many queries to wait before resending
379 * if there have been that many consecutive timeouts
381 static int retryfreq(int timeouts
)
399 * send_res_msg - sends msg to a nameserver.
400 * This should reflect /etc/resolv.conf.
401 * Returns number of nameserver successfully sent to
402 * or -1 if no successful sends.
404 static int send_res_msg(const char *msg
, int len
, int rcount
)
411 /* First try a nameserver that seems to work.
412 * Every once in a while, try a possibly broken one to check
413 * if it is working again.
415 for (i
= 0; i
< irc_nscount
; i
++)
417 ns
= (i
+ rcount
- 1) % irc_nscount
;
418 if (ns_failure_count
[ns
] && retrycnt
% retryfreq(ns_failure_count
[ns
]))
420 if (sendto(rb_get_fd(res_fd
), msg
, len
, 0,
421 (struct sockaddr
*)&(irc_nsaddr_list
[ns
]),
422 GET_SS_LEN(&irc_nsaddr_list
[ns
])) == len
)
426 /* No known working nameservers, try some broken one. */
427 for (i
= 0; i
< irc_nscount
; i
++)
429 ns
= (i
+ rcount
- 1) % irc_nscount
;
430 if (!ns_failure_count
[ns
])
432 if (sendto(rb_get_fd(res_fd
), msg
, len
, 0,
433 (struct sockaddr
*)&(irc_nsaddr_list
[ns
]),
434 GET_SS_LEN(&irc_nsaddr_list
[ns
])) == len
)
442 * find_id - find a dns request id (id is determined by dn_mkquery)
444 static struct reslist
*find_id(int id
)
447 struct reslist
*request
;
449 RB_DLINK_FOREACH(ptr
, request_list
.head
)
453 if (request
->id
== id
)
461 generate_random_id(void)
467 rb_get_random(&id
, sizeof(id
));
476 generate_random_port(void)
482 rb_get_random(&port
, sizeof(port
));
490 * gethost_byname_type - get host address from name, adding domain if needed
492 void gethost_byname_type(const char *name
, struct DNSQuery
*query
, int type
)
494 char fqdn
[IRCD_RES_HOSTLEN
+ 1];
497 rb_strlcpy(fqdn
, name
, sizeof fqdn
);
498 add_local_domain(fqdn
, IRCD_RES_HOSTLEN
);
499 gethost_byname_type_fqdn(fqdn
, query
, type
);
503 * gethost_byname_type_fqdn - get host address from fqdn
505 static void gethost_byname_type_fqdn(const char *name
, struct DNSQuery
*query
,
509 do_query_name(query
, name
, NULL
, type
);
513 * gethost_byaddr - get host name from address
515 void gethost_byaddr(const struct rb_sockaddr_storage
*addr
, struct DNSQuery
*query
)
517 do_query_number(query
, addr
, NULL
);
521 * do_query_name - nameserver lookup name
523 static void do_query_name(struct DNSQuery
*query
, const char *name
, struct reslist
*request
,
528 request
= make_request(query
);
529 request
->name
= rb_strdup(name
);
532 rb_strlcpy(request
->queryname
, name
, sizeof(request
->queryname
));
533 request
->type
= type
;
538 * do_query_number - Use this to do reverse IP# lookups.
540 static void do_query_number(struct DNSQuery
*query
, const struct rb_sockaddr_storage
*addr
,
541 struct reslist
*request
)
543 const unsigned char *cp
;
547 request
= make_request(query
);
548 memcpy(&request
->addr
, addr
, sizeof(struct rb_sockaddr_storage
));
549 request
->name
= (char *)rb_malloc(IRCD_RES_HOSTLEN
+ 1);
552 if (addr
->ss_family
== AF_INET
)
554 const struct sockaddr_in
*v4
= (const struct sockaddr_in
*)addr
;
555 cp
= (const unsigned char *)&v4
->sin_addr
.s_addr
;
557 sprintf(request
->queryname
, "%u.%u.%u.%u.in-addr.arpa", (unsigned int)(cp
[3]),
558 (unsigned int)(cp
[2]), (unsigned int)(cp
[1]), (unsigned int)(cp
[0]));
561 else if (addr
->ss_family
== AF_INET6
)
563 const struct sockaddr_in6
*v6
= (const struct sockaddr_in6
*)addr
;
564 cp
= (const unsigned char *)&v6
->sin6_addr
.s6_addr
;
566 (void)sprintf(request
->queryname
, "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
567 "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa",
568 (unsigned int)(cp
[15] & 0xf), (unsigned int)(cp
[15] >> 4),
569 (unsigned int)(cp
[14] & 0xf), (unsigned int)(cp
[14] >> 4),
570 (unsigned int)(cp
[13] & 0xf), (unsigned int)(cp
[13] >> 4),
571 (unsigned int)(cp
[12] & 0xf), (unsigned int)(cp
[12] >> 4),
572 (unsigned int)(cp
[11] & 0xf), (unsigned int)(cp
[11] >> 4),
573 (unsigned int)(cp
[10] & 0xf), (unsigned int)(cp
[10] >> 4),
574 (unsigned int)(cp
[9] & 0xf), (unsigned int)(cp
[9] >> 4),
575 (unsigned int)(cp
[8] & 0xf), (unsigned int)(cp
[8] >> 4),
576 (unsigned int)(cp
[7] & 0xf), (unsigned int)(cp
[7] >> 4),
577 (unsigned int)(cp
[6] & 0xf), (unsigned int)(cp
[6] >> 4),
578 (unsigned int)(cp
[5] & 0xf), (unsigned int)(cp
[5] >> 4),
579 (unsigned int)(cp
[4] & 0xf), (unsigned int)(cp
[4] >> 4),
580 (unsigned int)(cp
[3] & 0xf), (unsigned int)(cp
[3] >> 4),
581 (unsigned int)(cp
[2] & 0xf), (unsigned int)(cp
[2] >> 4),
582 (unsigned int)(cp
[1] & 0xf), (unsigned int)(cp
[1] >> 4),
583 (unsigned int)(cp
[0] & 0xf), (unsigned int)(cp
[0] >> 4));
587 request
->type
= T_PTR
;
592 * query_name - generate a query based on class, type and name.
594 static void query_name(struct reslist
*request
)
600 memset(buf
, 0, sizeof(buf
));
603 irc_res_mkquery(request
->queryname
, C_IN
, request
->type
, (unsigned char *)buf
, sizeof(buf
))) > 0)
605 HEADER
*header
= (HEADER
*)(void *)buf
;
606 header
->id
= request
->id
;
609 ns
= send_res_msg(buf
, request_len
, request
->sends
);
611 request
->lastns
= ns
;
615 static void resend_query(struct reslist
*request
)
617 if (--request
->retries
<= 0)
619 (*request
->query
->callback
) (request
->query
->ptr
, NULL
);
620 rem_request(request
);
624 switch (request
->type
)
627 do_query_number(NULL
, &request
->addr
, request
);
633 do_query_name(NULL
, request
->name
, request
, request
->type
);
641 * check_question - check if the reply really belongs to the
642 * name we queried (to guard against late replies from previous
643 * queries with the same id).
645 static int check_question(struct reslist
*request
, HEADER
* header
, char *buf
, char *eob
)
647 char hostbuf
[IRCD_RES_HOSTLEN
+ 1]; /* working buffer */
648 unsigned char *current
; /* current position in buf */
649 int n
; /* temp count */
651 current
= (unsigned char *)buf
+ sizeof(HEADER
);
652 if (header
->qdcount
!= 1)
654 n
= irc_dn_expand((unsigned char *)buf
, (unsigned char *)eob
, current
, hostbuf
,
658 if (strcasecmp(hostbuf
, request
->queryname
))
664 * proc_answer - process name server reply
666 static int proc_answer(struct reslist
*request
, HEADER
* header
, char *buf
, char *eob
)
668 char hostbuf
[IRCD_RES_HOSTLEN
+ 100]; /* working buffer */
669 unsigned char *current
; /* current position in buf */
670 int type
; /* answer type */
671 int n
; /* temp count */
673 struct sockaddr_in
*v4
; /* conversion */
675 struct sockaddr_in6
*v6
;
677 current
= (unsigned char *)buf
+ sizeof(HEADER
);
679 for (; header
->qdcount
> 0; --header
->qdcount
)
681 if ((n
= irc_dn_skipname(current
, (unsigned char *)eob
)) < 0)
684 current
+= (size_t) n
+ QFIXEDSZ
;
688 * process each answer sent to us blech.
690 while (header
->ancount
> 0 && (char *)current
< eob
)
694 n
= irc_dn_expand((unsigned char *)buf
, (unsigned char *)eob
, current
, hostbuf
,
707 * no more answers left
712 hostbuf
[IRCD_RES_HOSTLEN
] = '\0';
714 /* With Address arithmetic you have to be very anal
715 * this code was not working on alpha due to that
716 * (spotted by rodder/jailbird/dianora)
718 current
+= (size_t) n
;
720 if (!(((char *)current
+ ANSWER_FIXED_SIZE
) < eob
))
723 type
= irc_ns_get16(current
);
724 current
+= TYPE_SIZE
;
726 (void) irc_ns_get16(current
);
727 current
+= CLASS_SIZE
;
729 request
->ttl
= irc_ns_get32(current
);
732 rd_length
= irc_ns_get16(current
);
733 current
+= RDLENGTH_SIZE
;
736 * Wait to set request->type until we verify this structure
741 if (request
->type
!= T_A
)
745 * check for invalid rd_length or too many addresses
747 if (rd_length
!= sizeof(struct in_addr
))
749 v4
= (struct sockaddr_in
*)&request
->addr
;
750 SET_SS_LEN(&request
->addr
, sizeof(struct sockaddr_in
));
751 v4
->sin_family
= AF_INET
;
752 memcpy(&v4
->sin_addr
, current
, sizeof(struct in_addr
));
757 if (request
->type
!= T_AAAA
)
759 if (rd_length
!= sizeof(struct in6_addr
))
761 SET_SS_LEN(&request
->addr
, sizeof(struct sockaddr_in6
));
762 v6
= (struct sockaddr_in6
*)&request
->addr
;
763 v6
->sin6_family
= AF_INET6
;
764 memcpy(&v6
->sin6_addr
, current
, sizeof(struct in6_addr
));
769 if (request
->type
!= T_PTR
)
771 n
= irc_dn_expand((unsigned char *)buf
, (unsigned char *)eob
, current
,
772 hostbuf
, sizeof(hostbuf
));
774 return (0); /* broken message */
776 return (0); /* no more answers left */
778 rb_strlcpy(request
->name
, hostbuf
, IRCD_RES_HOSTLEN
+ 1);
783 /* real answer will follow */
784 current
+= rd_length
;
796 * res_read_single_reply - read a dns reply from the nameserver and process it.
797 * Return value: 1 if a packet was read, 0 otherwise
799 static int res_read_single_reply(rb_fde_t
*F
, void *data
)
801 char buf
[sizeof(HEADER
) + MAXPACKET
]
802 /* Sparc and alpha need 16bit-alignment for accessing header->id
803 * (which is uint16_t). Because of the header = (HEADER*) buf;
804 * lateron, this is neeeded. --FaUl
806 #if defined(__sparc__) || defined(__alpha__)
807 __attribute__ ((aligned(16)))
811 struct reslist
*request
= NULL
;
812 struct DNSReply
*reply
= NULL
;
815 socklen_t len
= sizeof(struct rb_sockaddr_storage
);
816 struct rb_sockaddr_storage lsin
;
819 rc
= recvfrom(rb_get_fd(F
), buf
, sizeof(buf
), 0, (struct sockaddr
*)&lsin
, &len
);
822 if (rc
== 0 || rc
== -1)
826 if (rc
<= (int)(sizeof(HEADER
)))
830 * convert DNS reply reader from Network byte order to CPU byte order.
832 header
= (HEADER
*)(void *)buf
;
833 header
->ancount
= ntohs(header
->ancount
);
834 header
->qdcount
= ntohs(header
->qdcount
);
835 header
->nscount
= ntohs(header
->nscount
);
836 header
->arcount
= ntohs(header
->arcount
);
839 * response for an id which we have already received an answer for
840 * just ignore this response.
842 if (0 == (request
= find_id(header
->id
)))
846 * check against possibly fake replies
848 ns
= res_ourserver(&lsin
);
852 if (ns
!= request
->lastns
)
855 * We'll accept the late reply, but penalize it a little more to make
856 * sure a laggy server doesn't end up favored.
858 ns_failure_count
[ns
] += 3;
862 if (!check_question(request
, header
, buf
, buf
+ rc
))
865 if ((header
->rcode
!= NO_ERRORS
) || (header
->ancount
== 0))
868 * RFC 2136 states that in the event of a server returning SERVFAIL
869 * or NOTIMP, the request should be resent to the next server.
870 * Additionally, if the server refuses our query, resend it as well.
873 if (SERVFAIL
== header
->rcode
|| NOTIMP
== header
->rcode
||
874 REFUSED
== header
->rcode
)
876 ns_failure_count
[ns
]++;
877 resend_query(request
);
882 * Either a fatal error was returned or no answer. Cancel the
885 if (NXDOMAIN
== header
->rcode
)
887 /* If the rcode is NXDOMAIN, treat it as a good response. */
888 ns_failure_count
[ns
] /= 4;
890 (*request
->query
->callback
) (request
->query
->ptr
, NULL
);
891 rem_request(request
);
896 * If this fails there was an error decoding the received packet.
899 answer_count
= proc_answer(request
, header
, buf
, buf
+ rc
);
903 if (request
->type
== T_PTR
)
905 if (request
->name
== NULL
)
908 * Got a PTR response with no name, something strange is
909 * happening. Try another DNS server.
911 ns_failure_count
[ns
]++;
912 resend_query(request
);
917 * Lookup the 'authoritative' name that we were given for the
921 if (request
->addr
.ss_family
== AF_INET6
)
922 gethost_byname_type_fqdn(request
->name
, request
->query
, T_AAAA
);
925 gethost_byname_type_fqdn(request
->name
, request
->query
, T_A
);
926 rem_request(request
);
931 * got a name and address response, client resolved
933 reply
= make_dnsreply(request
);
934 (*request
->query
->callback
) (request
->query
->ptr
, reply
);
936 rem_request(request
);
939 ns_failure_count
[ns
] /= 4;
943 /* Invalid or corrupt reply - try another resolver. */
944 ns_failure_count
[ns
]++;
945 resend_query(request
);
951 res_readreply(rb_fde_t
*F
, void *data
)
953 while (res_read_single_reply(F
, data
))
955 rb_setselect(F
, RB_SELECT_READ
, res_readreply
, NULL
);
958 static struct DNSReply
*
959 make_dnsreply(struct reslist
*request
)
962 lrb_assert(request
!= 0);
964 cp
= (struct DNSReply
*)rb_malloc(sizeof(struct DNSReply
));
966 cp
->h_name
= request
->name
;
967 memcpy(&cp
->addr
, &request
->addr
, sizeof(cp
->addr
));