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 #ifndef EVENT2_DNS_COMPAT_H_INCLUDED_ 28c43e99fdSEd Maste #define EVENT2_DNS_COMPAT_H_INCLUDED_ 29c43e99fdSEd Maste 30c43e99fdSEd Maste /** @file event2/dns_compat.h 31c43e99fdSEd Maste 32c43e99fdSEd Maste Potentially non-threadsafe versions of the functions in dns.h: provided 33c43e99fdSEd Maste only for backwards compatibility. 34c43e99fdSEd Maste 35c43e99fdSEd Maste 36c43e99fdSEd Maste */ 37c43e99fdSEd Maste 38c43e99fdSEd Maste #ifdef __cplusplus 39c43e99fdSEd Maste extern "C" { 40c43e99fdSEd Maste #endif 41c43e99fdSEd Maste 42c43e99fdSEd Maste #include <event2/event-config.h> 43c43e99fdSEd Maste #ifdef EVENT__HAVE_SYS_TYPES_H 44c43e99fdSEd Maste #include <sys/types.h> 45c43e99fdSEd Maste #endif 46c43e99fdSEd Maste #ifdef EVENT__HAVE_SYS_TIME_H 47c43e99fdSEd Maste #include <sys/time.h> 48c43e99fdSEd Maste #endif 49c43e99fdSEd Maste 50c43e99fdSEd Maste /* For int types. */ 51c43e99fdSEd Maste #include <event2/util.h> 52*b50261e2SCy Schubert #include <event2/visibility.h> 53c43e99fdSEd Maste 54c43e99fdSEd Maste /** 55c43e99fdSEd Maste Initialize the asynchronous DNS library. 56c43e99fdSEd Maste 57c43e99fdSEd Maste This function initializes support for non-blocking name resolution by 58c43e99fdSEd Maste calling evdns_resolv_conf_parse() on UNIX and 59c43e99fdSEd Maste evdns_config_windows_nameservers() on Windows. 60c43e99fdSEd Maste 61c43e99fdSEd Maste @deprecated This function is deprecated because it always uses the current 62c43e99fdSEd Maste event base, and is easily confused by multiple calls to event_init(), and 63c43e99fdSEd Maste so is not safe for multithreaded use. Additionally, it allocates a global 64c43e99fdSEd Maste structure that only one thread can use. The replacement is 65c43e99fdSEd Maste evdns_base_new(). 66c43e99fdSEd Maste 67c43e99fdSEd Maste @return 0 if successful, or -1 if an error occurred 68c43e99fdSEd Maste @see evdns_shutdown() 69c43e99fdSEd Maste */ 70*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 71c43e99fdSEd Maste int evdns_init(void); 72c43e99fdSEd Maste 73c43e99fdSEd Maste struct evdns_base; 74c43e99fdSEd Maste /** 75c43e99fdSEd Maste Return the global evdns_base created by event_init() and used by the other 76c43e99fdSEd Maste deprecated functions. 77c43e99fdSEd Maste 78c43e99fdSEd Maste @deprecated This function is deprecated because use of the global 79c43e99fdSEd Maste evdns_base is error-prone. 80c43e99fdSEd Maste */ 81*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 82c43e99fdSEd Maste struct evdns_base *evdns_get_global_base(void); 83c43e99fdSEd Maste 84c43e99fdSEd Maste /** 85c43e99fdSEd Maste Shut down the asynchronous DNS resolver and terminate all active requests. 86c43e99fdSEd Maste 87c43e99fdSEd Maste If the 'fail_requests' option is enabled, all active requests will return 88c43e99fdSEd Maste an empty result with the error flag set to DNS_ERR_SHUTDOWN. Otherwise, 89c43e99fdSEd Maste the requests will be silently discarded. 90c43e99fdSEd Maste 91c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 92c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 93c43e99fdSEd Maste function is evdns_base_shutdown(). 94c43e99fdSEd Maste 95c43e99fdSEd Maste @param fail_requests if zero, active requests will be aborted; if non-zero, 96c43e99fdSEd Maste active requests will return DNS_ERR_SHUTDOWN. 97c43e99fdSEd Maste @see evdns_init() 98c43e99fdSEd Maste */ 99*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 100c43e99fdSEd Maste void evdns_shutdown(int fail_requests); 101c43e99fdSEd Maste 102c43e99fdSEd Maste /** 103c43e99fdSEd Maste Add a nameserver. 104c43e99fdSEd Maste 105c43e99fdSEd Maste The address should be an IPv4 address in network byte order. 106c43e99fdSEd Maste The type of address is chosen so that it matches in_addr.s_addr. 107c43e99fdSEd Maste 108c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 109c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 110c43e99fdSEd Maste function is evdns_base_nameserver_add(). 111c43e99fdSEd Maste 112c43e99fdSEd Maste @param address an IP address in network byte order 113c43e99fdSEd Maste @return 0 if successful, or -1 if an error occurred 114c43e99fdSEd Maste @see evdns_nameserver_ip_add() 115c43e99fdSEd Maste */ 116*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 117c43e99fdSEd Maste int evdns_nameserver_add(unsigned long int address); 118c43e99fdSEd Maste 119c43e99fdSEd Maste /** 120c43e99fdSEd Maste Get the number of configured nameservers. 121c43e99fdSEd Maste 122c43e99fdSEd Maste This returns the number of configured nameservers (not necessarily the 123c43e99fdSEd Maste number of running nameservers). This is useful for double-checking 124c43e99fdSEd Maste whether our calls to the various nameserver configuration functions 125c43e99fdSEd Maste have been successful. 126c43e99fdSEd Maste 127c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 128c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 129c43e99fdSEd Maste function is evdns_base_count_nameservers(). 130c43e99fdSEd Maste 131c43e99fdSEd Maste @return the number of configured nameservers 132c43e99fdSEd Maste @see evdns_nameserver_add() 133c43e99fdSEd Maste */ 134*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 135c43e99fdSEd Maste int evdns_count_nameservers(void); 136c43e99fdSEd Maste 137c43e99fdSEd Maste /** 138c43e99fdSEd Maste Remove all configured nameservers, and suspend all pending resolves. 139c43e99fdSEd Maste 140c43e99fdSEd Maste Resolves will not necessarily be re-attempted until evdns_resume() is called. 141c43e99fdSEd Maste 142c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 143c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 144c43e99fdSEd Maste function is evdns_base_clear_nameservers_and_suspend(). 145c43e99fdSEd Maste 146c43e99fdSEd Maste @return 0 if successful, or -1 if an error occurred 147c43e99fdSEd Maste @see evdns_resume() 148c43e99fdSEd Maste */ 149*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 150c43e99fdSEd Maste int evdns_clear_nameservers_and_suspend(void); 151c43e99fdSEd Maste 152c43e99fdSEd Maste /** 153c43e99fdSEd Maste Resume normal operation and continue any suspended resolve requests. 154c43e99fdSEd Maste 155c43e99fdSEd Maste Re-attempt resolves left in limbo after an earlier call to 156c43e99fdSEd Maste evdns_clear_nameservers_and_suspend(). 157c43e99fdSEd Maste 158c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 159c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 160c43e99fdSEd Maste function is evdns_base_resume(). 161c43e99fdSEd Maste 162c43e99fdSEd Maste @return 0 if successful, or -1 if an error occurred 163c43e99fdSEd Maste @see evdns_clear_nameservers_and_suspend() 164c43e99fdSEd Maste */ 165*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 166c43e99fdSEd Maste int evdns_resume(void); 167c43e99fdSEd Maste 168c43e99fdSEd Maste /** 169c43e99fdSEd Maste Add a nameserver. 170c43e99fdSEd Maste 171c43e99fdSEd Maste This wraps the evdns_nameserver_add() function by parsing a string as an IP 172c43e99fdSEd Maste address and adds it as a nameserver. 173c43e99fdSEd Maste 174c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 175c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 176c43e99fdSEd Maste function is evdns_base_nameserver_ip_add(). 177c43e99fdSEd Maste 178c43e99fdSEd Maste @return 0 if successful, or -1 if an error occurred 179c43e99fdSEd Maste @see evdns_nameserver_add() 180c43e99fdSEd Maste */ 181*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 182c43e99fdSEd Maste int evdns_nameserver_ip_add(const char *ip_as_string); 183c43e99fdSEd Maste 184c43e99fdSEd Maste /** 185c43e99fdSEd Maste Lookup an A record for a given name. 186c43e99fdSEd Maste 187c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 188c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 189c43e99fdSEd Maste function is evdns_base_resolve_ipv4(). 190c43e99fdSEd Maste 191c43e99fdSEd Maste @param name a DNS hostname 192c43e99fdSEd Maste @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 193c43e99fdSEd Maste @param callback a callback function to invoke when the request is completed 194c43e99fdSEd Maste @param ptr an argument to pass to the callback function 195c43e99fdSEd Maste @return 0 if successful, or -1 if an error occurred 196c43e99fdSEd Maste @see evdns_resolve_ipv6(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6() 197c43e99fdSEd Maste */ 198*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 199c43e99fdSEd Maste int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr); 200c43e99fdSEd Maste 201c43e99fdSEd Maste /** 202c43e99fdSEd Maste Lookup an AAAA record for a given name. 203c43e99fdSEd Maste 204c43e99fdSEd Maste @param name a DNS hostname 205c43e99fdSEd Maste @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 206c43e99fdSEd Maste @param callback a callback function to invoke when the request is completed 207c43e99fdSEd Maste @param ptr an argument to pass to the callback function 208c43e99fdSEd Maste @return 0 if successful, or -1 if an error occurred 209c43e99fdSEd Maste @see evdns_resolve_ipv4(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6() 210c43e99fdSEd Maste */ 211*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 212c43e99fdSEd Maste int evdns_resolve_ipv6(const char *name, int flags, evdns_callback_type callback, void *ptr); 213c43e99fdSEd Maste 214c43e99fdSEd Maste struct in_addr; 215c43e99fdSEd Maste struct in6_addr; 216c43e99fdSEd Maste 217c43e99fdSEd Maste /** 218c43e99fdSEd Maste Lookup a PTR record for a given IP address. 219c43e99fdSEd Maste 220c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 221c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 222c43e99fdSEd Maste function is evdns_base_resolve_reverse(). 223c43e99fdSEd Maste 224c43e99fdSEd Maste @param in an IPv4 address 225c43e99fdSEd Maste @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 226c43e99fdSEd Maste @param callback a callback function to invoke when the request is completed 227c43e99fdSEd Maste @param ptr an argument to pass to the callback function 228c43e99fdSEd Maste @return 0 if successful, or -1 if an error occurred 229c43e99fdSEd Maste @see evdns_resolve_reverse_ipv6() 230c43e99fdSEd Maste */ 231*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 232c43e99fdSEd Maste int evdns_resolve_reverse(const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr); 233c43e99fdSEd Maste 234c43e99fdSEd Maste /** 235c43e99fdSEd Maste Lookup a PTR record for a given IPv6 address. 236c43e99fdSEd Maste 237c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 238c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 239c43e99fdSEd Maste function is evdns_base_resolve_reverse_ipv6(). 240c43e99fdSEd Maste 241c43e99fdSEd Maste @param in an IPv6 address 242c43e99fdSEd Maste @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 243c43e99fdSEd Maste @param callback a callback function to invoke when the request is completed 244c43e99fdSEd Maste @param ptr an argument to pass to the callback function 245c43e99fdSEd Maste @return 0 if successful, or -1 if an error occurred 246c43e99fdSEd Maste @see evdns_resolve_reverse_ipv6() 247c43e99fdSEd Maste */ 248*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 249c43e99fdSEd Maste int evdns_resolve_reverse_ipv6(const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr); 250c43e99fdSEd Maste 251c43e99fdSEd Maste /** 252c43e99fdSEd Maste Set the value of a configuration option. 253c43e99fdSEd Maste 254c43e99fdSEd Maste The currently available configuration options are: 255c43e99fdSEd Maste 256c43e99fdSEd Maste ndots, timeout, max-timeouts, max-inflight, and attempts 257c43e99fdSEd Maste 258c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 259c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 260c43e99fdSEd Maste function is evdns_base_set_option(). 261c43e99fdSEd Maste 262c43e99fdSEd Maste @param option the name of the configuration option to be modified 263c43e99fdSEd Maste @param val the value to be set 264c43e99fdSEd Maste @param flags Ignored. 265c43e99fdSEd Maste @return 0 if successful, or -1 if an error occurred 266c43e99fdSEd Maste */ 267*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 268c43e99fdSEd Maste int evdns_set_option(const char *option, const char *val, int flags); 269c43e99fdSEd Maste 270c43e99fdSEd Maste /** 271c43e99fdSEd Maste Parse a resolv.conf file. 272c43e99fdSEd Maste 273c43e99fdSEd Maste The 'flags' parameter determines what information is parsed from the 274c43e99fdSEd Maste resolv.conf file. See the man page for resolv.conf for the format of this 275c43e99fdSEd Maste file. 276c43e99fdSEd Maste 277c43e99fdSEd Maste The following directives are not parsed from the file: sortlist, rotate, 278c43e99fdSEd Maste no-check-names, inet6, debug. 279c43e99fdSEd Maste 280c43e99fdSEd Maste If this function encounters an error, the possible return values are: 1 = 281c43e99fdSEd Maste failed to open file, 2 = failed to stat file, 3 = file too large, 4 = out of 282c43e99fdSEd Maste memory, 5 = short read from file, 6 = no nameservers listed in the file 283c43e99fdSEd Maste 284c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 285c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 286c43e99fdSEd Maste function is evdns_base_resolv_conf_parse(). 287c43e99fdSEd Maste 288c43e99fdSEd Maste @param flags any of DNS_OPTION_NAMESERVERS|DNS_OPTION_SEARCH|DNS_OPTION_MISC| 289c43e99fdSEd Maste DNS_OPTIONS_ALL 290c43e99fdSEd Maste @param filename the path to the resolv.conf file 291c43e99fdSEd Maste @return 0 if successful, or various positive error codes if an error 292c43e99fdSEd Maste occurred (see above) 293c43e99fdSEd Maste @see resolv.conf(3), evdns_config_windows_nameservers() 294c43e99fdSEd Maste */ 295*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 296c43e99fdSEd Maste int evdns_resolv_conf_parse(int flags, const char *const filename); 297c43e99fdSEd Maste 298c43e99fdSEd Maste /** 299c43e99fdSEd Maste Clear the list of search domains. 300c43e99fdSEd Maste 301c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 302c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 303c43e99fdSEd Maste function is evdns_base_search_clear(). 304c43e99fdSEd Maste */ 305*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 306c43e99fdSEd Maste void evdns_search_clear(void); 307c43e99fdSEd Maste 308c43e99fdSEd Maste /** 309c43e99fdSEd Maste Add a domain to the list of search domains 310c43e99fdSEd Maste 311c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 312c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 313c43e99fdSEd Maste function is evdns_base_search_add(). 314c43e99fdSEd Maste 315c43e99fdSEd Maste @param domain the domain to be added to the search list 316c43e99fdSEd Maste */ 317*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 318c43e99fdSEd Maste void evdns_search_add(const char *domain); 319c43e99fdSEd Maste 320c43e99fdSEd Maste /** 321c43e99fdSEd Maste Set the 'ndots' parameter for searches. 322c43e99fdSEd Maste 323c43e99fdSEd Maste Sets the number of dots which, when found in a name, causes 324c43e99fdSEd Maste the first query to be without any search domain. 325c43e99fdSEd Maste 326c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 327c43e99fdSEd Maste caller to specify which evdns_base it applies to. The recommended 328c43e99fdSEd Maste function is evdns_base_search_ndots_set(). 329c43e99fdSEd Maste 330c43e99fdSEd Maste @param ndots the new ndots parameter 331c43e99fdSEd Maste */ 332*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 333c43e99fdSEd Maste void evdns_search_ndots_set(const int ndots); 334c43e99fdSEd Maste 335c43e99fdSEd Maste /** 336c43e99fdSEd Maste As evdns_server_new_with_base. 337c43e99fdSEd Maste 338c43e99fdSEd Maste @deprecated This function is deprecated because it does not allow the 339c43e99fdSEd Maste caller to specify which even_base it uses. The recommended 340c43e99fdSEd Maste function is evdns_add_server_port_with_base(). 341c43e99fdSEd Maste 342c43e99fdSEd Maste */ 343*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 344*b50261e2SCy Schubert struct evdns_server_port * 345*b50261e2SCy Schubert evdns_add_server_port(evutil_socket_t socket, int flags, 346*b50261e2SCy Schubert evdns_request_callback_fn_type callback, void *user_data); 347c43e99fdSEd Maste 348c43e99fdSEd Maste #ifdef _WIN32 349*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL 350c43e99fdSEd Maste int evdns_config_windows_nameservers(void); 351c43e99fdSEd Maste #define EVDNS_CONFIG_WINDOWS_NAMESERVERS_IMPLEMENTED 352c43e99fdSEd Maste #endif 353c43e99fdSEd Maste 354c43e99fdSEd Maste #ifdef __cplusplus 355c43e99fdSEd Maste } 356c43e99fdSEd Maste #endif 357c43e99fdSEd Maste 358c43e99fdSEd Maste #endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ 359