12b15cb3dSCy Schubert /* 22b15cb3dSCy Schubert * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu> 32b15cb3dSCy Schubert * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 42b15cb3dSCy Schubert * 52b15cb3dSCy Schubert * Redistribution and use in source and binary forms, with or without 62b15cb3dSCy Schubert * modification, are permitted provided that the following conditions 72b15cb3dSCy Schubert * are met: 82b15cb3dSCy Schubert * 1. Redistributions of source code must retain the above copyright 92b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer. 102b15cb3dSCy Schubert * 2. Redistributions in binary form must reproduce the above copyright 112b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer in the 122b15cb3dSCy Schubert * documentation and/or other materials provided with the distribution. 132b15cb3dSCy Schubert * 3. The name of the author may not be used to endorse or promote products 142b15cb3dSCy Schubert * derived from this software without specific prior written permission. 152b15cb3dSCy Schubert * 162b15cb3dSCy Schubert * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 172b15cb3dSCy Schubert * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 182b15cb3dSCy Schubert * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 192b15cb3dSCy Schubert * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 202b15cb3dSCy Schubert * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 212b15cb3dSCy Schubert * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222b15cb3dSCy Schubert * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232b15cb3dSCy Schubert * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242b15cb3dSCy Schubert * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 252b15cb3dSCy Schubert * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262b15cb3dSCy Schubert */ 272b15cb3dSCy Schubert 282b15cb3dSCy Schubert /* 292b15cb3dSCy Schubert * The original DNS code is due to Adam Langley with heavy 302b15cb3dSCy Schubert * modifications by Nick Mathewson. Adam put his DNS software in the 312b15cb3dSCy Schubert * public domain. You can find his original copyright below. Please, 322b15cb3dSCy Schubert * aware that the code as part of Libevent is governed by the 3-clause 332b15cb3dSCy Schubert * BSD license above. 342b15cb3dSCy Schubert * 352b15cb3dSCy Schubert * This software is Public Domain. To view a copy of the public domain dedication, 362b15cb3dSCy Schubert * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to 372b15cb3dSCy Schubert * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. 382b15cb3dSCy Schubert * 392b15cb3dSCy Schubert * I ask and expect, but do not require, that all derivative works contain an 402b15cb3dSCy Schubert * attribution similar to: 412b15cb3dSCy Schubert * Parts developed by Adam Langley <agl@imperialviolet.org> 422b15cb3dSCy Schubert * 432b15cb3dSCy Schubert * You may wish to replace the word "Parts" with something else depending on 442b15cb3dSCy Schubert * the amount of original code. 452b15cb3dSCy Schubert * 462b15cb3dSCy Schubert * (Derivative works does not include programs which link against, run or include 472b15cb3dSCy Schubert * the source verbatim in their source distributions) 482b15cb3dSCy Schubert */ 492b15cb3dSCy Schubert 502b15cb3dSCy Schubert /** @file event2/dns.h 512b15cb3dSCy Schubert * 522b15cb3dSCy Schubert * Welcome, gentle reader 532b15cb3dSCy Schubert * 542b15cb3dSCy Schubert * Async DNS lookups are really a whole lot harder than they should be, 552b15cb3dSCy Schubert * mostly stemming from the fact that the libc resolver has never been 562b15cb3dSCy Schubert * very good at them. Before you use this library you should see if libc 572b15cb3dSCy Schubert * can do the job for you with the modern async call getaddrinfo_a 582b15cb3dSCy Schubert * (see http://www.imperialviolet.org/page25.html#e498). Otherwise, 592b15cb3dSCy Schubert * please continue. 602b15cb3dSCy Schubert * 612b15cb3dSCy Schubert * The library keeps track of the state of nameservers and will avoid 622b15cb3dSCy Schubert * them when they go down. Otherwise it will round robin between them. 632b15cb3dSCy Schubert * 642b15cb3dSCy Schubert * Quick start guide: 652b15cb3dSCy Schubert * #include "evdns.h" 662b15cb3dSCy Schubert * void callback(int result, char type, int count, int ttl, 672b15cb3dSCy Schubert * void *addresses, void *arg); 682b15cb3dSCy Schubert * evdns_resolv_conf_parse(DNS_OPTIONS_ALL, "/etc/resolv.conf"); 692b15cb3dSCy Schubert * evdns_resolve("www.hostname.com", 0, callback, NULL); 702b15cb3dSCy Schubert * 712b15cb3dSCy Schubert * When the lookup is complete the callback function is called. The 722b15cb3dSCy Schubert * first argument will be one of the DNS_ERR_* defines in evdns.h. 732b15cb3dSCy Schubert * Hopefully it will be DNS_ERR_NONE, in which case type will be 742b15cb3dSCy Schubert * DNS_IPv4_A, count will be the number of IP addresses, ttl is the time 752b15cb3dSCy Schubert * which the data can be cached for (in seconds), addresses will point 762b15cb3dSCy Schubert * to an array of uint32_t's and arg will be whatever you passed to 772b15cb3dSCy Schubert * evdns_resolve. 782b15cb3dSCy Schubert * 792b15cb3dSCy Schubert * Searching: 802b15cb3dSCy Schubert * 812b15cb3dSCy Schubert * In order for this library to be a good replacement for glibc's resolver it 822b15cb3dSCy Schubert * supports searching. This involves setting a list of default domains, in 832b15cb3dSCy Schubert * which names will be queried for. The number of dots in the query name 842b15cb3dSCy Schubert * determines the order in which this list is used. 852b15cb3dSCy Schubert * 862b15cb3dSCy Schubert * Searching appears to be a single lookup from the point of view of the API, 872b15cb3dSCy Schubert * although many DNS queries may be generated from a single call to 882b15cb3dSCy Schubert * evdns_resolve. Searching can also drastically slow down the resolution 892b15cb3dSCy Schubert * of names. 902b15cb3dSCy Schubert * 912b15cb3dSCy Schubert * To disable searching: 922b15cb3dSCy Schubert * 1. Never set it up. If you never call evdns_resolv_conf_parse or 932b15cb3dSCy Schubert * evdns_search_add then no searching will occur. 942b15cb3dSCy Schubert * 952b15cb3dSCy Schubert * 2. If you do call evdns_resolv_conf_parse then don't pass 962b15cb3dSCy Schubert * DNS_OPTION_SEARCH (or DNS_OPTIONS_ALL, which implies it). 972b15cb3dSCy Schubert * 982b15cb3dSCy Schubert * 3. When calling evdns_resolve, pass the DNS_QUERY_NO_SEARCH flag. 992b15cb3dSCy Schubert * 1002b15cb3dSCy Schubert * The order of searches depends on the number of dots in the name. If the 1012b15cb3dSCy Schubert * number is greater than the ndots setting then the names is first tried 1022b15cb3dSCy Schubert * globally. Otherwise each search domain is appended in turn. 1032b15cb3dSCy Schubert * 1042b15cb3dSCy Schubert * The ndots setting can either be set from a resolv.conf, or by calling 1052b15cb3dSCy Schubert * evdns_search_ndots_set. 1062b15cb3dSCy Schubert * 1072b15cb3dSCy Schubert * For example, with ndots set to 1 (the default) and a search domain list of 1082b15cb3dSCy Schubert * ["myhome.net"]: 1092b15cb3dSCy Schubert * Query: www 1102b15cb3dSCy Schubert * Order: www.myhome.net, www. 1112b15cb3dSCy Schubert * 1122b15cb3dSCy Schubert * Query: www.abc 1132b15cb3dSCy Schubert * Order: www.abc., www.abc.myhome.net 1142b15cb3dSCy Schubert * 1152b15cb3dSCy Schubert * Internals: 1162b15cb3dSCy Schubert * 1172b15cb3dSCy Schubert * Requests are kept in two queues. The first is the inflight queue. In 1182b15cb3dSCy Schubert * this queue requests have an allocated transaction id and nameserver. 1192b15cb3dSCy Schubert * They will soon be transmitted if they haven't already been. 1202b15cb3dSCy Schubert * 1212b15cb3dSCy Schubert * The second is the waiting queue. The size of the inflight ring is 1222b15cb3dSCy Schubert * limited and all other requests wait in waiting queue for space. This 1232b15cb3dSCy Schubert * bounds the number of concurrent requests so that we don't flood the 1242b15cb3dSCy Schubert * nameserver. Several algorithms require a full walk of the inflight 1252b15cb3dSCy Schubert * queue and so bounding its size keeps thing going nicely under huge 1262b15cb3dSCy Schubert * (many thousands of requests) loads. 1272b15cb3dSCy Schubert * 1282b15cb3dSCy Schubert * If a nameserver loses too many requests it is considered down and we 1292b15cb3dSCy Schubert * try not to use it. After a while we send a probe to that nameserver 1302b15cb3dSCy Schubert * (a lookup for google.com) and, if it replies, we consider it working 1312b15cb3dSCy Schubert * again. If the nameserver fails a probe we wait longer to try again 1322b15cb3dSCy Schubert * with the next probe. 1332b15cb3dSCy Schubert */ 1342b15cb3dSCy Schubert 1352b15cb3dSCy Schubert #ifndef EVENT2_DNS_H_INCLUDED_ 1362b15cb3dSCy Schubert #define EVENT2_DNS_H_INCLUDED_ 1372b15cb3dSCy Schubert 1382b15cb3dSCy Schubert #include <event2/visibility.h> 1392b15cb3dSCy Schubert 1402b15cb3dSCy Schubert #ifdef __cplusplus 1412b15cb3dSCy Schubert extern "C" { 1422b15cb3dSCy Schubert #endif 1432b15cb3dSCy Schubert 1442b15cb3dSCy Schubert /* For integer types. */ 1452b15cb3dSCy Schubert #include <event2/util.h> 1462b15cb3dSCy Schubert 1472b15cb3dSCy Schubert /** Error codes 0-5 are as described in RFC 1035. */ 1482b15cb3dSCy Schubert #define DNS_ERR_NONE 0 1492b15cb3dSCy Schubert /** The name server was unable to interpret the query */ 1502b15cb3dSCy Schubert #define DNS_ERR_FORMAT 1 1512b15cb3dSCy Schubert /** The name server was unable to process this query due to a problem with the 1522b15cb3dSCy Schubert * name server */ 1532b15cb3dSCy Schubert #define DNS_ERR_SERVERFAILED 2 1542b15cb3dSCy Schubert /** The domain name does not exist */ 1552b15cb3dSCy Schubert #define DNS_ERR_NOTEXIST 3 1562b15cb3dSCy Schubert /** The name server does not support the requested kind of query */ 1572b15cb3dSCy Schubert #define DNS_ERR_NOTIMPL 4 1582b15cb3dSCy Schubert /** The name server refuses to reform the specified operation for policy 1592b15cb3dSCy Schubert * reasons */ 1602b15cb3dSCy Schubert #define DNS_ERR_REFUSED 5 1612b15cb3dSCy Schubert /** The reply was truncated or ill-formatted */ 1622b15cb3dSCy Schubert #define DNS_ERR_TRUNCATED 65 1632b15cb3dSCy Schubert /** An unknown error occurred */ 1642b15cb3dSCy Schubert #define DNS_ERR_UNKNOWN 66 1652b15cb3dSCy Schubert /** Communication with the server timed out */ 1662b15cb3dSCy Schubert #define DNS_ERR_TIMEOUT 67 1672b15cb3dSCy Schubert /** The request was canceled because the DNS subsystem was shut down. */ 1682b15cb3dSCy Schubert #define DNS_ERR_SHUTDOWN 68 1692b15cb3dSCy Schubert /** The request was canceled via a call to evdns_cancel_request */ 1702b15cb3dSCy Schubert #define DNS_ERR_CANCEL 69 1712b15cb3dSCy Schubert /** There were no answers and no error condition in the DNS packet. 1722b15cb3dSCy Schubert * This can happen when you ask for an address that exists, but a record 1732b15cb3dSCy Schubert * type that doesn't. */ 1742b15cb3dSCy Schubert #define DNS_ERR_NODATA 70 1752b15cb3dSCy Schubert 1762b15cb3dSCy Schubert #define DNS_IPv4_A 1 1772b15cb3dSCy Schubert #define DNS_PTR 2 1782b15cb3dSCy Schubert #define DNS_IPv6_AAAA 3 1792b15cb3dSCy Schubert 1802b15cb3dSCy Schubert #define DNS_QUERY_NO_SEARCH 1 1812b15cb3dSCy Schubert 182*a466cc55SCy Schubert /* Allow searching */ 1832b15cb3dSCy Schubert #define DNS_OPTION_SEARCH 1 184*a466cc55SCy Schubert /* Parse "nameserver" and add default if no such section */ 1852b15cb3dSCy Schubert #define DNS_OPTION_NAMESERVERS 2 186*a466cc55SCy Schubert /* Parse additional options like: 187*a466cc55SCy Schubert * - timeout: 188*a466cc55SCy Schubert * - getaddrinfo-allow-skew: 189*a466cc55SCy Schubert * - max-timeouts: 190*a466cc55SCy Schubert * - max-inflight: 191*a466cc55SCy Schubert * - attempts: 192*a466cc55SCy Schubert * - randomize-case: 193*a466cc55SCy Schubert * - initial-probe-timeout: 194*a466cc55SCy Schubert */ 1952b15cb3dSCy Schubert #define DNS_OPTION_MISC 4 196*a466cc55SCy Schubert /* Load hosts file (i.e. "/etc/hosts") */ 1972b15cb3dSCy Schubert #define DNS_OPTION_HOSTSFILE 8 198*a466cc55SCy Schubert /** 199*a466cc55SCy Schubert * All above: 200*a466cc55SCy Schubert * - DNS_OPTION_SEARCH 201*a466cc55SCy Schubert * - DNS_OPTION_NAMESERVERS 202*a466cc55SCy Schubert * - DNS_OPTION_MISC 203*a466cc55SCy Schubert * - DNS_OPTION_HOSTSFILE 204*a466cc55SCy Schubert */ 205*a466cc55SCy Schubert #define DNS_OPTIONS_ALL ( \ 206*a466cc55SCy Schubert DNS_OPTION_SEARCH | \ 207*a466cc55SCy Schubert DNS_OPTION_NAMESERVERS | \ 208*a466cc55SCy Schubert DNS_OPTION_MISC | \ 209*a466cc55SCy Schubert DNS_OPTION_HOSTSFILE | \ 210*a466cc55SCy Schubert 0 \ 211*a466cc55SCy Schubert ) 212*a466cc55SCy Schubert /* Do not "default" nameserver (i.e. "127.0.0.1:53") if there is no nameservers 213*a466cc55SCy Schubert * in resolv.conf, (iff DNS_OPTION_NAMESERVERS is set) */ 214*a466cc55SCy Schubert #define DNS_OPTION_NAMESERVERS_NO_DEFAULT 16 2152b15cb3dSCy Schubert 2162b15cb3dSCy Schubert /* Obsolete name for DNS_QUERY_NO_SEARCH */ 2172b15cb3dSCy Schubert #define DNS_NO_SEARCH DNS_QUERY_NO_SEARCH 2182b15cb3dSCy Schubert 2192b15cb3dSCy Schubert /** 2202b15cb3dSCy Schubert * The callback that contains the results from a lookup. 2212b15cb3dSCy Schubert * - result is one of the DNS_ERR_* values (DNS_ERR_NONE for success) 2222b15cb3dSCy Schubert * - type is either DNS_IPv4_A or DNS_PTR or DNS_IPv6_AAAA 2232b15cb3dSCy Schubert * - count contains the number of addresses of form type 2242b15cb3dSCy Schubert * - ttl is the number of seconds the resolution may be cached for. 2252b15cb3dSCy Schubert * - addresses needs to be cast according to type. It will be an array of 2262b15cb3dSCy Schubert * 4-byte sequences for ipv4, or an array of 16-byte sequences for ipv6, 2272b15cb3dSCy Schubert * or a nul-terminated string for PTR. 2282b15cb3dSCy Schubert */ 2292b15cb3dSCy Schubert typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg); 2302b15cb3dSCy Schubert 2312b15cb3dSCy Schubert struct evdns_base; 2322b15cb3dSCy Schubert struct event_base; 2332b15cb3dSCy Schubert 2342b15cb3dSCy Schubert /** Flag for evdns_base_new: process resolv.conf. */ 2352b15cb3dSCy Schubert #define EVDNS_BASE_INITIALIZE_NAMESERVERS 1 2362b15cb3dSCy Schubert /** Flag for evdns_base_new: Do not prevent the libevent event loop from 2372b15cb3dSCy Schubert * exiting when we have no active dns requests. */ 2382b15cb3dSCy Schubert #define EVDNS_BASE_DISABLE_WHEN_INACTIVE 0x8000 239*a466cc55SCy Schubert /** Flag for evdns_base_new: If EVDNS_BASE_INITIALIZE_NAMESERVERS isset, do not 240*a466cc55SCy Schubert * add default nameserver if there are no nameservers in resolv.conf 241*a466cc55SCy Schubert * @see DNS_OPTION_NAMESERVERS_NO_DEFAULT */ 242*a466cc55SCy Schubert #define EVDNS_BASE_NAMESERVERS_NO_DEFAULT 0x10000 2432b15cb3dSCy Schubert 2442b15cb3dSCy Schubert /** 2452b15cb3dSCy Schubert Initialize the asynchronous DNS library. 2462b15cb3dSCy Schubert 2472b15cb3dSCy Schubert This function initializes support for non-blocking name resolution by 2482b15cb3dSCy Schubert calling evdns_resolv_conf_parse() on UNIX and 2492b15cb3dSCy Schubert evdns_config_windows_nameservers() on Windows. 2502b15cb3dSCy Schubert 2512b15cb3dSCy Schubert @param event_base the event base to associate the dns client with 2522b15cb3dSCy Schubert @param flags any of EVDNS_BASE_INITIALIZE_NAMESERVERS| 253*a466cc55SCy Schubert EVDNS_BASE_DISABLE_WHEN_INACTIVE|EVDNS_BASE_NAMESERVERS_NO_DEFAULT 2542b15cb3dSCy Schubert @return evdns_base object if successful, or NULL if an error occurred. 2552b15cb3dSCy Schubert @see evdns_base_free() 2562b15cb3dSCy Schubert */ 2572b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 2582b15cb3dSCy Schubert struct evdns_base * evdns_base_new(struct event_base *event_base, int initialize_nameservers); 2592b15cb3dSCy Schubert 2602b15cb3dSCy Schubert 2612b15cb3dSCy Schubert /** 2622b15cb3dSCy Schubert Shut down the asynchronous DNS resolver and terminate all active requests. 2632b15cb3dSCy Schubert 2642b15cb3dSCy Schubert If the 'fail_requests' option is enabled, all active requests will return 2652b15cb3dSCy Schubert an empty result with the error flag set to DNS_ERR_SHUTDOWN. Otherwise, 2662b15cb3dSCy Schubert the requests will be silently discarded. 2672b15cb3dSCy Schubert 2682b15cb3dSCy Schubert @param evdns_base the evdns base to free 2692b15cb3dSCy Schubert @param fail_requests if zero, active requests will be aborted; if non-zero, 2702b15cb3dSCy Schubert active requests will return DNS_ERR_SHUTDOWN. 2712b15cb3dSCy Schubert @see evdns_base_new() 2722b15cb3dSCy Schubert */ 2732b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 2742b15cb3dSCy Schubert void evdns_base_free(struct evdns_base *base, int fail_requests); 2752b15cb3dSCy Schubert 2762b15cb3dSCy Schubert /** 2772b15cb3dSCy Schubert Remove all hosts entries that have been loaded into the event_base via 2782b15cb3dSCy Schubert evdns_base_load_hosts or via event_base_resolv_conf_parse. 2792b15cb3dSCy Schubert 2802b15cb3dSCy Schubert @param evdns_base the evdns base to remove outdated host addresses from 2812b15cb3dSCy Schubert */ 2822b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 2832b15cb3dSCy Schubert void evdns_base_clear_host_addresses(struct evdns_base *base); 2842b15cb3dSCy Schubert 2852b15cb3dSCy Schubert /** 2862b15cb3dSCy Schubert Convert a DNS error code to a string. 2872b15cb3dSCy Schubert 2882b15cb3dSCy Schubert @param err the DNS error code 2892b15cb3dSCy Schubert @return a string containing an explanation of the error code 2902b15cb3dSCy Schubert */ 2912b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 2922b15cb3dSCy Schubert const char *evdns_err_to_string(int err); 2932b15cb3dSCy Schubert 2942b15cb3dSCy Schubert 2952b15cb3dSCy Schubert /** 2962b15cb3dSCy Schubert Add a nameserver. 2972b15cb3dSCy Schubert 2982b15cb3dSCy Schubert The address should be an IPv4 address in network byte order. 2992b15cb3dSCy Schubert The type of address is chosen so that it matches in_addr.s_addr. 3002b15cb3dSCy Schubert 3012b15cb3dSCy Schubert @param base the evdns_base to which to add the name server 3022b15cb3dSCy Schubert @param address an IP address in network byte order 3032b15cb3dSCy Schubert @return 0 if successful, or -1 if an error occurred 3042b15cb3dSCy Schubert @see evdns_base_nameserver_ip_add() 3052b15cb3dSCy Schubert */ 3062b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 3072b15cb3dSCy Schubert int evdns_base_nameserver_add(struct evdns_base *base, 3082b15cb3dSCy Schubert unsigned long int address); 3092b15cb3dSCy Schubert 3102b15cb3dSCy Schubert /** 3112b15cb3dSCy Schubert Get the number of configured nameservers. 3122b15cb3dSCy Schubert 3132b15cb3dSCy Schubert This returns the number of configured nameservers (not necessarily the 3142b15cb3dSCy Schubert number of running nameservers). This is useful for double-checking 3152b15cb3dSCy Schubert whether our calls to the various nameserver configuration functions 3162b15cb3dSCy Schubert have been successful. 3172b15cb3dSCy Schubert 3182b15cb3dSCy Schubert @param base the evdns_base to which to apply this operation 3192b15cb3dSCy Schubert @return the number of configured nameservers 3202b15cb3dSCy Schubert @see evdns_base_nameserver_add() 3212b15cb3dSCy Schubert */ 3222b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 3232b15cb3dSCy Schubert int evdns_base_count_nameservers(struct evdns_base *base); 3242b15cb3dSCy Schubert 3252b15cb3dSCy Schubert /** 3262b15cb3dSCy Schubert Remove all configured nameservers, and suspend all pending resolves. 3272b15cb3dSCy Schubert 3282b15cb3dSCy Schubert Resolves will not necessarily be re-attempted until evdns_base_resume() is called. 3292b15cb3dSCy Schubert 3302b15cb3dSCy Schubert @param base the evdns_base to which to apply this operation 3312b15cb3dSCy Schubert @return 0 if successful, or -1 if an error occurred 3322b15cb3dSCy Schubert @see evdns_base_resume() 3332b15cb3dSCy Schubert */ 3342b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 3352b15cb3dSCy Schubert int evdns_base_clear_nameservers_and_suspend(struct evdns_base *base); 3362b15cb3dSCy Schubert 3372b15cb3dSCy Schubert 3382b15cb3dSCy Schubert /** 3392b15cb3dSCy Schubert Resume normal operation and continue any suspended resolve requests. 3402b15cb3dSCy Schubert 3412b15cb3dSCy Schubert Re-attempt resolves left in limbo after an earlier call to 3422b15cb3dSCy Schubert evdns_base_clear_nameservers_and_suspend(). 3432b15cb3dSCy Schubert 3442b15cb3dSCy Schubert @param base the evdns_base to which to apply this operation 3452b15cb3dSCy Schubert @return 0 if successful, or -1 if an error occurred 3462b15cb3dSCy Schubert @see evdns_base_clear_nameservers_and_suspend() 3472b15cb3dSCy Schubert */ 3482b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 3492b15cb3dSCy Schubert int evdns_base_resume(struct evdns_base *base); 3502b15cb3dSCy Schubert 3512b15cb3dSCy Schubert /** 3522b15cb3dSCy Schubert Add a nameserver by string address. 3532b15cb3dSCy Schubert 3542b15cb3dSCy Schubert This function parses a n IPv4 or IPv6 address from a string and adds it as a 3552b15cb3dSCy Schubert nameserver. It supports the following formats: 3562b15cb3dSCy Schubert - [IPv6Address]:port 3572b15cb3dSCy Schubert - [IPv6Address] 3582b15cb3dSCy Schubert - IPv6Address 3592b15cb3dSCy Schubert - IPv4Address:port 3602b15cb3dSCy Schubert - IPv4Address 3612b15cb3dSCy Schubert 3622b15cb3dSCy Schubert If no port is specified, it defaults to 53. 3632b15cb3dSCy Schubert 3642b15cb3dSCy Schubert @param base the evdns_base to which to apply this operation 3652b15cb3dSCy Schubert @return 0 if successful, or -1 if an error occurred 3662b15cb3dSCy Schubert @see evdns_base_nameserver_add() 3672b15cb3dSCy Schubert */ 3682b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 3692b15cb3dSCy Schubert int evdns_base_nameserver_ip_add(struct evdns_base *base, 3702b15cb3dSCy Schubert const char *ip_as_string); 3712b15cb3dSCy Schubert 3722b15cb3dSCy Schubert /** 3732b15cb3dSCy Schubert Add a nameserver by sockaddr. 3742b15cb3dSCy Schubert **/ 3752b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 3762b15cb3dSCy Schubert int 3772b15cb3dSCy Schubert evdns_base_nameserver_sockaddr_add(struct evdns_base *base, 3782b15cb3dSCy Schubert const struct sockaddr *sa, ev_socklen_t len, unsigned flags); 3792b15cb3dSCy Schubert 3802b15cb3dSCy Schubert struct evdns_request; 3812b15cb3dSCy Schubert 3822b15cb3dSCy Schubert /** 3832b15cb3dSCy Schubert Lookup an A record for a given name. 3842b15cb3dSCy Schubert 3852b15cb3dSCy Schubert @param base the evdns_base to which to apply this operation 3862b15cb3dSCy Schubert @param name a DNS hostname 3872b15cb3dSCy Schubert @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 3882b15cb3dSCy Schubert @param callback a callback function to invoke when the request is completed 3892b15cb3dSCy Schubert @param ptr an argument to pass to the callback function 3902b15cb3dSCy Schubert @return an evdns_request object if successful, or NULL if an error occurred. 3912b15cb3dSCy Schubert @see evdns_resolve_ipv6(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6(), evdns_cancel_request() 3922b15cb3dSCy Schubert */ 3932b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 3942b15cb3dSCy Schubert struct evdns_request *evdns_base_resolve_ipv4(struct evdns_base *base, const char *name, int flags, evdns_callback_type callback, void *ptr); 3952b15cb3dSCy Schubert 3962b15cb3dSCy Schubert /** 3972b15cb3dSCy Schubert Lookup an AAAA record for a given name. 3982b15cb3dSCy Schubert 3992b15cb3dSCy Schubert @param base the evdns_base to which to apply this operation 4002b15cb3dSCy Schubert @param name a DNS hostname 4012b15cb3dSCy Schubert @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 4022b15cb3dSCy Schubert @param callback a callback function to invoke when the request is completed 4032b15cb3dSCy Schubert @param ptr an argument to pass to the callback function 4042b15cb3dSCy Schubert @return an evdns_request object if successful, or NULL if an error occurred. 4052b15cb3dSCy Schubert @see evdns_resolve_ipv4(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6(), evdns_cancel_request() 4062b15cb3dSCy Schubert */ 4072b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 4082b15cb3dSCy Schubert struct evdns_request *evdns_base_resolve_ipv6(struct evdns_base *base, const char *name, int flags, evdns_callback_type callback, void *ptr); 4092b15cb3dSCy Schubert 4102b15cb3dSCy Schubert struct in_addr; 4112b15cb3dSCy Schubert struct in6_addr; 4122b15cb3dSCy Schubert 4132b15cb3dSCy Schubert /** 4142b15cb3dSCy Schubert Lookup a PTR record for a given IP address. 4152b15cb3dSCy Schubert 4162b15cb3dSCy Schubert @param base the evdns_base to which to apply this operation 4172b15cb3dSCy Schubert @param in an IPv4 address 4182b15cb3dSCy Schubert @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 4192b15cb3dSCy Schubert @param callback a callback function to invoke when the request is completed 4202b15cb3dSCy Schubert @param ptr an argument to pass to the callback function 4212b15cb3dSCy Schubert @return an evdns_request object if successful, or NULL if an error occurred. 4222b15cb3dSCy Schubert @see evdns_resolve_reverse_ipv6(), evdns_cancel_request() 4232b15cb3dSCy Schubert */ 4242b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 4252b15cb3dSCy Schubert struct evdns_request *evdns_base_resolve_reverse(struct evdns_base *base, const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr); 4262b15cb3dSCy Schubert 4272b15cb3dSCy Schubert 4282b15cb3dSCy Schubert /** 4292b15cb3dSCy Schubert Lookup a PTR record for a given IPv6 address. 4302b15cb3dSCy Schubert 4312b15cb3dSCy Schubert @param base the evdns_base to which to apply this operation 4322b15cb3dSCy Schubert @param in an IPv6 address 4332b15cb3dSCy Schubert @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 4342b15cb3dSCy Schubert @param callback a callback function to invoke when the request is completed 4352b15cb3dSCy Schubert @param ptr an argument to pass to the callback function 4362b15cb3dSCy Schubert @return an evdns_request object if successful, or NULL if an error occurred. 4372b15cb3dSCy Schubert @see evdns_resolve_reverse_ipv6(), evdns_cancel_request() 4382b15cb3dSCy Schubert */ 4392b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 4402b15cb3dSCy Schubert 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); 4412b15cb3dSCy Schubert 4422b15cb3dSCy Schubert /** 4432b15cb3dSCy Schubert Cancels a pending DNS resolution request. 4442b15cb3dSCy Schubert 4452b15cb3dSCy Schubert @param base the evdns_base that was used to make the request 4462b15cb3dSCy Schubert @param req the evdns_request that was returned by calling a resolve function 4472b15cb3dSCy Schubert @see evdns_base_resolve_ipv4(), evdns_base_resolve_ipv6, evdns_base_resolve_reverse 4482b15cb3dSCy Schubert */ 4492b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 4502b15cb3dSCy Schubert void evdns_cancel_request(struct evdns_base *base, struct evdns_request *req); 4512b15cb3dSCy Schubert 4522b15cb3dSCy Schubert /** 4532b15cb3dSCy Schubert Set the value of a configuration option. 4542b15cb3dSCy Schubert 4552b15cb3dSCy Schubert The currently available configuration options are: 4562b15cb3dSCy Schubert 4572b15cb3dSCy Schubert ndots, timeout, max-timeouts, max-inflight, attempts, randomize-case, 458*a466cc55SCy Schubert bind-to, initial-probe-timeout, getaddrinfo-allow-skew, 459*a466cc55SCy Schubert so-rcvbuf, so-sndbuf. 4602b15cb3dSCy Schubert 4612b15cb3dSCy Schubert In versions before Libevent 2.0.3-alpha, the option name needed to end with 4622b15cb3dSCy Schubert a colon. 4632b15cb3dSCy Schubert 4642b15cb3dSCy Schubert @param base the evdns_base to which to apply this operation 4652b15cb3dSCy Schubert @param option the name of the configuration option to be modified 4662b15cb3dSCy Schubert @param val the value to be set 4672b15cb3dSCy Schubert @return 0 if successful, or -1 if an error occurred 4682b15cb3dSCy Schubert */ 4692b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 4702b15cb3dSCy Schubert int evdns_base_set_option(struct evdns_base *base, const char *option, const char *val); 4712b15cb3dSCy Schubert 4722b15cb3dSCy Schubert 4732b15cb3dSCy Schubert /** 4742b15cb3dSCy Schubert Parse a resolv.conf file. 4752b15cb3dSCy Schubert 4762b15cb3dSCy Schubert The 'flags' parameter determines what information is parsed from the 4772b15cb3dSCy Schubert resolv.conf file. See the man page for resolv.conf for the format of this 4782b15cb3dSCy Schubert file. 4792b15cb3dSCy Schubert 4802b15cb3dSCy Schubert The following directives are not parsed from the file: sortlist, rotate, 4812b15cb3dSCy Schubert no-check-names, inet6, debug. 4822b15cb3dSCy Schubert 4832b15cb3dSCy Schubert If this function encounters an error, the possible return values are: 1 = 4842b15cb3dSCy Schubert failed to open file, 2 = failed to stat file, 3 = file too large, 4 = out of 4852b15cb3dSCy Schubert memory, 5 = short read from file, 6 = no nameservers listed in the file 4862b15cb3dSCy Schubert 4872b15cb3dSCy Schubert @param base the evdns_base to which to apply this operation 4882b15cb3dSCy Schubert @param flags any of DNS_OPTION_NAMESERVERS|DNS_OPTION_SEARCH|DNS_OPTION_MISC| 489*a466cc55SCy Schubert DNS_OPTION_HOSTSFILE|DNS_OPTIONS_ALL|DNS_OPTION_NAMESERVERS_NO_DEFAULT 4902b15cb3dSCy Schubert @param filename the path to the resolv.conf file 4912b15cb3dSCy Schubert @return 0 if successful, or various positive error codes if an error 4922b15cb3dSCy Schubert occurred (see above) 4932b15cb3dSCy Schubert @see resolv.conf(3), evdns_config_windows_nameservers() 4942b15cb3dSCy Schubert */ 4952b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 4962b15cb3dSCy Schubert int evdns_base_resolv_conf_parse(struct evdns_base *base, int flags, const char *const filename); 4972b15cb3dSCy Schubert 4982b15cb3dSCy Schubert /** 4992b15cb3dSCy Schubert Load an /etc/hosts-style file from 'hosts_fname' into 'base'. 5002b15cb3dSCy Schubert 5012b15cb3dSCy Schubert If hosts_fname is NULL, add minimal entries for localhost, and nothing 5022b15cb3dSCy Schubert else. 5032b15cb3dSCy Schubert 5042b15cb3dSCy Schubert Note that only evdns_getaddrinfo uses the /etc/hosts entries. 5052b15cb3dSCy Schubert 5062b15cb3dSCy Schubert This function does not replace previously loaded hosts entries; to do that, 5072b15cb3dSCy Schubert call evdns_base_clear_host_addresses first. 5082b15cb3dSCy Schubert 5092b15cb3dSCy Schubert Return 0 on success, negative on failure. 5102b15cb3dSCy Schubert */ 5112b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 5122b15cb3dSCy Schubert int evdns_base_load_hosts(struct evdns_base *base, const char *hosts_fname); 5132b15cb3dSCy Schubert 514*a466cc55SCy Schubert #if defined(EVENT_IN_DOXYGEN_) || defined(_WIN32) 5152b15cb3dSCy Schubert /** 5162b15cb3dSCy Schubert Obtain nameserver information using the Windows API. 5172b15cb3dSCy Schubert 5182b15cb3dSCy Schubert Attempt to configure a set of nameservers based on platform settings on 5192b15cb3dSCy Schubert a win32 host. Preferentially tries to use GetNetworkParams; if that fails, 5202b15cb3dSCy Schubert looks in the registry. 5212b15cb3dSCy Schubert 5222b15cb3dSCy Schubert @return 0 if successful, or -1 if an error occurred 5232b15cb3dSCy Schubert @see evdns_resolv_conf_parse() 5242b15cb3dSCy Schubert */ 5252b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 5262b15cb3dSCy Schubert int evdns_base_config_windows_nameservers(struct evdns_base *); 5272b15cb3dSCy Schubert #define EVDNS_BASE_CONFIG_WINDOWS_NAMESERVERS_IMPLEMENTED 5282b15cb3dSCy Schubert #endif 5292b15cb3dSCy Schubert 5302b15cb3dSCy Schubert 5312b15cb3dSCy Schubert /** 5322b15cb3dSCy Schubert Clear the list of search domains. 5332b15cb3dSCy Schubert */ 5342b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 5352b15cb3dSCy Schubert void evdns_base_search_clear(struct evdns_base *base); 5362b15cb3dSCy Schubert 5372b15cb3dSCy Schubert 5382b15cb3dSCy Schubert /** 5392b15cb3dSCy Schubert Add a domain to the list of search domains 5402b15cb3dSCy Schubert 5412b15cb3dSCy Schubert @param domain the domain to be added to the search list 5422b15cb3dSCy Schubert */ 5432b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 5442b15cb3dSCy Schubert void evdns_base_search_add(struct evdns_base *base, const char *domain); 5452b15cb3dSCy Schubert 5462b15cb3dSCy Schubert 5472b15cb3dSCy Schubert /** 5482b15cb3dSCy Schubert Set the 'ndots' parameter for searches. 5492b15cb3dSCy Schubert 5502b15cb3dSCy Schubert Sets the number of dots which, when found in a name, causes 5512b15cb3dSCy Schubert the first query to be without any search domain. 5522b15cb3dSCy Schubert 5532b15cb3dSCy Schubert @param ndots the new ndots parameter 5542b15cb3dSCy Schubert */ 5552b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 5562b15cb3dSCy Schubert void evdns_base_search_ndots_set(struct evdns_base *base, const int ndots); 5572b15cb3dSCy Schubert 5582b15cb3dSCy Schubert /** 5592b15cb3dSCy Schubert A callback that is invoked when a log message is generated 5602b15cb3dSCy Schubert 5612b15cb3dSCy Schubert @param is_warning indicates if the log message is a 'warning' 5622b15cb3dSCy Schubert @param msg the content of the log message 5632b15cb3dSCy Schubert */ 5642b15cb3dSCy Schubert typedef void (*evdns_debug_log_fn_type)(int is_warning, const char *msg); 5652b15cb3dSCy Schubert 5662b15cb3dSCy Schubert 5672b15cb3dSCy Schubert /** 5682b15cb3dSCy Schubert Set the callback function to handle DNS log messages. If this 5692b15cb3dSCy Schubert callback is not set, evdns log messages are handled with the regular 5702b15cb3dSCy Schubert Libevent logging system. 5712b15cb3dSCy Schubert 5722b15cb3dSCy Schubert @param fn the callback to be invoked when a log message is generated 5732b15cb3dSCy Schubert */ 5742b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 5752b15cb3dSCy Schubert void evdns_set_log_fn(evdns_debug_log_fn_type fn); 5762b15cb3dSCy Schubert 5772b15cb3dSCy Schubert /** 5782b15cb3dSCy Schubert Set a callback that will be invoked to generate transaction IDs. By 5792b15cb3dSCy Schubert default, we pick transaction IDs based on the current clock time, which 5802b15cb3dSCy Schubert is bad for security. 5812b15cb3dSCy Schubert 5822b15cb3dSCy Schubert @param fn the new callback, or NULL to use the default. 5832b15cb3dSCy Schubert 5842b15cb3dSCy Schubert NOTE: This function has no effect in Libevent 2.0.4-alpha and later, 5852b15cb3dSCy Schubert since Libevent now provides its own secure RNG. 5862b15cb3dSCy Schubert */ 5872b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 5882b15cb3dSCy Schubert void evdns_set_transaction_id_fn(ev_uint16_t (*fn)(void)); 5892b15cb3dSCy Schubert 5902b15cb3dSCy Schubert /** 5912b15cb3dSCy Schubert Set a callback used to generate random bytes. By default, we use 5922b15cb3dSCy Schubert the same function as passed to evdns_set_transaction_id_fn to generate 5932b15cb3dSCy Schubert bytes two at a time. If a function is provided here, it's also used 5942b15cb3dSCy Schubert to generate transaction IDs. 5952b15cb3dSCy Schubert 5962b15cb3dSCy Schubert NOTE: This function has no effect in Libevent 2.0.4-alpha and later, 5972b15cb3dSCy Schubert since Libevent now provides its own secure RNG. 5982b15cb3dSCy Schubert */ 5992b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 6002b15cb3dSCy Schubert void evdns_set_random_bytes_fn(void (*fn)(char *, size_t)); 6012b15cb3dSCy Schubert 6022b15cb3dSCy Schubert /* 6032b15cb3dSCy Schubert * Functions used to implement a DNS server. 6042b15cb3dSCy Schubert */ 6052b15cb3dSCy Schubert 6062b15cb3dSCy Schubert struct evdns_server_request; 6072b15cb3dSCy Schubert struct evdns_server_question; 6082b15cb3dSCy Schubert 6092b15cb3dSCy Schubert /** 6102b15cb3dSCy Schubert A callback to implement a DNS server. The callback function receives a DNS 6112b15cb3dSCy Schubert request. It should then optionally add a number of answers to the reply 6122b15cb3dSCy Schubert using the evdns_server_request_add_*_reply functions, before calling either 6132b15cb3dSCy Schubert evdns_server_request_respond to send the reply back, or 6142b15cb3dSCy Schubert evdns_server_request_drop to decline to answer the request. 6152b15cb3dSCy Schubert 6162b15cb3dSCy Schubert @param req A newly received request 6172b15cb3dSCy Schubert @param user_data A pointer that was passed to 6182b15cb3dSCy Schubert evdns_add_server_port_with_base(). 6192b15cb3dSCy Schubert */ 6202b15cb3dSCy Schubert typedef void (*evdns_request_callback_fn_type)(struct evdns_server_request *, void *); 6212b15cb3dSCy Schubert #define EVDNS_ANSWER_SECTION 0 6222b15cb3dSCy Schubert #define EVDNS_AUTHORITY_SECTION 1 6232b15cb3dSCy Schubert #define EVDNS_ADDITIONAL_SECTION 2 6242b15cb3dSCy Schubert 6252b15cb3dSCy Schubert #define EVDNS_TYPE_A 1 6262b15cb3dSCy Schubert #define EVDNS_TYPE_NS 2 6272b15cb3dSCy Schubert #define EVDNS_TYPE_CNAME 5 6282b15cb3dSCy Schubert #define EVDNS_TYPE_SOA 6 6292b15cb3dSCy Schubert #define EVDNS_TYPE_PTR 12 6302b15cb3dSCy Schubert #define EVDNS_TYPE_MX 15 6312b15cb3dSCy Schubert #define EVDNS_TYPE_TXT 16 6322b15cb3dSCy Schubert #define EVDNS_TYPE_AAAA 28 6332b15cb3dSCy Schubert 6342b15cb3dSCy Schubert #define EVDNS_QTYPE_AXFR 252 6352b15cb3dSCy Schubert #define EVDNS_QTYPE_ALL 255 6362b15cb3dSCy Schubert 6372b15cb3dSCy Schubert #define EVDNS_CLASS_INET 1 6382b15cb3dSCy Schubert 6392b15cb3dSCy Schubert /* flags that can be set in answers; as part of the err parameter */ 6402b15cb3dSCy Schubert #define EVDNS_FLAGS_AA 0x400 6412b15cb3dSCy Schubert #define EVDNS_FLAGS_RD 0x080 6422b15cb3dSCy Schubert 6432b15cb3dSCy Schubert /** Create a new DNS server port. 6442b15cb3dSCy Schubert 6452b15cb3dSCy Schubert @param base The event base to handle events for the server port. 6462b15cb3dSCy Schubert @param socket A UDP socket to accept DNS requests. 6472b15cb3dSCy Schubert @param flags Always 0 for now. 6482b15cb3dSCy Schubert @param callback A function to invoke whenever we get a DNS request 6492b15cb3dSCy Schubert on the socket. 6502b15cb3dSCy Schubert @param user_data Data to pass to the callback. 651*a466cc55SCy Schubert @return an evdns_server_port structure for this server port or NULL if 652*a466cc55SCy Schubert an error occurred. 6532b15cb3dSCy Schubert */ 6542b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 6552b15cb3dSCy Schubert 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); 6562b15cb3dSCy Schubert /** Close down a DNS server port, and free associated structures. */ 6572b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 6582b15cb3dSCy Schubert void evdns_close_server_port(struct evdns_server_port *port); 6592b15cb3dSCy Schubert 6602b15cb3dSCy Schubert /** Sets some flags in a reply we're building. 6612b15cb3dSCy Schubert Allows setting of the AA or RD flags 6622b15cb3dSCy Schubert */ 6632b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 6642b15cb3dSCy Schubert void evdns_server_request_set_flags(struct evdns_server_request *req, int flags); 6652b15cb3dSCy Schubert 6662b15cb3dSCy Schubert /* Functions to add an answer to an in-progress DNS reply. 6672b15cb3dSCy Schubert */ 6682b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 6692b15cb3dSCy Schubert 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); 6702b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 6712b15cb3dSCy Schubert int evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl); 6722b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 6732b15cb3dSCy Schubert int evdns_server_request_add_aaaa_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl); 6742b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 6752b15cb3dSCy Schubert 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); 6762b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 6772b15cb3dSCy Schubert int evdns_server_request_add_cname_reply(struct evdns_server_request *req, const char *name, const char *cname, int ttl); 6782b15cb3dSCy Schubert 6792b15cb3dSCy Schubert /** 6802b15cb3dSCy Schubert Send back a response to a DNS request, and free the request structure. 6812b15cb3dSCy Schubert */ 6822b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 6832b15cb3dSCy Schubert int evdns_server_request_respond(struct evdns_server_request *req, int err); 6842b15cb3dSCy Schubert /** 6852b15cb3dSCy Schubert Free a DNS request without sending back a reply. 6862b15cb3dSCy Schubert */ 6872b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 6882b15cb3dSCy Schubert int evdns_server_request_drop(struct evdns_server_request *req); 6892b15cb3dSCy Schubert struct sockaddr; 6902b15cb3dSCy Schubert /** 6912b15cb3dSCy Schubert Get the address that made a DNS request. 6922b15cb3dSCy Schubert */ 6932b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 6942b15cb3dSCy Schubert int evdns_server_request_get_requesting_addr(struct evdns_server_request *req, struct sockaddr *sa, int addr_len); 6952b15cb3dSCy Schubert 6962b15cb3dSCy Schubert /** Callback for evdns_getaddrinfo. */ 6972b15cb3dSCy Schubert typedef void (*evdns_getaddrinfo_cb)(int result, struct evutil_addrinfo *res, void *arg); 6982b15cb3dSCy Schubert 6992b15cb3dSCy Schubert struct evdns_base; 7002b15cb3dSCy Schubert struct evdns_getaddrinfo_request; 7012b15cb3dSCy Schubert /** Make a non-blocking getaddrinfo request using the dns_base in 'dns_base'. 7022b15cb3dSCy Schubert * 7032b15cb3dSCy Schubert * If we can answer the request immediately (with an error or not!), then we 7042b15cb3dSCy Schubert * invoke cb immediately and return NULL. Otherwise we return 7052b15cb3dSCy Schubert * an evdns_getaddrinfo_request and invoke cb later. 7062b15cb3dSCy Schubert * 7072b15cb3dSCy Schubert * When the callback is invoked, we pass as its first argument the error code 7082b15cb3dSCy Schubert * that getaddrinfo would return (or 0 for no error). As its second argument, 7092b15cb3dSCy Schubert * we pass the evutil_addrinfo structures we found (or NULL on error). We 7102b15cb3dSCy Schubert * pass 'arg' as the third argument. 7112b15cb3dSCy Schubert * 7122b15cb3dSCy Schubert * Limitations: 7132b15cb3dSCy Schubert * 7142b15cb3dSCy Schubert * - The AI_V4MAPPED and AI_ALL flags are not currently implemented. 7152b15cb3dSCy Schubert * - For ai_socktype, we only handle SOCKTYPE_STREAM, SOCKTYPE_UDP, and 0. 7162b15cb3dSCy Schubert * - For ai_protocol, we only handle IPPROTO_TCP, IPPROTO_UDP, and 0. 7172b15cb3dSCy Schubert */ 7182b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 7192b15cb3dSCy Schubert struct evdns_getaddrinfo_request *evdns_getaddrinfo( 7202b15cb3dSCy Schubert struct evdns_base *dns_base, 7212b15cb3dSCy Schubert const char *nodename, const char *servname, 7222b15cb3dSCy Schubert const struct evutil_addrinfo *hints_in, 7232b15cb3dSCy Schubert evdns_getaddrinfo_cb cb, void *arg); 7242b15cb3dSCy Schubert 7252b15cb3dSCy Schubert /* Cancel an in-progress evdns_getaddrinfo. This MUST NOT be called after the 7262b15cb3dSCy Schubert * getaddrinfo's callback has been invoked. The resolves will be canceled, 7272b15cb3dSCy Schubert * and the callback will be invoked with the error EVUTIL_EAI_CANCEL. */ 7282b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 7292b15cb3dSCy Schubert void evdns_getaddrinfo_cancel(struct evdns_getaddrinfo_request *req); 7302b15cb3dSCy Schubert 731a25439b6SCy Schubert /** 732a25439b6SCy Schubert Retrieve the address of the 'idx'th configured nameserver. 733a25439b6SCy Schubert 734a25439b6SCy Schubert @param base The evdns_base to examine. 735a25439b6SCy Schubert @param idx The index of the nameserver to get the address of. 736a25439b6SCy Schubert @param sa A location to receive the server's address. 737a25439b6SCy Schubert @param len The number of bytes available at sa. 738a25439b6SCy Schubert 739a25439b6SCy Schubert @return the number of bytes written into sa on success. On failure, returns 740a25439b6SCy Schubert -1 if idx is greater than the number of configured nameservers, or a 741a25439b6SCy Schubert value greater than 'len' if len was not high enough. 742a25439b6SCy Schubert */ 743a25439b6SCy Schubert EVENT2_EXPORT_SYMBOL 744a25439b6SCy Schubert int evdns_base_get_nameserver_addr(struct evdns_base *base, int idx, 745a25439b6SCy Schubert struct sockaddr *sa, ev_socklen_t len); 746a25439b6SCy Schubert 7472b15cb3dSCy Schubert #ifdef __cplusplus 7482b15cb3dSCy Schubert } 7492b15cb3dSCy Schubert #endif 7502b15cb3dSCy Schubert 7512b15cb3dSCy Schubert #endif /* !EVENT2_DNS_H_INCLUDED_ */ 752