dns_compat.h 12 KB

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