1 --- libevent-1.4.14b-stable/evdns.3 st lis 25 07:55:34 2009
2 +++ libevent-1.4.14b-stable/evdns.3 po lis 21 09:31:22 2011
4 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5 .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13 -.Nm evdns_err_to_string
14 -.Nm evdns_nameserver_add
15 -.Nm evdns_count_nameservers
16 -.Nm evdns_clear_nameservers_and_suspend
18 -.Nm evdns_nameserver_ip_add
19 -.Nm evdns_resolve_ipv4
20 -.Nm evdns_resolve_reverse
21 -.Nm evdns_resolv_conf_parse
22 -.Nm evdns_config_windows_nameservers
23 -.Nm evdns_search_clear
25 -.Nm evdns_search_ndots_set
27 -.Nd asynchronous functions for DNS resolution.
29 -.Fd #include <sys/time.h>
30 -.Fd #include <event.h>
31 -.Fd #include <evdns.h>
35 -.Fn evdns_shutdown "int fail_requests"
37 -.Fn evdns_err_to_string "int err"
39 -.Fn evdns_nameserver_add "unsigned long int address"
41 -.Fn evdns_count_nameservers
43 -.Fn evdns_clear_nameservers_and_suspend
47 -.Fn evdns_nameserver_ip_add(const char *ip_as_string);
49 -.Fn evdns_resolve_ipv4 "const char *name" "int flags" "evdns_callback_type callback" "void *ptr"
51 -.Fn evdns_resolve_reverse "struct in_addr *in" "int flags" "evdns_callback_type callback" "void *ptr"
53 -.Fn evdns_resolv_conf_parse "int flags" "const char *"
55 -.Fn evdns_search_clear
57 -.Fn evdns_search_add "const char *domain"
59 -.Fn evdns_search_ndots_set "const int ndots"
61 -.Fn evdns_set_log_fn "evdns_debug_log_fn_type fn"
63 -.Fn evdns_config_windows_nameservers
65 +.TH EVDNS 3 "21 November 2011" "libevent 1.4.14b" "libevent Manual"
70 +evdns_nameserver_add,
71 +evdns_count_nameservers,
72 +evdns_clear_nameservers_and_suspend,
74 +evdns_nameserver_ip_add,
76 +evdns_resolve_reverse,
77 +evdns_resolv_conf_parse,
78 +evdns_config_windows_nameservers,
81 +evdns_search_ndots_set,
83 +\- asynchronous functions for DNS resolution.
87 +\fB#include <sys/time.h>\fP
88 +\fB#include <event.h>\fP
89 +\fB#include <evdns.h>\fP
91 +\fBinit \fBevdns_init\fR\fR(\fBvoid\fP\fR);
93 +\fBvoid \fBevdns_shutdown\fR\fR(\fBint \fIfail_requests\fP\fR);
95 +\fBconst char* \fBevdns_err_to_string\fR\fR(\fBint \fIerr\fP\fR);
97 +\fBint \fBevdns_nameserver_add\fR\fR(\fBunsigned long int \fIaddress\fP\fR);
99 +\fBint \fBevdns_count_nameservers\fR\fR(\fBvoid\fP\fR);
101 +\fBint \fBevdns_clear_nameservers_and_suspend\fR\fR(\fBvoid\fP\fR);
103 +\fBint \fBevdns_resume\fR\fR(\fBvoid\fP\fR);
105 +\fBint \fBevdns_nameserver_ip_add\fR\fR(\fBconst char* \fIip_as_string\fP\fR);
107 +\fBint \fBevdns_resolve_ipv4\fR\fR(\fBconst char* \fIname\fP\fR, \fBint \fIflags\fP\fR, \fBevdns_callback_type \fIcallback\fP\fR, \fBvoid* \fIptr\fP\fR);
109 +\fBint \fBevdns_resolve_reverse\fR\fR(\fBstruct in_addr* \fIin\fP\fR, \fBint \fIflags\fP\fR, \fBevdns_callback_type \fIcallback\fP\fR, \fBvoid* \fIptr\fP\fR);
111 +\fBint \fBevdns_resolv_conf_parse\fR\fR(\fBint \fIflags\fP\fR, \fBconst char* \fIfilename\fP\fR);
113 +\fBvoid \fBevdns_search_clear\fR\fR(\fBvoid\fP\fR);
115 +\fBvoid \fBevdns_search_add\fR\fR(\fBconst char* \fIdomain\fP\fR);
117 +\fBvoid \fBevdns_search_ndots_set\fR\fR(\fBconst int \fIndots\fP\fR);
119 +\fBvoid \fBevdns_set_log_fn\fR\fR(\fBcevdns_debug_log_fn_type \fIfn\fP\fR);
121 +\fBint \fBevdns_config_windows_nameservers\fR\fR(\fBvoid\fP\fR);
124 Welcome, gentle reader
127 Async DNS lookups are really a whole lot harder than they should be,
128 mostly stemming from the fact that the libc resolver has never been
129 very good at them. Before you use this library you should see if libc
131 can do the job for you with the modern async call getaddrinfo_a
132 (see http://www.imperialviolet.org/page25.html#e498). Otherwise,
136 This code is based on libevent and you must call event_init before
137 any of the APIs in this file. You must also seed the OpenSSL random
138 source if you are using OpenSSL for ids (see below).
141 This library is designed to be included and shipped with your source
142 code. You statically link with it. You should also test for the
143 existence of strtok_r and define HAVE_STRTOK_R if you have it.
146 The DNS protocol requires a good source of id numbers and these
147 numbers should be unpredictable for spoofing reasons. There are
148 three methods for generating them here and you must define exactly
149 one of them. In increasing order of preference:
151 -.Bl -tag -width "DNS_USE_GETTIMEOFDAY_FOR_ID" -compact -offset indent
152 -.It DNS_USE_GETTIMEOFDAY_FOR_ID
154 +DNS_USE_GETTIMEOFDAY_FOR_ID
158 Using the bottom 16 bits of the usec result from gettimeofday. This
159 is a pretty poor solution but should work anywhere.
160 -.It DNS_USE_CPU_CLOCK_FOR_ID
163 +DNS_USE_CPU_CLOCK_FOR_ID
167 Using the bottom 16 bits of the nsec result from the CPU's time
168 counter. This is better, but may not work everywhere. Requires
169 POSIX realtime support and you'll need to link against -lrt on
170 glibc systems at least.
171 -.It DNS_USE_OPENSSL_FOR_ID
174 +DNS_USE_OPENSSL_FOR_ID
178 Uses the OpenSSL RAND_bytes call to generate the data. You must
179 have seeded the pool before making any calls to this library.
184 The library keeps track of the state of nameservers and will avoid
185 them when they go down. Otherwise it will round robin between them.
190 void callback(int result, char type, int count, int ttl,
192 void *addresses, void *arg);
193 evdns_resolv_conf_parse(DNS_OPTIONS_ALL, "/etc/resolv.conf");
194 evdns_resolve("www.hostname.com", 0, callback, NULL);
197 When the lookup is complete the callback function is called. The
198 first argument will be one of the DNS_ERR_* defines in evdns.h.
199 Hopefully it will be DNS_ERR_NONE, in which case type will be
200 @@ -136,152 +149,187 @@
201 which the data can be cached for (in seconds), addresses will point
202 to an array of uint32_t's and arg will be whatever you passed to
209 In order for this library to be a good replacement for glibc's resolver it
210 supports searching. This involves setting a list of default domains, in
211 which names will be queried for. The number of dots in the query name
212 determines the order in which this list is used.
215 Searching appears to be a single lookup from the point of view of the API,
216 although many DNS queries may be generated from a single call to
217 evdns_resolve. Searching can also drastically slow down the resolution
221 To disable searching:
222 -.Bl -enum -compact -offset indent
224 -Never set it up. If you never call
225 -.Fn evdns_resolv_conf_parse,
230 +1. Never set it up. If you never call
231 +\fBevdns_resolv_conf_parse\fP\fR,
232 +\fBevdns_init\fP\fR,
234 -.Fn evdns_search_add
235 +\fBevdns_search_add\fP\R
236 then no searching will occur.
239 -.Fn evdns_resolv_conf_parse
242 +\fBevdns_resolv_conf_parse\fP\fR
244 -.Va DNS_OPTION_SEARCH
247 -.Va DNS_OPTIONS_ALL,
255 +\fBevdns_resolve\fP\fR,
257 -.Va DNS_QUERY_NO_SEARCH
264 The order of searches depends on the number of dots in the name. If the
265 number is greater than the ndots setting then the names is first tried
266 globally. Otherwise each search domain is appended in turn.
269 The ndots setting can either be set from a resolv.conf, or by calling
270 evdns_search_ndots_set.
273 For example, with ndots set to 1 (the default) and a search domain list of
276 Order: www.myhome.net, www.
280 Order: www.abc., www.abc.myhome.net
284 -.Bl -tag -width 0123456
285 -.It Ft int Fn evdns_init
289 +.SS "\fBint \fBevdns_init\fR\fR(\fBvoid\fP\fR)"
292 Initializes support for non-blocking name resolution by calling
293 -.Fn evdns_resolv_conf_parse
294 +evdns_resolv_conf_parse()
296 -.Fn evdns_config_windows_nameservers
297 +evdns_config_windows_nameservers()
299 -.It Ft int Fn evdns_nameserver_add "unsigned long int address"
300 +.SS "\fBint \fBevdns_nameserver_add\fR\fR(\fBunsigned long int\fP\fR \fIaddress\fP\fR)"
303 Add a nameserver. The address should be an IP address in
304 network byte order. The type of address is chosen so that
305 it matches in_addr.s_addr.
306 Returns non-zero on error.
307 -.It Ft int Fn evdns_nameserver_ip_add "const char *ip_as_string"
308 +.SS "\fBint \fBevdns_nameserver_ip_add\fR\fR(\fBconst char* \fIip_as_string\fP\fR)"
311 This wraps the above function by parsing a string as an IP
312 address and adds it as a nameserver.
313 Returns non-zero on error
314 -.It Ft int Fn evdns_resolve "const char *name" "int flags" "evdns_callback_type callback" "void *ptr"
315 +.SS "\fBint \fBevdns_resolve\fR\fR(\fBconst char* \fIname\fP\fR, \fBint \fIflags\fP\fR, \fBevdns_callback_type \fIcallback\fP\fR, \fBvoid* \fIptr\fP\fR)"
318 Resolve a name. The name parameter should be a DNS name.
319 The flags parameter should be 0, or DNS_QUERY_NO_SEARCH
320 which disables searching for this query. (see defn of
324 The callback argument is a function which is called when
325 this query completes and ptr is an argument which is passed
326 to that callback function.
329 Returns non-zero on error
330 -.It Ft void Fn evdns_search_clear
331 +.SS "\fBvoid \fBevdns_search_clear\fR\fR(\fBvoid\fP\fR)"
334 Clears the list of search domains
335 -.It Ft void Fn evdns_search_add "const char *domain"
336 +.SS "\fBvoid \fBevdns_search_add\fR\fR(\fBconst char* \fIdomain\fP\fR)"
339 Add a domain to the list of search domains
340 -.It Ft void Fn evdns_search_ndots_set "int ndots"
341 +.SS "\fBvoid \fBevdns_search_ndots_set\fR\fR(\fBconst int \fIndots\fP\fR)"
344 Set the number of dots which, when found in a name, causes
345 the first query to be without any search domain.
346 -.It Ft int Fn evdns_count_nameservers "void"
347 +.SS "\fBint \fBevdns_count_nameservers\fR\fR(\fBvoid\fP\fR)"
350 Return the number of configured nameservers (not necessarily the
351 number of running nameservers). This is useful for double-checking
352 whether our calls to the various nameserver configuration functions
353 have been successful.
354 -.It Ft int Fn evdns_clear_nameservers_and_suspend "void"
355 +.SS "\fBint \fBevdns_clear_nameservers_and_suspend\fR\fR(\fBvoid\fP\fR)"
358 Remove all currently configured nameservers, and suspend all pending
359 resolves. Resolves will not necessarily be re-attempted until
360 evdns_resume() is called.
361 -.It Ft int Fn evdns_resume "void"
362 +.SS "\fBint \fBevdns_resume\fR\fR(\fBvoid\fP\fR)"
365 Re-attempt resolves left in limbo after an earlier call to
366 evdns_clear_nameservers_and_suspend().
367 -.It Ft int Fn evdns_config_windows_nameservers "void"
368 +.SS "\fBint \fBevdns_config_windows_nameservers\fR\fR(\fBvoid\fP\fR)"
371 Attempt to configure a set of nameservers based on platform settings on
372 a win32 host. Preferentially tries to use GetNetworkParams; if that fails,
373 looks in the registry. Returns 0 on success, nonzero on failure.
374 -.It Ft int Fn evdns_resolv_conf_parse "int flags" "const char *filename"
375 +.SS "\fBint \fBevdns_resolv_conf_parse\fR\fR(\fBint \fIflags\fP\fR, \fBconst char*filename\fP\fR)"
378 Parse a resolv.conf like file from the given filename.
381 See the man page for resolv.conf for the format of this file.
382 The flags argument determines what information is parsed from
384 -.Bl -tag -width "DNS_OPTION_NAMESERVERS" -offset indent -compact -nested
385 -.It DNS_OPTION_SEARCH
388 domain, search and ndots options
389 -.It DNS_OPTION_NAMESERVERS
391 +DNS_OPTION_NAMESERVERS
396 timeout and attempts options
404 The following directives are not parsed from the file:
405 sortlist, rotate, no-check-names, inet6, debug
408 Returns non-zero on error:
409 -.Bl -tag -width "0" -offset indent -compact -nested
444 Requests are kept in two queues. The first is the inflight queue. In
445 this queue requests have an allocated transaction id and nameserver.
446 They will soon be transmitted if they haven't already been.
449 The second is the waiting queue. The size of the inflight ring is
450 limited and all other requests wait in waiting queue for space. This
451 bounds the number of concurrent requests so that we don't flood the
452 @@ -288,33 +336,33 @@
453 nameserver. Several algorithms require a full walk of the inflight
454 queue and so bounding its size keeps thing going nicely under huge
455 (many thousands of requests) loads.
458 If a nameserver loses too many requests it is considered down and we
459 try not to use it. After a while we send a probe to that nameserver
460 (a lookup for google.com) and, if it replies, we consider it working
461 again. If the nameserver fails a probe we wait longer to try again
465 -.Xr gethostbyname 3 ,
470 +\fBgethostbyname(3)\fR,
471 +\fBresolv.conf(4)\fR
476 API was developed by Adam Langley on top of the
480 The code was integrate into
483 by Nick Mathewson and finally put into
486 itself by Niels Provos.
492 API and code was written by Adam Langley with significant
493 contributions by Nick Mathewson.
496 This documentation is neither complete nor authoritative.
497 If you are in doubt about the usage of this API then
498 check the source code to find out how it works, write