1 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
1 | /* $Id: evdns.c,v 1.16 2007/11/06 16:09:37 root Exp $ */ |
2 | |
2 | |
3 | /* The original version of this module was written by Adam Langley; for |
3 | /* The original version of this module was written by Adam Langley; for |
4 | * a history of modifications, check out the subversion logs. |
4 | * a history of modifications, check out the subversion logs. |
5 | * |
5 | * |
6 | * When editing this module, try to keep it re-mergeable by Adam. Don't |
6 | * When editing this module, try to keep it re-mergeable by Adam. Don't |
… | |
… | |
38 | #ifdef HAVE_CONFIG_H |
38 | #ifdef HAVE_CONFIG_H |
39 | #include "config.h" |
39 | #include "config.h" |
40 | #endif |
40 | #endif |
41 | |
41 | |
42 | #ifdef WIN32 |
42 | #ifdef WIN32 |
|
|
43 | #ifndef EV_STANDALONE |
43 | #include "misc.h" |
44 | #include "misc.h" |
|
|
45 | #endif |
44 | #endif |
46 | #endif |
45 | |
47 | |
46 | /* #define NDEBUG */ |
48 | /* #define NDEBUG */ |
47 | |
49 | |
48 | #ifndef DNS_USE_CPU_CLOCK_FOR_ID |
50 | #ifndef DNS_USE_CPU_CLOCK_FOR_ID |
… | |
… | |
76 | |
78 | |
77 | #define _FORTIFY_SOURCE 3 |
79 | #define _FORTIFY_SOURCE 3 |
78 | |
80 | |
79 | #include <string.h> |
81 | #include <string.h> |
80 | #include <fcntl.h> |
82 | #include <fcntl.h> |
81 | #include <sys/time.h> |
|
|
82 | #ifdef HAVE_STDINT_H |
83 | #ifdef HAVE_STDINT_H |
83 | #include <stdint.h> |
84 | #include <stdint.h> |
84 | #endif |
85 | #endif |
85 | #include <stdlib.h> |
86 | #include <stdlib.h> |
86 | #include <string.h> |
87 | #include <string.h> |
87 | #include <errno.h> |
88 | #include <errno.h> |
88 | #include <assert.h> |
89 | #include <assert.h> |
89 | #include <unistd.h> |
|
|
90 | #include <limits.h> |
90 | #include <limits.h> |
91 | #include <sys/stat.h> |
91 | #include <sys/stat.h> |
92 | #include <ctype.h> |
92 | #include <ctype.h> |
93 | #include <stdio.h> |
93 | #include <stdio.h> |
94 | #include <stdarg.h> |
94 | #include <stdarg.h> |
… | |
… | |
173 | char request_appended; /* true if the request pointer is data which follows this struct */ |
173 | char request_appended; /* true if the request pointer is data which follows this struct */ |
174 | char transmit_me; /* needs to be transmitted */ |
174 | char transmit_me; /* needs to be transmitted */ |
175 | }; |
175 | }; |
176 | |
176 | |
177 | #ifndef HAVE_STRUCT_IN6_ADDR |
177 | #ifndef HAVE_STRUCT_IN6_ADDR |
178 | struct xin6_addr { |
178 | struct in6_addr { |
179 | u8 s6_addr[16]; |
179 | u8 s6_addr[16]; |
180 | }; |
180 | }; |
181 | #endif |
181 | #endif |
182 | |
182 | |
183 | struct reply { |
183 | struct reply { |
… | |
… | |
188 | u32 addrcount; |
188 | u32 addrcount; |
189 | u32 addresses[MAX_ADDRS]; |
189 | u32 addresses[MAX_ADDRS]; |
190 | } a; |
190 | } a; |
191 | struct { |
191 | struct { |
192 | u32 addrcount; |
192 | u32 addrcount; |
193 | struct xin6_addr addresses[MAX_ADDRS]; |
193 | struct in6_addr addresses[MAX_ADDRS]; |
194 | } aaaa; |
194 | } aaaa; |
195 | struct { |
195 | struct { |
196 | char name[HOST_NAME_MAX]; |
196 | char name[HOST_NAME_MAX]; |
197 | } ptr; |
197 | } ptr; |
198 | } data; |
198 | } data; |
… | |
… | |
2263 | if (!req) return 1; |
2263 | if (!req) return 1; |
2264 | request_submit(req); |
2264 | request_submit(req); |
2265 | return 0; |
2265 | return 0; |
2266 | } |
2266 | } |
2267 | |
2267 | |
2268 | int evdns_resolve_reverse_ipv6(struct xin6_addr *in, int flags, evdns_callback_type callback, void *ptr) { |
2268 | int evdns_resolve_reverse_ipv6(struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr) { |
2269 | char buf[96]; |
2269 | char buf[96]; |
2270 | char *cp; |
2270 | char *cp; |
2271 | struct request *req; |
2271 | struct request *req; |
2272 | int i; |
2272 | int i; |
2273 | assert(in); |
2273 | assert(in); |
… | |
… | |
2542 | /* if the file isn't found then we assume a local resolver */ |
2542 | /* if the file isn't found then we assume a local resolver */ |
2543 | if (flags & DNS_OPTION_SEARCH) search_set_from_hostname(); |
2543 | if (flags & DNS_OPTION_SEARCH) search_set_from_hostname(); |
2544 | if (flags & DNS_OPTION_NAMESERVERS) evdns_nameserver_ip_add("127.0.0.1"); |
2544 | if (flags & DNS_OPTION_NAMESERVERS) evdns_nameserver_ip_add("127.0.0.1"); |
2545 | } |
2545 | } |
2546 | |
2546 | |
|
|
2547 | #ifndef HAVE_STRTOK_R |
|
|
2548 | static char * |
|
|
2549 | strtok_r(char *s, const char *delim, char **state) { |
|
|
2550 | return strtok(s, delim); |
|
|
2551 | } |
|
|
2552 | #endif |
2547 | |
2553 | |
2548 | /* helper version of atoi which returns -1 on error */ |
2554 | /* helper version of atoi which returns -1 on error */ |
2549 | static int |
2555 | static int |
2550 | strtoint(const char *const str) { |
2556 | strtoint(const char *const str) { |
2551 | char *endptr; |
2557 | char *endptr; |
… | |
… | |
2614 | |
2620 | |
2615 | static void |
2621 | static void |
2616 | resolv_conf_parse_line(char *const start, int flags) { |
2622 | resolv_conf_parse_line(char *const start, int flags) { |
2617 | char *strtok_state; |
2623 | char *strtok_state; |
2618 | static const char *const delims = " \t"; |
2624 | static const char *const delims = " \t"; |
2619 | #define NEXT_TOKEN strtok(NULL, delims, &strtok_state) |
2625 | #define NEXT_TOKEN strtok_r(NULL, delims, &strtok_state) |
2620 | |
2626 | |
2621 | char *const first_token = strtok(start, delims, &strtok_state); |
2627 | char *const first_token = strtok_r(start, delims, &strtok_state); |
2622 | if (!first_token) return; |
2628 | if (!first_token) return; |
2623 | |
2629 | |
2624 | if (!strcmp(first_token, "nameserver") && (flags & DNS_OPTION_NAMESERVERS)) { |
2630 | if (!strcmp(first_token, "nameserver") && (flags & DNS_OPTION_NAMESERVERS)) { |
2625 | const char *const nameserver = NEXT_TOKEN; |
2631 | const char *const nameserver = NEXT_TOKEN; |
2626 | struct in_addr ina; |
2632 | struct in_addr ina; |