1290001Sglebius/* 2290001Sglebius * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu> 3290001Sglebius * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4290001Sglebius * 5290001Sglebius * Redistribution and use in source and binary forms, with or without 6290001Sglebius * modification, are permitted provided that the following conditions 7290001Sglebius * are met: 8290001Sglebius * 1. Redistributions of source code must retain the above copyright 9290001Sglebius * notice, this list of conditions and the following disclaimer. 10290001Sglebius * 2. Redistributions in binary form must reproduce the above copyright 11290001Sglebius * notice, this list of conditions and the following disclaimer in the 12290001Sglebius * documentation and/or other materials provided with the distribution. 13290001Sglebius * 3. The name of the author may not be used to endorse or promote products 14290001Sglebius * derived from this software without specific prior written permission. 15290001Sglebius * 16290001Sglebius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17290001Sglebius * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18290001Sglebius * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19290001Sglebius * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20290001Sglebius * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21290001Sglebius * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22290001Sglebius * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23290001Sglebius * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24290001Sglebius * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25290001Sglebius * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26290001Sglebius */ 27290001Sglebius#ifndef EVENT2_DNS_COMPAT_H_INCLUDED_ 28290001Sglebius#define EVENT2_DNS_COMPAT_H_INCLUDED_ 29290001Sglebius 30290001Sglebius/** @file event2/dns_compat.h 31290001Sglebius 32290001Sglebius Potentially non-threadsafe versions of the functions in dns.h: provided 33290001Sglebius only for backwards compatibility. 34290001Sglebius 35290001Sglebius 36290001Sglebius */ 37290001Sglebius 38290001Sglebius#ifdef __cplusplus 39290001Sglebiusextern "C" { 40290001Sglebius#endif 41290001Sglebius 42290001Sglebius#include <event2/event-config.h> 43290001Sglebius#ifdef EVENT__HAVE_SYS_TYPES_H 44290001Sglebius#include <sys/types.h> 45290001Sglebius#endif 46290001Sglebius#ifdef EVENT__HAVE_SYS_TIME_H 47290001Sglebius#include <sys/time.h> 48290001Sglebius#endif 49290001Sglebius 50290001Sglebius/* For int types. */ 51290001Sglebius#include <event2/util.h> 52290001Sglebius 53290001Sglebius/** 54290001Sglebius Initialize the asynchronous DNS library. 55290001Sglebius 56290001Sglebius This function initializes support for non-blocking name resolution by 57290001Sglebius calling evdns_resolv_conf_parse() on UNIX and 58290001Sglebius evdns_config_windows_nameservers() on Windows. 59290001Sglebius 60290001Sglebius @deprecated This function is deprecated because it always uses the current 61290001Sglebius event base, and is easily confused by multiple calls to event_init(), and 62290001Sglebius so is not safe for multithreaded use. Additionally, it allocates a global 63290001Sglebius structure that only one thread can use. The replacement is 64290001Sglebius evdns_base_new(). 65290001Sglebius 66290001Sglebius @return 0 if successful, or -1 if an error occurred 67290001Sglebius @see evdns_shutdown() 68290001Sglebius */ 69290001Sglebiusint evdns_init(void); 70290001Sglebius 71290001Sglebiusstruct evdns_base; 72290001Sglebius/** 73290001Sglebius Return the global evdns_base created by event_init() and used by the other 74290001Sglebius deprecated functions. 75290001Sglebius 76290001Sglebius @deprecated This function is deprecated because use of the global 77290001Sglebius evdns_base is error-prone. 78290001Sglebius */ 79290001Sglebiusstruct evdns_base *evdns_get_global_base(void); 80290001Sglebius 81290001Sglebius/** 82290001Sglebius Shut down the asynchronous DNS resolver and terminate all active requests. 83290001Sglebius 84290001Sglebius If the 'fail_requests' option is enabled, all active requests will return 85290001Sglebius an empty result with the error flag set to DNS_ERR_SHUTDOWN. Otherwise, 86290001Sglebius the requests will be silently discarded. 87290001Sglebius 88290001Sglebius @deprecated This function is deprecated because it does not allow the 89290001Sglebius caller to specify which evdns_base it applies to. The recommended 90290001Sglebius function is evdns_base_shutdown(). 91290001Sglebius 92290001Sglebius @param fail_requests if zero, active requests will be aborted; if non-zero, 93290001Sglebius active requests will return DNS_ERR_SHUTDOWN. 94290001Sglebius @see evdns_init() 95290001Sglebius */ 96290001Sglebiusvoid evdns_shutdown(int fail_requests); 97290001Sglebius 98290001Sglebius/** 99290001Sglebius Add a nameserver. 100290001Sglebius 101290001Sglebius The address should be an IPv4 address in network byte order. 102290001Sglebius The type of address is chosen so that it matches in_addr.s_addr. 103290001Sglebius 104290001Sglebius @deprecated This function is deprecated because it does not allow the 105290001Sglebius caller to specify which evdns_base it applies to. The recommended 106290001Sglebius function is evdns_base_nameserver_add(). 107290001Sglebius 108290001Sglebius @param address an IP address in network byte order 109290001Sglebius @return 0 if successful, or -1 if an error occurred 110290001Sglebius @see evdns_nameserver_ip_add() 111290001Sglebius */ 112290001Sglebiusint evdns_nameserver_add(unsigned long int address); 113290001Sglebius 114290001Sglebius/** 115290001Sglebius Get the number of configured nameservers. 116290001Sglebius 117290001Sglebius This returns the number of configured nameservers (not necessarily the 118290001Sglebius number of running nameservers). This is useful for double-checking 119290001Sglebius whether our calls to the various nameserver configuration functions 120290001Sglebius have been successful. 121290001Sglebius 122290001Sglebius @deprecated This function is deprecated because it does not allow the 123290001Sglebius caller to specify which evdns_base it applies to. The recommended 124290001Sglebius function is evdns_base_count_nameservers(). 125290001Sglebius 126290001Sglebius @return the number of configured nameservers 127290001Sglebius @see evdns_nameserver_add() 128290001Sglebius */ 129290001Sglebiusint evdns_count_nameservers(void); 130290001Sglebius 131290001Sglebius/** 132290001Sglebius Remove all configured nameservers, and suspend all pending resolves. 133290001Sglebius 134290001Sglebius Resolves will not necessarily be re-attempted until evdns_resume() is called. 135290001Sglebius 136290001Sglebius @deprecated This function is deprecated because it does not allow the 137290001Sglebius caller to specify which evdns_base it applies to. The recommended 138290001Sglebius function is evdns_base_clear_nameservers_and_suspend(). 139290001Sglebius 140290001Sglebius @return 0 if successful, or -1 if an error occurred 141290001Sglebius @see evdns_resume() 142290001Sglebius */ 143290001Sglebiusint evdns_clear_nameservers_and_suspend(void); 144290001Sglebius 145290001Sglebius/** 146290001Sglebius Resume normal operation and continue any suspended resolve requests. 147290001Sglebius 148290001Sglebius Re-attempt resolves left in limbo after an earlier call to 149290001Sglebius evdns_clear_nameservers_and_suspend(). 150290001Sglebius 151290001Sglebius @deprecated This function is deprecated because it does not allow the 152290001Sglebius caller to specify which evdns_base it applies to. The recommended 153290001Sglebius function is evdns_base_resume(). 154290001Sglebius 155290001Sglebius @return 0 if successful, or -1 if an error occurred 156290001Sglebius @see evdns_clear_nameservers_and_suspend() 157290001Sglebius */ 158290001Sglebiusint evdns_resume(void); 159290001Sglebius 160290001Sglebius/** 161290001Sglebius Add a nameserver. 162290001Sglebius 163290001Sglebius This wraps the evdns_nameserver_add() function by parsing a string as an IP 164290001Sglebius address and adds it as a nameserver. 165290001Sglebius 166290001Sglebius @deprecated This function is deprecated because it does not allow the 167290001Sglebius caller to specify which evdns_base it applies to. The recommended 168290001Sglebius function is evdns_base_nameserver_ip_add(). 169290001Sglebius 170290001Sglebius @return 0 if successful, or -1 if an error occurred 171290001Sglebius @see evdns_nameserver_add() 172290001Sglebius */ 173290001Sglebiusint evdns_nameserver_ip_add(const char *ip_as_string); 174290001Sglebius 175290001Sglebius/** 176290001Sglebius Lookup an A record for a given name. 177290001Sglebius 178290001Sglebius @deprecated This function is deprecated because it does not allow the 179290001Sglebius caller to specify which evdns_base it applies to. The recommended 180290001Sglebius function is evdns_base_resolve_ipv4(). 181290001Sglebius 182290001Sglebius @param name a DNS hostname 183290001Sglebius @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 184290001Sglebius @param callback a callback function to invoke when the request is completed 185290001Sglebius @param ptr an argument to pass to the callback function 186290001Sglebius @return 0 if successful, or -1 if an error occurred 187290001Sglebius @see evdns_resolve_ipv6(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6() 188290001Sglebius */ 189290001Sglebiusint evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr); 190290001Sglebius 191290001Sglebius/** 192290001Sglebius Lookup an AAAA record for a given name. 193290001Sglebius 194290001Sglebius @param name a DNS hostname 195290001Sglebius @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 196290001Sglebius @param callback a callback function to invoke when the request is completed 197290001Sglebius @param ptr an argument to pass to the callback function 198290001Sglebius @return 0 if successful, or -1 if an error occurred 199290001Sglebius @see evdns_resolve_ipv4(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6() 200290001Sglebius */ 201290001Sglebiusint evdns_resolve_ipv6(const char *name, int flags, evdns_callback_type callback, void *ptr); 202290001Sglebius 203290001Sglebiusstruct in_addr; 204290001Sglebiusstruct in6_addr; 205290001Sglebius 206290001Sglebius/** 207290001Sglebius Lookup a PTR record for a given IP address. 208290001Sglebius 209290001Sglebius @deprecated This function is deprecated because it does not allow the 210290001Sglebius caller to specify which evdns_base it applies to. The recommended 211290001Sglebius function is evdns_base_resolve_reverse(). 212290001Sglebius 213290001Sglebius @param in an IPv4 address 214290001Sglebius @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 215290001Sglebius @param callback a callback function to invoke when the request is completed 216290001Sglebius @param ptr an argument to pass to the callback function 217290001Sglebius @return 0 if successful, or -1 if an error occurred 218290001Sglebius @see evdns_resolve_reverse_ipv6() 219290001Sglebius */ 220290001Sglebiusint evdns_resolve_reverse(const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr); 221290001Sglebius 222290001Sglebius/** 223290001Sglebius Lookup a PTR record for a given IPv6 address. 224290001Sglebius 225290001Sglebius @deprecated This function is deprecated because it does not allow the 226290001Sglebius caller to specify which evdns_base it applies to. The recommended 227290001Sglebius function is evdns_base_resolve_reverse_ipv6(). 228290001Sglebius 229290001Sglebius @param in an IPv6 address 230290001Sglebius @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 231290001Sglebius @param callback a callback function to invoke when the request is completed 232290001Sglebius @param ptr an argument to pass to the callback function 233290001Sglebius @return 0 if successful, or -1 if an error occurred 234290001Sglebius @see evdns_resolve_reverse_ipv6() 235290001Sglebius */ 236290001Sglebiusint evdns_resolve_reverse_ipv6(const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr); 237290001Sglebius 238290001Sglebius/** 239290001Sglebius Set the value of a configuration option. 240290001Sglebius 241290001Sglebius The currently available configuration options are: 242290001Sglebius 243290001Sglebius ndots, timeout, max-timeouts, max-inflight, and attempts 244290001Sglebius 245290001Sglebius @deprecated This function is deprecated because it does not allow the 246290001Sglebius caller to specify which evdns_base it applies to. The recommended 247290001Sglebius function is evdns_base_set_option(). 248290001Sglebius 249290001Sglebius @param option the name of the configuration option to be modified 250290001Sglebius @param val the value to be set 251290001Sglebius @param flags Ignored. 252290001Sglebius @return 0 if successful, or -1 if an error occurred 253290001Sglebius */ 254290001Sglebiusint evdns_set_option(const char *option, const char *val, int flags); 255290001Sglebius 256290001Sglebius/** 257290001Sglebius Parse a resolv.conf file. 258290001Sglebius 259290001Sglebius The 'flags' parameter determines what information is parsed from the 260290001Sglebius resolv.conf file. See the man page for resolv.conf for the format of this 261290001Sglebius file. 262290001Sglebius 263290001Sglebius The following directives are not parsed from the file: sortlist, rotate, 264290001Sglebius no-check-names, inet6, debug. 265290001Sglebius 266290001Sglebius If this function encounters an error, the possible return values are: 1 = 267290001Sglebius failed to open file, 2 = failed to stat file, 3 = file too large, 4 = out of 268290001Sglebius memory, 5 = short read from file, 6 = no nameservers listed in the file 269290001Sglebius 270290001Sglebius @deprecated This function is deprecated because it does not allow the 271290001Sglebius caller to specify which evdns_base it applies to. The recommended 272290001Sglebius function is evdns_base_resolv_conf_parse(). 273290001Sglebius 274290001Sglebius @param flags any of DNS_OPTION_NAMESERVERS|DNS_OPTION_SEARCH|DNS_OPTION_MISC| 275290001Sglebius DNS_OPTIONS_ALL 276290001Sglebius @param filename the path to the resolv.conf file 277290001Sglebius @return 0 if successful, or various positive error codes if an error 278290001Sglebius occurred (see above) 279290001Sglebius @see resolv.conf(3), evdns_config_windows_nameservers() 280290001Sglebius */ 281290001Sglebiusint evdns_resolv_conf_parse(int flags, const char *const filename); 282290001Sglebius 283290001Sglebius/** 284290001Sglebius Clear the list of search domains. 285290001Sglebius 286290001Sglebius @deprecated This function is deprecated because it does not allow the 287290001Sglebius caller to specify which evdns_base it applies to. The recommended 288290001Sglebius function is evdns_base_search_clear(). 289290001Sglebius */ 290290001Sglebiusvoid evdns_search_clear(void); 291290001Sglebius 292290001Sglebius/** 293290001Sglebius Add a domain to the list of search domains 294290001Sglebius 295290001Sglebius @deprecated This function is deprecated because it does not allow the 296290001Sglebius caller to specify which evdns_base it applies to. The recommended 297290001Sglebius function is evdns_base_search_add(). 298290001Sglebius 299290001Sglebius @param domain the domain to be added to the search list 300290001Sglebius */ 301290001Sglebiusvoid evdns_search_add(const char *domain); 302290001Sglebius 303290001Sglebius/** 304290001Sglebius Set the 'ndots' parameter for searches. 305290001Sglebius 306290001Sglebius Sets the number of dots which, when found in a name, causes 307290001Sglebius the first query to be without any search domain. 308290001Sglebius 309290001Sglebius @deprecated This function is deprecated because it does not allow the 310290001Sglebius caller to specify which evdns_base it applies to. The recommended 311290001Sglebius function is evdns_base_search_ndots_set(). 312290001Sglebius 313290001Sglebius @param ndots the new ndots parameter 314290001Sglebius */ 315290001Sglebiusvoid evdns_search_ndots_set(const int ndots); 316290001Sglebius 317290001Sglebius/** 318290001Sglebius As evdns_server_new_with_base. 319290001Sglebius 320290001Sglebius @deprecated This function is deprecated because it does not allow the 321290001Sglebius caller to specify which even_base it uses. The recommended 322290001Sglebius function is evdns_add_server_port_with_base(). 323290001Sglebius 324290001Sglebius*/ 325290001Sglebiusstruct evdns_server_port *evdns_add_server_port(evutil_socket_t socket, int flags, evdns_request_callback_fn_type callback, void *user_data); 326290001Sglebius 327290001Sglebius#ifdef _WIN32 328290001Sglebiusint evdns_config_windows_nameservers(void); 329290001Sglebius#define EVDNS_CONFIG_WINDOWS_NAMESERVERS_IMPLEMENTED 330290001Sglebius#endif 331290001Sglebius 332290001Sglebius#ifdef __cplusplus 333290001Sglebius} 334290001Sglebius#endif 335290001Sglebius 336290001Sglebius#endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ 337