dns_compat.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
  3. * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef _EVENT2_DNS_COMPAT_H_
  28. #define _EVENT2_DNS_COMPAT_H_
  29. /** @file event2/dns_compat.h
  30. Potentially non-threadsafe versions of the functions in dns.h: provided
  31. only for backwards compatibility.
  32. */
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. #include <event2/event-config.h>
  37. #ifdef _EVENT_HAVE_SYS_TYPES_H
  38. #include <sys/types.h>
  39. #endif
  40. #ifdef _EVENT_HAVE_SYS_TIME_H
  41. #include <sys/time.h>
  42. #endif
  43. /* For int types. */
  44. #include <event2/util.h>
  45. /**
  46. Initialize the asynchronous DNS library.
  47. This function initializes support for non-blocking name resolution by
  48. calling evdns_resolv_conf_parse() on UNIX and
  49. evdns_config_windows_nameservers() on Windows.
  50. @deprecated This function is deprecated because it always uses the current
  51. event base, and is easily confused by multiple calls to event_init(), and
  52. so is not safe for multithreaded use. Additionally, it allocates a global
  53. structure that only one thread can use. The replacement is
  54. evdns_base_new().
  55. @return 0 if successful, or -1 if an error occurred
  56. @see evdns_shutdown()
  57. */
  58. int evdns_init(void);
  59. struct evdns_base;
  60. /**
  61. Return the global evdns_base created by event_init() and used by the other
  62. deprecated functions.
  63. @deprecated This function is deprecated because use of the global
  64. evdns_base is error-prone.
  65. */
  66. struct evdns_base *evdns_get_global_base(void);
  67. /**
  68. Shut down the asynchronous DNS resolver and terminate all active requests.
  69. If the 'fail_requests' option is enabled, all active requests will return
  70. an empty result with the error flag set to DNS_ERR_SHUTDOWN. Otherwise,
  71. the requests will be silently discarded.
  72. @deprecated This function is deprecated because it does not allow the
  73. caller to specify which evdns_base it applies to. The recommended
  74. function is evdns_base_shutdown().
  75. @param fail_requests if zero, active requests will be aborted; if non-zero,
  76. active requests will return DNS_ERR_SHUTDOWN.
  77. @see evdns_init()
  78. */
  79. void evdns_shutdown(int fail_requests);
  80. /**
  81. Add a nameserver.
  82. The address should be an IPv4 address in network byte order.
  83. The type of address is chosen so that it matches in_addr.s_addr.
  84. @deprecated This function is deprecated because it does not allow the
  85. caller to specify which evdns_base it applies to. The recommended
  86. function is evdns_base_nameserver_add().
  87. @param address an IP address in network byte order
  88. @return 0 if successful, or -1 if an error occurred
  89. @see evdns_nameserver_ip_add()
  90. */
  91. int evdns_nameserver_add(unsigned long int address);
  92. /**
  93. Get the number of configured nameservers.
  94. This returns the number of configured nameservers (not necessarily the
  95. number of running nameservers). This is useful for double-checking
  96. whether our calls to the various nameserver configuration functions
  97. have been successful.
  98. @deprecated This function is deprecated because it does not allow the
  99. caller to specify which evdns_base it applies to. The recommended
  100. function is evdns_base_count_nameservers().
  101. @return the number of configured nameservers
  102. @see evdns_nameserver_add()
  103. */
  104. int evdns_count_nameservers(void);
  105. /**
  106. Remove all configured nameservers, and suspend all pending resolves.
  107. Resolves will not necessarily be re-attempted until evdns_resume() is called.
  108. @deprecated This function is deprecated because it does not allow the
  109. caller to specify which evdns_base it applies to. The recommended
  110. function is evdns_base_clear_nameservers_and_suspend().
  111. @return 0 if successful, or -1 if an error occurred
  112. @see evdns_resume()
  113. */
  114. int evdns_clear_nameservers_and_suspend(void);
  115. /**
  116. Resume normal operation and continue any suspended resolve requests.
  117. Re-attempt resolves left in limbo after an earlier call to
  118. evdns_clear_nameservers_and_suspend().
  119. @deprecated This function is deprecated because it does not allow the
  120. caller to specify which evdns_base it applies to. The recommended
  121. function is evdns_base_resume().
  122. @return 0 if successful, or -1 if an error occurred
  123. @see evdns_clear_nameservers_and_suspend()
  124. */
  125. int evdns_resume(void);
  126. /**
  127. Add a nameserver.
  128. This wraps the evdns_nameserver_add() function by parsing a string as an IP
  129. address and adds it as a nameserver.
  130. @deprecated This function is deprecated because it does not allow the
  131. caller to specify which evdns_base it applies to. The recommended
  132. function is evdns_base_nameserver_ip_add().
  133. @return 0 if successful, or -1 if an error occurred
  134. @see evdns_nameserver_add()
  135. */
  136. int evdns_nameserver_ip_add(const char *ip_as_string);
  137. /**
  138. Lookup an A record for a given name.
  139. @deprecated This function is deprecated because it does not allow the
  140. caller to specify which evdns_base it applies to. The recommended
  141. function is evdns_base_resolve_ipv4().
  142. @param name a DNS hostname
  143. @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
  144. @param callback a callback function to invoke when the request is completed
  145. @param ptr an argument to pass to the callback function
  146. @return 0 if successful, or -1 if an error occurred
  147. @see evdns_resolve_ipv6(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6()
  148. */
  149. int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr);
  150. /**
  151. Lookup an AAAA record for a given name.
  152. @param name a DNS hostname
  153. @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
  154. @param callback a callback function to invoke when the request is completed
  155. @param ptr an argument to pass to the callback function
  156. @return 0 if successful, or -1 if an error occurred
  157. @see evdns_resolve_ipv4(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6()
  158. */
  159. int evdns_resolve_ipv6(const char *name, int flags, evdns_callback_type callback, void *ptr);
  160. struct in_addr;
  161. struct in6_addr;
  162. /**
  163. Lookup a PTR record for a given IP address.
  164. @deprecated This function is deprecated because it does not allow the
  165. caller to specify which evdns_base it applies to. The recommended
  166. function is evdns_base_resolve_reverse().
  167. @param in an IPv4 address
  168. @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
  169. @param callback a callback function to invoke when the request is completed
  170. @param ptr an argument to pass to the callback function
  171. @return 0 if successful, or -1 if an error occurred
  172. @see evdns_resolve_reverse_ipv6()
  173. */
  174. int evdns_resolve_reverse(const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr);
  175. /**
  176. Lookup a PTR record for a given IPv6 address.
  177. @deprecated This function is deprecated because it does not allow the
  178. caller to specify which evdns_base it applies to. The recommended
  179. function is evdns_base_resolve_reverse_ipv6().
  180. @param in an IPv6 address
  181. @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
  182. @param callback a callback function to invoke when the request is completed
  183. @param ptr an argument to pass to the callback function
  184. @return 0 if successful, or -1 if an error occurred
  185. @see evdns_resolve_reverse_ipv6()
  186. */
  187. int evdns_resolve_reverse_ipv6(const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr);
  188. /**
  189. Set the value of a configuration option.
  190. The currently available configuration options are:
  191. ndots, timeout, max-timeouts, max-inflight, and attempts
  192. @deprecated This function is deprecated because it does not allow the
  193. caller to specify which evdns_base it applies to. The recommended
  194. function is evdns_base_set_option().
  195. @param option the name of the configuration option to be modified
  196. @param val the value to be set
  197. @param flags Ignored.
  198. @return 0 if successful, or -1 if an error occurred
  199. */
  200. int evdns_set_option(const char *option, const char *val, int flags);
  201. /**
  202. Parse a resolv.conf file.
  203. The 'flags' parameter determines what information is parsed from the
  204. resolv.conf file. See the man page for resolv.conf for the format of this
  205. file.
  206. The following directives are not parsed from the file: sortlist, rotate,
  207. no-check-names, inet6, debug.
  208. If this function encounters an error, the possible return values are: 1 =
  209. failed to open file, 2 = failed to stat file, 3 = file too large, 4 = out of
  210. memory, 5 = short read from file, 6 = no nameservers listed in the file
  211. @deprecated This function is deprecated because it does not allow the
  212. caller to specify which evdns_base it applies to. The recommended
  213. function is evdns_base_resolv_conf_parse().
  214. @param flags any of DNS_OPTION_NAMESERVERS|DNS_OPTION_SEARCH|DNS_OPTION_MISC|
  215. DNS_OPTIONS_ALL
  216. @param filename the path to the resolv.conf file
  217. @return 0 if successful, or various positive error codes if an error
  218. occurred (see above)
  219. @see resolv.conf(3), evdns_config_windows_nameservers()
  220. */
  221. int evdns_resolv_conf_parse(int flags, const char *const filename);
  222. /**
  223. Clear the list of search domains.
  224. @deprecated This function is deprecated because it does not allow the
  225. caller to specify which evdns_base it applies to. The recommended
  226. function is evdns_base_search_clear().
  227. */
  228. void evdns_search_clear(void);
  229. /**
  230. Add a domain to the list of search domains
  231. @deprecated This function is deprecated because it does not allow the
  232. caller to specify which evdns_base it applies to. The recommended
  233. function is evdns_base_search_add().
  234. @param domain the domain to be added to the search list
  235. */
  236. void evdns_search_add(const char *domain);
  237. /**
  238. Set the 'ndots' parameter for searches.
  239. Sets the number of dots which, when found in a name, causes
  240. the first query to be without any search domain.
  241. @deprecated This function is deprecated because it does not allow the
  242. caller to specify which evdns_base it applies to. The recommended
  243. function is evdns_base_search_ndots_set().
  244. @param ndots the new ndots parameter
  245. */
  246. void evdns_search_ndots_set(const int ndots);
  247. /**
  248. As evdns_server_new_with_base.
  249. @deprecated This function is deprecated because it does not allow the
  250. caller to specify which even_base it uses. The recommended
  251. function is evdns_add_server_port_with_base().
  252. */
  253. struct evdns_server_port *evdns_add_server_port(evutil_socket_t socket, int flags, evdns_request_callback_fn_type callback, void *user_data);
  254. #ifdef WIN32
  255. int evdns_config_windows_nameservers(void);
  256. #define EVDNS_CONFIG_WINDOWS_NAMESERVERS_IMPLEMENTED
  257. #endif
  258. #ifdef __cplusplus
  259. }
  260. #endif
  261. #endif /* _EVENT2_EVENT_COMPAT_H_ */