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