|
|
1 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
1 | /* $Id: evdns.c,v 1.1 2007/11/01 15:46:43 root Exp $ */ |
2 | /* $Id: evdns.c,v 1.2 2007/11/01 17:29:19 root Exp $ */ |
2 | |
3 | |
3 | /* The original version of this module was written by Adam Langley; for |
4 | /* The original version of this module was written by Adam Langley; for |
4 | * a history of modifications, check out the subversion logs. |
5 | * a history of modifications, check out the subversion logs. |
5 | * |
6 | * |
6 | * When editing this module, try to keep it re-mergeable by Adam. Don't |
7 | * When editing this module, try to keep it re-mergeable by Adam. Don't |
… | |
… | |
92 | #include <ctype.h> |
93 | #include <ctype.h> |
93 | #include <stdio.h> |
94 | #include <stdio.h> |
94 | #include <stdarg.h> |
95 | #include <stdarg.h> |
95 | |
96 | |
96 | #include "evdns.h" |
97 | #include "evdns.h" |
97 | /*#include "log.h"*/ |
|
|
98 | #ifdef WIN32 |
98 | #ifdef WIN32 |
99 | #include <windows.h> |
99 | #include <windows.h> |
100 | #include <winsock2.h> |
100 | #include <winsock2.h> |
101 | #include <iphlpapi.h> |
101 | #include <iphlpapi.h> |
102 | #else |
102 | #else |
… | |
… | |
174 | char request_appended; /* true if the request pointer is data which follows this struct */ |
174 | char request_appended; /* true if the request pointer is data which follows this struct */ |
175 | char transmit_me; /* needs to be transmitted */ |
175 | char transmit_me; /* needs to be transmitted */ |
176 | }; |
176 | }; |
177 | |
177 | |
178 | #ifndef HAVE_STRUCT_IN6_ADDR |
178 | #ifndef HAVE_STRUCT_IN6_ADDR |
179 | struct in6_addr { |
179 | struct xin6_addr { |
180 | u8 s6_addr[16]; |
180 | u8 s6_addr[16]; |
181 | }; |
181 | }; |
182 | #endif |
182 | #endif |
183 | |
183 | |
184 | struct reply { |
184 | struct reply { |
… | |
… | |
189 | u32 addrcount; |
189 | u32 addrcount; |
190 | u32 addresses[MAX_ADDRS]; |
190 | u32 addresses[MAX_ADDRS]; |
191 | } a; |
191 | } a; |
192 | struct { |
192 | struct { |
193 | u32 addrcount; |
193 | u32 addrcount; |
194 | struct in6_addr addresses[MAX_ADDRS]; |
194 | struct xin6_addr addresses[MAX_ADDRS]; |
195 | } aaaa; |
195 | } aaaa; |
196 | struct { |
196 | struct { |
197 | char name[HOST_NAME_MAX]; |
197 | char name[HOST_NAME_MAX]; |
198 | } ptr; |
198 | } ptr; |
199 | } data; |
199 | } data; |
… | |
… | |
2264 | if (!req) return 1; |
2264 | if (!req) return 1; |
2265 | request_submit(req); |
2265 | request_submit(req); |
2266 | return 0; |
2266 | return 0; |
2267 | } |
2267 | } |
2268 | |
2268 | |
2269 | int evdns_resolve_reverse_ipv6(struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr) { |
2269 | int evdns_resolve_reverse_ipv6(struct xin6_addr *in, int flags, evdns_callback_type callback, void *ptr) { |
2270 | char buf[64]; |
2270 | char buf[64]; |
2271 | char *cp; |
2271 | char *cp; |
2272 | struct request *req; |
2272 | struct request *req; |
2273 | int i; |
2273 | int i; |
2274 | assert(in); |
2274 | assert(in); |
… | |
… | |
2543 | /* if the file isn't found then we assume a local resolver */ |
2543 | /* if the file isn't found then we assume a local resolver */ |
2544 | if (flags & DNS_OPTION_SEARCH) search_set_from_hostname(); |
2544 | if (flags & DNS_OPTION_SEARCH) search_set_from_hostname(); |
2545 | if (flags & DNS_OPTION_NAMESERVERS) evdns_nameserver_ip_add("127.0.0.1"); |
2545 | if (flags & DNS_OPTION_NAMESERVERS) evdns_nameserver_ip_add("127.0.0.1"); |
2546 | } |
2546 | } |
2547 | |
2547 | |
2548 | #ifndef HAVE_STRTOK_R |
|
|
2549 | static char * |
|
|
2550 | strtok_r(char *s, const char *delim, char **state) { |
|
|
2551 | return strtok(s, delim); |
|
|
2552 | } |
|
|
2553 | #endif |
|
|
2554 | |
2548 | |
2555 | /* helper version of atoi which returns -1 on error */ |
2549 | /* helper version of atoi which returns -1 on error */ |
2556 | static int |
2550 | static int |
2557 | strtoint(const char *const str) { |
2551 | strtoint(const char *const str) { |
2558 | char *endptr; |
2552 | char *endptr; |
… | |
… | |
2621 | |
2615 | |
2622 | static void |
2616 | static void |
2623 | resolv_conf_parse_line(char *const start, int flags) { |
2617 | resolv_conf_parse_line(char *const start, int flags) { |
2624 | char *strtok_state; |
2618 | char *strtok_state; |
2625 | static const char *const delims = " \t"; |
2619 | static const char *const delims = " \t"; |
2626 | #define NEXT_TOKEN strtok_r(NULL, delims, &strtok_state) |
2620 | #define NEXT_TOKEN strtok(NULL, delims, &strtok_state) |
2627 | |
2621 | |
2628 | char *const first_token = strtok_r(start, delims, &strtok_state); |
2622 | char *const first_token = strtok(start, delims, &strtok_state); |
2629 | if (!first_token) return; |
2623 | if (!first_token) return; |
2630 | |
2624 | |
2631 | if (!strcmp(first_token, "nameserver") && (flags & DNS_OPTION_NAMESERVERS)) { |
2625 | if (!strcmp(first_token, "nameserver") && (flags & DNS_OPTION_NAMESERVERS)) { |
2632 | const char *const nameserver = NEXT_TOKEN; |
2626 | const char *const nameserver = NEXT_TOKEN; |
2633 | struct in_addr ina; |
2627 | struct in_addr ina; |