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