OpenMPI  0.1.1
dns.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
3  * Copyright (c) 2007-2010 Niels Provos and Nick Mathewson
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /*
29  * The original DNS code is due to Adam Langley with heavy
30  * modifications by Nick Mathewson. Adam put his DNS software in the
31  * public domain. You can find his original copyright below. Please,
32  * aware that the code as part of Libevent is governed by the 3-clause
33  * BSD license above.
34  *
35  * This software is Public Domain. To view a copy of the public domain dedication,
36  * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
37  * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
38  *
39  * I ask and expect, but do not require, that all derivative works contain an
40  * attribution similar to:
41  * Parts developed by Adam Langley <agl@imperialviolet.org>
42  *
43  * You may wish to replace the word "Parts" with something else depending on
44  * the amount of original code.
45  *
46  * (Derivative works does not include programs which link against, run or include
47  * the source verbatim in their source distributions)
48  */
49 
50 /** @file event2/dns.h
51  *
52  * Welcome, gentle reader
53  *
54  * Async DNS lookups are really a whole lot harder than they should be,
55  * mostly stemming from the fact that the libc resolver has never been
56  * very good at them. Before you use this library you should see if libc
57  * can do the job for you with the modern async call getaddrinfo_a
58  * (see http://www.imperialviolet.org/page25.html#e498). Otherwise,
59  * please continue.
60  *
61  * The library keeps track of the state of nameservers and will avoid
62  * them when they go down. Otherwise it will round robin between them.
63  *
64  * Quick start guide:
65  * #include "evdns.h"
66  * void callback(int result, char type, int count, int ttl,
67  * void *addresses, void *arg);
68  * evdns_resolv_conf_parse(DNS_OPTIONS_ALL, "/etc/resolv.conf");
69  * evdns_resolve("www.hostname.com", 0, callback, NULL);
70  *
71  * When the lookup is complete the callback function is called. The
72  * first argument will be one of the DNS_ERR_* defines in evdns.h.
73  * Hopefully it will be DNS_ERR_NONE, in which case type will be
74  * DNS_IPv4_A, count will be the number of IP addresses, ttl is the time
75  * which the data can be cached for (in seconds), addresses will point
76  * to an array of uint32_t's and arg will be whatever you passed to
77  * evdns_resolve.
78  *
79  * Searching:
80  *
81  * In order for this library to be a good replacement for glibc's resolver it
82  * supports searching. This involves setting a list of default domains, in
83  * which names will be queried for. The number of dots in the query name
84  * determines the order in which this list is used.
85  *
86  * Searching appears to be a single lookup from the point of view of the API,
87  * although many DNS queries may be generated from a single call to
88  * evdns_resolve. Searching can also drastically slow down the resolution
89  * of names.
90  *
91  * To disable searching:
92  * 1. Never set it up. If you never call evdns_resolv_conf_parse or
93  * evdns_search_add then no searching will occur.
94  *
95  * 2. If you do call evdns_resolv_conf_parse then don't pass
96  * DNS_OPTION_SEARCH (or DNS_OPTIONS_ALL, which implies it).
97  *
98  * 3. When calling evdns_resolve, pass the DNS_QUERY_NO_SEARCH flag.
99  *
100  * The order of searches depends on the number of dots in the name. If the
101  * number is greater than the ndots setting then the names is first tried
102  * globally. Otherwise each search domain is appended in turn.
103  *
104  * The ndots setting can either be set from a resolv.conf, or by calling
105  * evdns_search_ndots_set.
106  *
107  * For example, with ndots set to 1 (the default) and a search domain list of
108  * ["myhome.net"]:
109  * Query: www
110  * Order: www.myhome.net, www.
111  *
112  * Query: www.abc
113  * Order: www.abc., www.abc.myhome.net
114  *
115  * Internals:
116  *
117  * Requests are kept in two queues. The first is the inflight queue. In
118  * this queue requests have an allocated transaction id and nameserver.
119  * They will soon be transmitted if they haven't already been.
120  *
121  * The second is the waiting queue. The size of the inflight ring is
122  * limited and all other requests wait in waiting queue for space. This
123  * bounds the number of concurrent requests so that we don't flood the
124  * nameserver. Several algorithms require a full walk of the inflight
125  * queue and so bounding its size keeps thing going nicely under huge
126  * (many thousands of requests) loads.
127  *
128  * If a nameserver loses too many requests it is considered down and we
129  * try not to use it. After a while we send a probe to that nameserver
130  * (a lookup for google.com) and, if it replies, we consider it working
131  * again. If the nameserver fails a probe we wait longer to try again
132  * with the next probe.
133  */
134 
135 #ifndef _EVENT2_DNS_H_
136 #define _EVENT2_DNS_H_
137 
138 #ifdef __cplusplus
139 extern "C" {
140 #endif
141 
142 /* For integer types. */
143 #include <event2/util.h>
144 
145 /** Error codes 0-5 are as described in RFC 1035. */
146 #define DNS_ERR_NONE 0
147 /** The name server was unable to interpret the query */
148 #define DNS_ERR_FORMAT 1
149 /** The name server was unable to process this query due to a problem with the
150  * name server */
151 #define DNS_ERR_SERVERFAILED 2
152 /** The domain name does not exist */
153 #define DNS_ERR_NOTEXIST 3
154 /** The name server does not support the requested kind of query */
155 #define DNS_ERR_NOTIMPL 4
156 /** The name server refuses to reform the specified operation for policy
157  * reasons */
158 #define DNS_ERR_REFUSED 5
159 /** The reply was truncated or ill-formatted */
160 #define DNS_ERR_TRUNCATED 65
161 /** An unknown error occurred */
162 #define DNS_ERR_UNKNOWN 66
163 /** Communication with the server timed out */
164 #define DNS_ERR_TIMEOUT 67
165 /** The request was canceled because the DNS subsystem was shut down. */
166 #define DNS_ERR_SHUTDOWN 68
167 /** The request was canceled via a call to evdns_cancel_request */
168 #define DNS_ERR_CANCEL 69
169 
170 #define DNS_IPv4_A 1
171 #define DNS_PTR 2
172 #define DNS_IPv6_AAAA 3
173 
174 #define DNS_QUERY_NO_SEARCH 1
175 
176 #define DNS_OPTION_SEARCH 1
177 #define DNS_OPTION_NAMESERVERS 2
178 #define DNS_OPTION_MISC 4
179 #define DNS_OPTION_HOSTSFILE 8
180 #define DNS_OPTIONS_ALL 15
181 
182 /* Obsolete name for DNS_QUERY_NO_SEARCH */
183 #define DNS_NO_SEARCH DNS_QUERY_NO_SEARCH
184 
185 /**
186  * The callback that contains the results from a lookup.
187  * - result is one of the DNS_ERR_* values (DNS_ERR_NONE for success)
188  * - type is either DNS_IPv4_A or DNS_PTR or DNS_IPv6_AAAA
189  * - count contains the number of addresses of form type
190  * - ttl is the number of seconds the resolution may be cached for.
191  * - addresses needs to be cast according to type. It will be an array of
192  * 4-byte sequences for ipv4, or an array of 16-byte sequences for ipv6,
193  * or a nul-terminated string for PTR.
194  */
195 typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg);
196 
197 struct evdns_base;
198 struct event_base;
199 
200 /**
201  Initialize the asynchronous DNS library.
202 
203  This function initializes support for non-blocking name resolution by
204  calling evdns_resolv_conf_parse() on UNIX and
205  evdns_config_windows_nameservers() on Windows.
206 
207  @param event_base the event base to associate the dns client with
208  @param initialize_nameservers 1 if resolve.conf processing should occur
209  @return 0 if successful, or -1 if an error occurred
210  @see evdns_base_free()
211  */
212 struct evdns_base * evdns_base_new(struct event_base *event_base, int initialize_nameservers);
213 
214 
215 /**
216  Shut down the asynchronous DNS resolver and terminate all active requests.
217 
218  If the 'fail_requests' option is enabled, all active requests will return
219  an empty result with the error flag set to DNS_ERR_SHUTDOWN. Otherwise,
220  the requests will be silently discarded.
221 
222  @param evdns_base the evdns base to free
223  @param fail_requests if zero, active requests will be aborted; if non-zero,
224  active requests will return DNS_ERR_SHUTDOWN.
225  @see evdns_base_new()
226  */
227 void evdns_base_free(struct evdns_base *base, int fail_requests);
228 
229 /**
230  Convert a DNS error code to a string.
231 
232  @param err the DNS error code
233  @return a string containing an explanation of the error code
234 */
235 const char *evdns_err_to_string(int err);
236 
237 
238 /**
239  Add a nameserver.
240 
241  The address should be an IPv4 address in network byte order.
242  The type of address is chosen so that it matches in_addr.s_addr.
243 
244  @param base the evdns_base to which to add the name server
245  @param address an IP address in network byte order
246  @return 0 if successful, or -1 if an error occurred
247  @see evdns_base_nameserver_ip_add()
248  */
249 int evdns_base_nameserver_add(struct evdns_base *base,
250  unsigned long int address);
251 
252 /**
253  Get the number of configured nameservers.
254 
255  This returns the number of configured nameservers (not necessarily the
256  number of running nameservers). This is useful for double-checking
257  whether our calls to the various nameserver configuration functions
258  have been successful.
259 
260  @param base the evdns_base to which to apply this operation
261  @return the number of configured nameservers
262  @see evdns_base_nameserver_add()
263  */
264 int evdns_base_count_nameservers(struct evdns_base *base);
265 
266 /**
267  Remove all configured nameservers, and suspend all pending resolves.
268 
269  Resolves will not necessarily be re-attempted until evdns_resume() is called.
270 
271  @param base the evdns_base to which to apply this operation
272  @return 0 if successful, or -1 if an error occurred
273  @see evdns_base_resume()
274  */
276 
277 
278 /**
279  Resume normal operation and continue any suspended resolve requests.
280 
281  Re-attempt resolves left in limbo after an earlier call to
282  evdns_clear_nameservers_and_suspend().
283 
284  @param base the evdns_base to which to apply this operation
285  @return 0 if successful, or -1 if an error occurred
286  @see evdns_base_clear_nameservers_and_suspend()
287  */
288 int evdns_base_resume(struct evdns_base *base);
289 
290 /**
291  Add a nameserver by string address.
292 
293  This function parses a n IPv4 or IPv6 address from a string and adds it as a
294  nameserver. It supports the following formats:
295  - [IPv6Address]:port
296  - [IPv6Address]
297  - IPv6Address
298  - IPv4Address:port
299  - IPv4Address
300 
301  If no port is specified, it defaults to 53.
302 
303  @param base the evdns_base to which to apply this operation
304  @return 0 if successful, or -1 if an error occurred
305  @see evdns_base_nameserver_add()
306  */
308  const char *ip_as_string);
309 
310 /**
311  Add a nameserver by sockaddr.
312  **/
313 int
315  const struct sockaddr *sa, ev_socklen_t len, unsigned flags);
316 
317 struct evdns_request;
318 
319 /**
320  Lookup an A record for a given name.
321 
322  @param base the evdns_base to which to apply this operation
323  @param name a DNS hostname
324  @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
325  @param callback a callback function to invoke when the request is completed
326  @param ptr an argument to pass to the callback function
327  @return an evdns_request object if successful, or NULL if an error occurred.
328  @see evdns_resolve_ipv6(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6(), evdns_cancel_request()
329  */
330 struct evdns_request *evdns_base_resolve_ipv4(struct evdns_base *base, const char *name, int flags, evdns_callback_type callback, void *ptr);
331 
332 /**
333  Lookup an AAAA record for a given name.
334 
335  @param base the evdns_base to which to apply this operation
336  @param name a DNS hostname
337  @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
338  @param callback a callback function to invoke when the request is completed
339  @param ptr an argument to pass to the callback function
340  @return an evdns_request object if successful, or NULL if an error occurred.
341  @see evdns_resolve_ipv4(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6(), evdns_cancel_request()
342  */
343 struct evdns_request *evdns_base_resolve_ipv6(struct evdns_base *base, const char *name, int flags, evdns_callback_type callback, void *ptr);
344 
345 struct in_addr;
346 struct in6_addr;
347 
348 /**
349  Lookup a PTR record for a given IP address.
350 
351  @param base the evdns_base to which to apply this operation
352  @param in an IPv4 address
353  @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
354  @param callback a callback function to invoke when the request is completed
355  @param ptr an argument to pass to the callback function
356  @return an evdns_request object if successful, or NULL if an error occurred.
357  @see evdns_resolve_reverse_ipv6(), evdns_cancel_request()
358  */
359 struct evdns_request *evdns_base_resolve_reverse(struct evdns_base *base, const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr);
360 
361 
362 /**
363  Lookup a PTR record for a given IPv6 address.
364 
365  @param base the evdns_base to which to apply this operation
366  @param in an IPv6 address
367  @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
368  @param callback a callback function to invoke when the request is completed
369  @param ptr an argument to pass to the callback function
370  @return an evdns_request object if successful, or NULL if an error occurred.
371  @see evdns_resolve_reverse_ipv6(), evdns_cancel_request()
372  */
373 struct evdns_request *evdns_base_resolve_reverse_ipv6(struct evdns_base *base, const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr);
374 
375 /**
376  Cancels a pending DNS resolution request.
377 
378  @param base the evdns_base that was used to make the request
379  @param req the evdns_request that was returned by calling a resolve function
380  @see evdns_base_resolve_ip4(), evdns_base_resolve_ipv6, evdns_base_resolve_reverse
381 */
382 void evdns_cancel_request(struct evdns_base *base, struct evdns_request *req);
383 
384 /**
385  Set the value of a configuration option.
386 
387  The currently available configuration options are:
388 
389  ndots, timeout, max-timeouts, max-inflight, attempts, randomize-case,
390  bind-to, initial-probe-timeout, getaddrinfo-allow-skew.
391 
392  In versions before Libevent 2.0.3-alpha, the option name needed to end with
393  a colon.
394 
395  @param base the evdns_base to which to apply this operation
396  @param option the name of the configuration option to be modified
397  @param val the value to be set
398  @return 0 if successful, or -1 if an error occurred
399  */
400 int evdns_base_set_option(struct evdns_base *base, const char *option, const char *val);
401 
402 
403 /**
404  Parse a resolv.conf file.
405 
406  The 'flags' parameter determines what information is parsed from the
407  resolv.conf file. See the man page for resolv.conf for the format of this
408  file.
409 
410  The following directives are not parsed from the file: sortlist, rotate,
411  no-check-names, inet6, debug.
412 
413  If this function encounters an error, the possible return values are: 1 =
414  failed to open file, 2 = failed to stat file, 3 = file too large, 4 = out of
415  memory, 5 = short read from file, 6 = no nameservers listed in the file
416 
417  @param base the evdns_base to which to apply this operation
418  @param flags any of DNS_OPTION_NAMESERVERS|DNS_OPTION_SEARCH|DNS_OPTION_MISC|
419  DNS_OPTIONS_HOSTSFILE|DNS_OPTIONS_ALL
420  @param filename the path to the resolv.conf file
421  @return 0 if successful, or various positive error codes if an error
422  occurred (see above)
423  @see resolv.conf(3), evdns_config_windows_nameservers()
424  */
425 int evdns_base_resolv_conf_parse(struct evdns_base *base, int flags, const char *const filename);
426 
427 /**
428  Load an /etc/hosts-style file from 'hosts_fname' into 'base'.
429 
430  If hosts_fname is NULL, add minimal entries for localhost, and nothing
431  else.
432 
433  Note that only evdns_getaddrinfo uses the /etc/hosts entries.
434 
435  Return 0 on success, negative on failure.
436 */
437 int evdns_base_load_hosts(struct evdns_base *base, const char *hosts_fname);
438 
439 /**
440  Obtain nameserver information using the Windows API.
441 
442  Attempt to configure a set of nameservers based on platform settings on
443  a win32 host. Preferentially tries to use GetNetworkParams; if that fails,
444  looks in the registry.
445 
446  @return 0 if successful, or -1 if an error occurred
447  @see evdns_resolv_conf_parse()
448  */
449 #ifdef WIN32
450 int evdns_base_config_windows_nameservers(struct evdns_base *);
451 #define EVDNS_BASE_CONFIG_WINDOWS_NAMESERVERS_IMPLEMENTED
452 #endif
453 
454 
455 /**
456  Clear the list of search domains.
457  */
458 void evdns_base_search_clear(struct evdns_base *base);
459 
460 
461 /**
462  Add a domain to the list of search domains
463 
464  @param domain the domain to be added to the search list
465  */
466 void evdns_base_search_add(struct evdns_base *base, const char *domain);
467 
468 
469 /**
470  Set the 'ndots' parameter for searches.
471 
472  Sets the number of dots which, when found in a name, causes
473  the first query to be without any search domain.
474 
475  @param ndots the new ndots parameter
476  */
477 void evdns_base_search_ndots_set(struct evdns_base *base, const int ndots);
478 
479 /**
480  A callback that is invoked when a log message is generated
481 
482  @param is_warning indicates if the log message is a 'warning'
483  @param msg the content of the log message
484  */
485 typedef void (*evdns_debug_log_fn_type)(int is_warning, const char *msg);
486 
487 
488 /**
489  Set the callback function to handle DNS log messages. If this
490  callback is not set, evdns log messages are handled with the regular
491  Libevent logging system.
492 
493  @param fn the callback to be invoked when a log message is generated
494  */
496 
497 /**
498  Set a callback that will be invoked to generate transaction IDs. By
499  default, we pick transaction IDs based on the current clock time, which
500  is bad for security.
501 
502  @param fn the new callback, or NULL to use the default.
503 
504  NOTE: This function has no effect in Libevent 2.0.4-alpha and later,
505  since Libevent now provides its own secure RNG.
506  */
507 void evdns_set_transaction_id_fn(ev_uint16_t (*fn)(void));
508 
509 /**
510  Set a callback used to generate random bytes. By default, we use
511  the same function as passed to evdns_set_transaction_id_fn to generate
512  bytes two at a time. If a function is provided here, it's also used
513  to generate transaction IDs.
514 
515  NOTE: This function has no effect in Libevent 2.0.4-alpha and later,
516  since Libevent now provides its own secure RNG.
517 */
518 void evdns_set_random_bytes_fn(void (*fn)(char *, size_t));
519 
520 /*
521  * Functions used to implement a DNS server.
522  */
523 
524 struct evdns_server_request;
525 struct evdns_server_question;
526 
527 /**
528  A callback to implement a DNS server. The callback function receives a DNS
529  request. It should then optionally add a number of answers to the reply
530  using the evdns_server_request_add_*_reply functions, before calling either
531  evdns_server_request_respond to send the reply back, or
532  evdns_server_request_drop to decline to answer the request.
533 
534  @param req A newly received request
535  @param user_data A pointer that was passed to
536  evdns_add_server_port_with_base().
537  */
538 typedef void (*evdns_request_callback_fn_type)(struct evdns_server_request *, void *);
539 #define EVDNS_ANSWER_SECTION 0
540 #define EVDNS_AUTHORITY_SECTION 1
541 #define EVDNS_ADDITIONAL_SECTION 2
542 
543 #define EVDNS_TYPE_A 1
544 #define EVDNS_TYPE_NS 2
545 #define EVDNS_TYPE_CNAME 5
546 #define EVDNS_TYPE_SOA 6
547 #define EVDNS_TYPE_PTR 12
548 #define EVDNS_TYPE_MX 15
549 #define EVDNS_TYPE_TXT 16
550 #define EVDNS_TYPE_AAAA 28
551 
552 #define EVDNS_QTYPE_AXFR 252
553 #define EVDNS_QTYPE_ALL 255
554 
555 #define EVDNS_CLASS_INET 1
556 
557 /* flags that can be set in answers; as part of the err parameter */
558 #define EVDNS_FLAGS_AA 0x400
559 #define EVDNS_FLAGS_RD 0x080
560 
561 /** Create a new DNS server port.
562 
563  @param base The event base to handle events for the server port.
564  @param socket A UDP socket to accept DNS requests.
565  @param flags Always 0 for now.
566  @param callback A function to invoke whenever we get a DNS request
567  on the socket.
568  @param user_data Data to pass to the callback.
569  @return an evdns_server_port structure for this server port.
570  */
572 /** Close down a DNS server port, and free associated structures. */
573 void evdns_close_server_port(struct evdns_server_port *port);
574 
575 /** Sets some flags in a reply we're building.
576  Allows setting of the AA or RD flags
577  */
578 void evdns_server_request_set_flags(struct evdns_server_request *req, int flags);
579 
580 /* Functions to add an answer to an in-progress DNS reply.
581  */
582 int evdns_server_request_add_reply(struct evdns_server_request *req, int section, const char *name, int type, int dns_class, int ttl, int datalen, int is_name, const char *data);
583 int evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl);
584 int evdns_server_request_add_aaaa_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl);
585 int evdns_server_request_add_ptr_reply(struct evdns_server_request *req, struct in_addr *in, const char *inaddr_name, const char *hostname, int ttl);
586 int evdns_server_request_add_cname_reply(struct evdns_server_request *req, const char *name, const char *cname, int ttl);
587 
588 /**
589  Send back a response to a DNS request, and free the request structure.
590 */
591 int evdns_server_request_respond(struct evdns_server_request *req, int err);
592 /**
593  Free a DNS request without sending back a reply.
594 */
596 struct sockaddr;
597 /**
598  Get the address that made a DNS request.
599  */
600 int evdns_server_request_get_requesting_addr(struct evdns_server_request *_req, struct sockaddr *sa, int addr_len);
601 
602 /** Callback for evdns_getaddrinfo. */
603 typedef void (*evdns_getaddrinfo_cb)(int result, struct evutil_addrinfo *res, void *arg);
604 
605 struct evdns_base;
607 /** Make a non-blocking getaddrinfo request using the dns_base in 'dns_base'.
608  *
609  * If we can answer the request immediately (with an error or not!), then we
610  * invoke cb immediately and return NULL. Otherwise we return
611  * an evdns_getaddrinfo_request and invoke cb later.
612  *
613  * When the callback is invoked, we pass as its first argument the error code
614  * that getaddrinfo would return (or 0 for no error). As its second argument,
615  * we pass the evutil_addrinfo structures we found (or NULL on error). We
616  * pass 'arg' as the third argument.
617  *
618  * Limitations:
619  *
620  * - The AI_V4MAPPED and AI_ALL flags are not currently implemented.
621  * - For ai_socktype, we only handle SOCKTYPE_STREAM, SOCKTYPE_UDP, and 0.
622  * - For ai_protocol, we only handle IPPROTO_TCP, IPPROTO_UDP, and 0.
623  */
625  struct evdns_base *dns_base,
626  const char *nodename, const char *servname,
627  const struct evutil_addrinfo *hints_in,
628  evdns_getaddrinfo_cb cb, void *arg);
629 
630 /* Cancel an in-progress evdns_getaddrinfo. This MUST NOT be called after the
631  * getaddrinfo's callback has been invoked. The resolves will be canceled,
632  * and the callback will be invoked with the error EVUTIL_EAI_CANCEL. */
633 void evdns_getaddrinfo_cancel(struct evdns_getaddrinfo_request *req);
634 
635 #ifdef __cplusplus
636 }
637 #endif
638 
639 #endif /* !_EVENT2_DNS_H_ */
Definition: evdns.c:286
void(* evdns_debug_log_fn_type)(int is_warning, const char *msg)
A callback that is invoked when a log message is generated.
Definition: dns.h:485
struct evdns_getaddrinfo_request * evdns_getaddrinfo(struct evdns_base *dns_base, const char *nodename, const char *servname, const struct evutil_addrinfo *hints_in, evdns_getaddrinfo_cb cb, void *arg)
Make a non-blocking getaddrinfo request using the dns_base in 'dns_base'.
Definition: evdns.c:4422
void evdns_set_log_fn(evdns_debug_log_fn_type fn)
Set the callback function to handle DNS log messages.
Definition: evdns.c:425
Definition: evdns.c:226
void(* evdns_callback_type)(int result, char type, int count, int ttl, void *addresses, void *arg)
The callback that contains the results from a lookup.
Definition: dns.h:195
int evdns_base_resolv_conf_parse(struct evdns_base *base, int flags, const char *const filename)
Parse a resolv.conf file.
Definition: evdns.c:3427
Definition: dns_struct.h:61
struct evdns_request * evdns_base_resolve_ipv6(struct evdns_base *base, const char *name, int flags, evdns_callback_type callback, void *ptr)
Lookup an AAAA record for a given name.
Definition: evdns.c:2774
struct evdns_request * evdns_base_resolve_reverse(struct evdns_base *base, const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr)
Lookup a PTR record for a given IP address.
Definition: evdns.c:2809
int evdns_base_load_hosts(struct evdns_base *base, const char *hosts_fname)
Load an /etc/hosts-style file from 'hosts_fname' into 'base'.
Definition: evdns.c:4030
int evdns_server_request_respond(struct evdns_server_request *req, int err)
Send back a response to a DNS request, and free the request structure.
Definition: evdns.c:1907
int evdns_base_resume(struct evdns_base *base)
Resume normal operation and continue any suspended resolve requests.
Definition: evdns.c:2356
Definition: evdns.c:4048
int evdns_server_request_drop(struct evdns_server_request *req)
Free a DNS request without sending back a reply.
Definition: evdns.c:2055
const char * evdns_err_to_string(int err)
Convert a DNS error code to a string.
Definition: evdns.c:3827
void evdns_close_server_port(struct evdns_server_port *port)
Close down a DNS server port, and free associated structures.
Definition: evdns.c:1664
#define evutil_socket_t
A type wide enough to hold the output of "socket()" or "accept()".
Definition: util.h:278
Definition: ipv6-internal.h:51
int evdns_base_clear_nameservers_and_suspend(struct evdns_base *base)
Remove all configured nameservers, and suspend all pending resolves.
Definition: evdns.c:2287
void evdns_base_search_ndots_set(struct evdns_base *base, const int ndots)
Set the 'ndots' parameter for searches.
Definition: evdns.c:3006
Common convenience functions for cross-platform portability and related socket manipulations.
void(* evdns_getaddrinfo_cb)(int result, struct evutil_addrinfo *res, void *arg)
Callback for evdns_getaddrinfo.
Definition: dns.h:603
int evdns_base_count_nameservers(struct evdns_base *base)
Get the number of configured nameservers.
Definition: evdns.c:2261
Definition: dns_struct.h:56
struct evdns_base * evdns_base_new(struct event_base *event_base, int initialize_nameservers)
Initialize the asynchronous DNS library.
Definition: evdns.c:3750
A definition of struct addrinfo for systems that lack it.
Definition: util.h:513
void evdns_set_random_bytes_fn(void(*fn)(char *, size_t))
Set a callback used to generate random bytes.
Definition: evdns.c:1230
int evdns_base_set_option(struct evdns_base *base, const char *option, const char *val)
Set the value of a configuration option.
Definition: evdns.c:3269
void evdns_set_transaction_id_fn(ev_uint16_t(*fn)(void))
Set a callback that will be invoked to generate transaction IDs.
Definition: evdns.c:1225
Definition: t-test1.c:28
void evdns_server_request_set_flags(struct evdns_server_request *req, int flags)
Sets some flags in a reply we're building.
Definition: evdns.c:1801
void evdns_base_search_clear(struct evdns_base *base)
Obtain nameserver information using the Windows API.
Definition: evdns.c:2942
void evdns_base_free(struct evdns_base *base, int fail_requests)
Shut down the asynchronous DNS resolver and terminate all active requests.
Definition: evdns.c:3919
int evdns_base_nameserver_sockaddr_add(struct evdns_base *base, const struct sockaddr *sa, ev_socklen_t len, unsigned flags)
Add a nameserver by sockaddr.
Definition: evdns.c:2529
int evdns_server_request_get_requesting_addr(struct evdns_server_request *_req, struct sockaddr *sa, int addr_len)
Get the address that made a DNS request.
Definition: evdns.c:2064
struct evdns_request * evdns_base_resolve_ipv4(struct evdns_base *base, const char *name, int flags, evdns_callback_type callback, void *ptr)
Lookup an A record for a given name.
Definition: evdns.c:2737
struct evdns_server_port * evdns_add_server_port_with_base(struct event_base *base, evutil_socket_t socket, int flags, evdns_request_callback_fn_type callback, void *user_data)
Create a new DNS server port.
Definition: evdns.c:1626
void evdns_cancel_request(struct evdns_base *base, struct evdns_request *req)
Cancels a pending DNS resolution request.
Definition: evdns.c:2701
int evdns_base_nameserver_ip_add(struct evdns_base *base, const char *ip_as_string)
Add a nameserver by string address.
Definition: evdns.c:2500
void evdns_base_search_add(struct evdns_base *base, const char *domain)
Add a domain to the list of search domains.
Definition: evdns.c:2994
Definition: evdns.c:144
struct evdns_request * evdns_base_resolve_reverse_ipv6(struct evdns_base *base, const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr)
Lookup a PTR record for a given IPv6 address.
Definition: evdns.c:2843
Definition: event-internal.h:167
void(* evdns_request_callback_fn_type)(struct evdns_server_request *, void *)
A callback to implement a DNS server.
Definition: dns.h:538
int evdns_base_nameserver_add(struct evdns_base *base, unsigned long int address)
Add a nameserver.
Definition: evdns.c:2456