ares.h 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. /* MIT License
  2. *
  3. * Copyright (c) Massachusetts Institute of Technology
  4. * Copyright (c) Daniel Stenberg
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the next
  14. * paragraph) shall be included in all copies or substantial portions of the
  15. * Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. *
  25. * SPDX-License-Identifier: MIT
  26. */
  27. #ifndef ARES__H
  28. #define ARES__H
  29. #include "ares_version.h" /* c-ares version defines */
  30. #include "ares_build.h" /* c-ares build definitions */
  31. #if defined(_WIN32)
  32. # ifndef WIN32_LEAN_AND_MEAN
  33. # define WIN32_LEAN_AND_MEAN
  34. # endif
  35. #endif
  36. #ifdef CARES_HAVE_SYS_TYPES_H
  37. # include <sys/types.h>
  38. #endif
  39. #ifdef CARES_HAVE_SYS_SOCKET_H
  40. # include <sys/socket.h>
  41. #endif
  42. #ifdef CARES_HAVE_SYS_SELECT_H
  43. # include <sys/select.h>
  44. #endif
  45. #ifdef CARES_HAVE_WINSOCK2_H
  46. # include <winsock2.h>
  47. /* To aid with linking against a static c-ares build, lets tell the microsoft
  48. * compiler to pull in needed dependencies */
  49. # ifdef _MSC_VER
  50. # pragma comment(lib, "ws2_32")
  51. # pragma comment(lib, "advapi32")
  52. # pragma comment(lib, "iphlpapi")
  53. # endif
  54. #endif
  55. #ifdef CARES_HAVE_WS2TCPIP_H
  56. # include <ws2tcpip.h>
  57. #endif
  58. #ifdef CARES_HAVE_WINDOWS_H
  59. # include <windows.h>
  60. #endif
  61. /* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
  62. libc5-based Linux systems. Only include it on system that are known to
  63. require it! */
  64. #if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \
  65. defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \
  66. defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \
  67. defined(__QNX__) || defined(__MVS__) || defined(__HAIKU__)
  68. # include <sys/select.h>
  69. #endif
  70. #if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
  71. # include <sys/bsdskt.h>
  72. #endif
  73. #if !defined(_WIN32)
  74. # include <netinet/in.h>
  75. #endif
  76. #ifdef WATT32
  77. # include <tcp.h>
  78. #endif
  79. #if defined(ANDROID) || defined(__ANDROID__)
  80. # include <jni.h>
  81. #endif
  82. typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;
  83. typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t;
  84. #ifdef __cplusplus
  85. extern "C" {
  86. #endif
  87. /*
  88. ** c-ares external API function linkage decorations.
  89. */
  90. #if defined(_WIN32) || defined(__CYGWIN__) || defined(__SYMBIAN32__)
  91. # ifdef CARES_STATICLIB
  92. # define CARES_EXTERN
  93. # else
  94. # ifdef CARES_BUILDING_LIBRARY
  95. # define CARES_EXTERN __declspec(dllexport)
  96. # else
  97. # define CARES_EXTERN __declspec(dllimport)
  98. # endif
  99. # endif
  100. #else
  101. # if defined(__GNUC__) && __GNUC__ >= 4
  102. # define CARES_EXTERN __attribute__((visibility("default")))
  103. # elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 900
  104. # define CARES_EXTERN __attribute__((visibility("default")))
  105. # elif defined(__SUNPRO_C)
  106. # define CARES_EXTERN _global
  107. # else
  108. # define CARES_EXTERN
  109. # endif
  110. #endif
  111. #ifdef __GNUC__
  112. # define CARES_GCC_VERSION \
  113. (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
  114. #else
  115. # define CARES_GCC_VERSION 0
  116. #endif
  117. #ifndef __has_attribute
  118. # define __has_attribute(x) 0
  119. #endif
  120. #if 1
  121. # define CARES_DEPRECATED
  122. # define CARES_DEPRECATED_FOR(f)
  123. #else
  124. # if CARES_GCC_VERSION >= 30200 || __has_attribute(__deprecated__)
  125. # define CARES_DEPRECATED __attribute__((__deprecated__))
  126. # else
  127. # define CARES_DEPRECATED
  128. # endif
  129. # if CARES_GCC_VERSION >= 40500 || defined(__clang__)
  130. # define CARES_DEPRECATED_FOR(f) \
  131. __attribute__((deprecated("Use " #f " instead")))
  132. # elif defined(_MSC_VER)
  133. # define CARES_DEPRECATED_FOR(f) __declspec(deprecated("Use " #f " instead"))
  134. # else
  135. # define CARES_DEPRECATED_FOR(f) CARES_DEPRECATED
  136. # endif
  137. #endif
  138. typedef enum {
  139. ARES_SUCCESS = 0,
  140. /* Server error codes (ARES_ENODATA indicates no relevant answer) */
  141. ARES_ENODATA = 1,
  142. ARES_EFORMERR = 2,
  143. ARES_ESERVFAIL = 3,
  144. ARES_ENOTFOUND = 4,
  145. ARES_ENOTIMP = 5,
  146. ARES_EREFUSED = 6,
  147. /* Locally generated error codes */
  148. ARES_EBADQUERY = 7,
  149. ARES_EBADNAME = 8,
  150. ARES_EBADFAMILY = 9,
  151. ARES_EBADRESP = 10,
  152. ARES_ECONNREFUSED = 11,
  153. ARES_ETIMEOUT = 12,
  154. ARES_EOF = 13,
  155. ARES_EFILE = 14,
  156. ARES_ENOMEM = 15,
  157. ARES_EDESTRUCTION = 16,
  158. ARES_EBADSTR = 17,
  159. /* ares_getnameinfo error codes */
  160. ARES_EBADFLAGS = 18,
  161. /* ares_getaddrinfo error codes */
  162. ARES_ENONAME = 19,
  163. ARES_EBADHINTS = 20,
  164. /* Uninitialized library error code */
  165. ARES_ENOTINITIALIZED = 21, /* introduced in 1.7.0 */
  166. /* ares_library_init error codes */
  167. ARES_ELOADIPHLPAPI = 22, /* introduced in 1.7.0 */
  168. ARES_EADDRGETNETWORKPARAMS = 23, /* introduced in 1.7.0 */
  169. /* More error codes */
  170. ARES_ECANCELLED = 24, /* introduced in 1.7.0 */
  171. /* More ares_getaddrinfo error codes */
  172. ARES_ESERVICE = 25, /* ares_getaddrinfo() was passed a text service name that
  173. * is not recognized. introduced in 1.16.0 */
  174. ARES_ENOSERVER = 26 /* No DNS servers were configured */
  175. } ares_status_t;
  176. typedef enum {
  177. ARES_FALSE = 0,
  178. ARES_TRUE = 1
  179. } ares_bool_t;
  180. /*! Values for ARES_OPT_EVENT_THREAD */
  181. typedef enum {
  182. /*! Default (best choice) event system */
  183. ARES_EVSYS_DEFAULT = 0,
  184. /*! Win32 IOCP/AFD_POLL event system */
  185. ARES_EVSYS_WIN32 = 1,
  186. /*! Linux epoll */
  187. ARES_EVSYS_EPOLL = 2,
  188. /*! BSD/MacOS kqueue */
  189. ARES_EVSYS_KQUEUE = 3,
  190. /*! POSIX poll() */
  191. ARES_EVSYS_POLL = 4,
  192. /*! last fallback on Unix-like systems, select() */
  193. ARES_EVSYS_SELECT = 5
  194. } ares_evsys_t;
  195. /* Flag values */
  196. #define ARES_FLAG_USEVC (1 << 0)
  197. #define ARES_FLAG_PRIMARY (1 << 1)
  198. #define ARES_FLAG_IGNTC (1 << 2)
  199. #define ARES_FLAG_NORECURSE (1 << 3)
  200. #define ARES_FLAG_STAYOPEN (1 << 4)
  201. #define ARES_FLAG_NOSEARCH (1 << 5)
  202. #define ARES_FLAG_NOALIASES (1 << 6)
  203. #define ARES_FLAG_NOCHECKRESP (1 << 7)
  204. #define ARES_FLAG_EDNS (1 << 8)
  205. #define ARES_FLAG_NO_DFLT_SVR (1 << 9)
  206. #define ARES_FLAG_DNS0x20 (1 << 10)
  207. /* Option mask values */
  208. #define ARES_OPT_FLAGS (1 << 0)
  209. #define ARES_OPT_TIMEOUT (1 << 1)
  210. #define ARES_OPT_TRIES (1 << 2)
  211. #define ARES_OPT_NDOTS (1 << 3)
  212. #define ARES_OPT_UDP_PORT (1 << 4)
  213. #define ARES_OPT_TCP_PORT (1 << 5)
  214. #define ARES_OPT_SERVERS (1 << 6)
  215. #define ARES_OPT_DOMAINS (1 << 7)
  216. #define ARES_OPT_LOOKUPS (1 << 8)
  217. #define ARES_OPT_SOCK_STATE_CB (1 << 9)
  218. #define ARES_OPT_SORTLIST (1 << 10)
  219. #define ARES_OPT_SOCK_SNDBUF (1 << 11)
  220. #define ARES_OPT_SOCK_RCVBUF (1 << 12)
  221. #define ARES_OPT_TIMEOUTMS (1 << 13)
  222. #define ARES_OPT_ROTATE (1 << 14)
  223. #define ARES_OPT_EDNSPSZ (1 << 15)
  224. #define ARES_OPT_NOROTATE (1 << 16)
  225. #define ARES_OPT_RESOLVCONF (1 << 17)
  226. #define ARES_OPT_HOSTS_FILE (1 << 18)
  227. #define ARES_OPT_UDP_MAX_QUERIES (1 << 19)
  228. #define ARES_OPT_MAXTIMEOUTMS (1 << 20)
  229. #define ARES_OPT_QUERY_CACHE (1 << 21)
  230. #define ARES_OPT_EVENT_THREAD (1 << 22)
  231. #define ARES_OPT_SERVER_FAILOVER (1 << 23)
  232. /* Nameinfo flag values */
  233. #define ARES_NI_NOFQDN (1 << 0)
  234. #define ARES_NI_NUMERICHOST (1 << 1)
  235. #define ARES_NI_NAMEREQD (1 << 2)
  236. #define ARES_NI_NUMERICSERV (1 << 3)
  237. #define ARES_NI_DGRAM (1 << 4)
  238. #define ARES_NI_TCP 0
  239. #define ARES_NI_UDP ARES_NI_DGRAM
  240. #define ARES_NI_SCTP (1 << 5)
  241. #define ARES_NI_DCCP (1 << 6)
  242. #define ARES_NI_NUMERICSCOPE (1 << 7)
  243. #define ARES_NI_LOOKUPHOST (1 << 8)
  244. #define ARES_NI_LOOKUPSERVICE (1 << 9)
  245. /* Reserved for future use */
  246. #define ARES_NI_IDN (1 << 10)
  247. #define ARES_NI_IDN_ALLOW_UNASSIGNED (1 << 11)
  248. #define ARES_NI_IDN_USE_STD3_ASCII_RULES (1 << 12)
  249. /* Addrinfo flag values */
  250. #define ARES_AI_CANONNAME (1 << 0)
  251. #define ARES_AI_NUMERICHOST (1 << 1)
  252. #define ARES_AI_PASSIVE (1 << 2)
  253. #define ARES_AI_NUMERICSERV (1 << 3)
  254. #define ARES_AI_V4MAPPED (1 << 4)
  255. #define ARES_AI_ALL (1 << 5)
  256. #define ARES_AI_ADDRCONFIG (1 << 6)
  257. #define ARES_AI_NOSORT (1 << 7)
  258. #define ARES_AI_ENVHOSTS (1 << 8)
  259. /* Reserved for future use */
  260. #define ARES_AI_IDN (1 << 10)
  261. #define ARES_AI_IDN_ALLOW_UNASSIGNED (1 << 11)
  262. #define ARES_AI_IDN_USE_STD3_ASCII_RULES (1 << 12)
  263. #define ARES_AI_CANONIDN (1 << 13)
  264. #define ARES_AI_MASK \
  265. (ARES_AI_CANONNAME | ARES_AI_NUMERICHOST | ARES_AI_PASSIVE | \
  266. ARES_AI_NUMERICSERV | ARES_AI_V4MAPPED | ARES_AI_ALL | ARES_AI_ADDRCONFIG)
  267. #define ARES_GETSOCK_MAXNUM \
  268. 16 /* ares_getsock() can return info about this \
  269. many sockets */
  270. #define ARES_GETSOCK_READABLE(bits, num) (bits & (1 << (num)))
  271. #define ARES_GETSOCK_WRITABLE(bits, num) \
  272. (bits & (1 << ((num) + ARES_GETSOCK_MAXNUM)))
  273. /* c-ares library initialization flag values */
  274. #define ARES_LIB_INIT_NONE (0)
  275. #define ARES_LIB_INIT_WIN32 (1 << 0)
  276. #define ARES_LIB_INIT_ALL (ARES_LIB_INIT_WIN32)
  277. /* Server state callback flag values */
  278. #define ARES_SERV_STATE_UDP (1 << 0) /* Query used UDP */
  279. #define ARES_SERV_STATE_TCP (1 << 1) /* Query used TCP */
  280. /*
  281. * Typedef our socket type
  282. */
  283. #ifndef ares_socket_typedef
  284. # if defined(_WIN32) && !defined(WATT32)
  285. typedef SOCKET ares_socket_t;
  286. # define ARES_SOCKET_BAD INVALID_SOCKET
  287. # else
  288. typedef int ares_socket_t;
  289. # define ARES_SOCKET_BAD -1
  290. # endif
  291. # define ares_socket_typedef
  292. #endif /* ares_socket_typedef */
  293. typedef void (*ares_sock_state_cb)(void *data, ares_socket_t socket_fd,
  294. int readable, int writable);
  295. struct apattern;
  296. /* Options controlling server failover behavior.
  297. * The retry chance is the probability (1/N) by which we will retry a failed
  298. * server instead of the best server when selecting a server to send queries
  299. * to.
  300. * The retry delay is the minimum time in milliseconds to wait between doing
  301. * such retries (applied per-server).
  302. */
  303. struct ares_server_failover_options {
  304. unsigned short retry_chance;
  305. size_t retry_delay;
  306. };
  307. /* NOTE about the ares_options struct to users and developers.
  308. This struct will remain looking like this. It will not be extended nor
  309. shrunk in future releases, but all new options will be set by ares_set_*()
  310. options instead of with the ares_init_options() function.
  311. Eventually (in a galaxy far far away), all options will be settable by
  312. ares_set_*() options and the ares_init_options() function will become
  313. deprecated.
  314. When new options are added to c-ares, they are not added to this
  315. struct. And they are not "saved" with the ares_save_options() function but
  316. instead we encourage the use of the ares_dup() function. Needless to say,
  317. if you add config options to c-ares you need to make sure ares_dup()
  318. duplicates this new option.
  319. */
  320. struct ares_options {
  321. int flags;
  322. int timeout; /* in seconds or milliseconds, depending on options */
  323. int tries;
  324. int ndots;
  325. unsigned short udp_port; /* host byte order */
  326. unsigned short tcp_port; /* host byte order */
  327. int socket_send_buffer_size;
  328. int socket_receive_buffer_size;
  329. struct in_addr *servers;
  330. int nservers;
  331. char **domains;
  332. int ndomains;
  333. char *lookups;
  334. ares_sock_state_cb sock_state_cb;
  335. void *sock_state_cb_data;
  336. struct apattern *sortlist;
  337. int nsort;
  338. int ednspsz;
  339. char *resolvconf_path;
  340. char *hosts_path;
  341. int udp_max_queries;
  342. int maxtimeout; /* in milliseconds */
  343. unsigned int qcache_max_ttl; /* Maximum TTL for query cache, 0=disabled */
  344. ares_evsys_t evsys;
  345. struct ares_server_failover_options server_failover_opts;
  346. };
  347. struct hostent;
  348. struct timeval;
  349. struct sockaddr;
  350. struct ares_channeldata;
  351. struct ares_addrinfo;
  352. struct ares_addrinfo_hints;
  353. /* Legacy typedef, don't use, you can't specify "const" */
  354. typedef struct ares_channeldata *ares_channel;
  355. /* Current main channel typedef */
  356. typedef struct ares_channeldata ares_channel_t;
  357. /*
  358. * NOTE: before c-ares 1.7.0 we would most often use the system in6_addr
  359. * struct below when ares itself was built, but many apps would use this
  360. * private version since the header checked a HAVE_* define for it. Starting
  361. * with 1.7.0 we always declare and use our own to stop relying on the
  362. * system's one.
  363. */
  364. struct ares_in6_addr {
  365. union {
  366. unsigned char _S6_u8[16];
  367. } _S6_un;
  368. };
  369. struct ares_addr {
  370. int family;
  371. union {
  372. struct in_addr addr4;
  373. struct ares_in6_addr addr6;
  374. } addr;
  375. };
  376. /* DNS record parser, writer, and helpers */
  377. #include "ares_dns_record.h"
  378. typedef void (*ares_callback)(void *arg, int status, int timeouts,
  379. unsigned char *abuf, int alen);
  380. typedef void (*ares_callback_dnsrec)(void *arg, ares_status_t status,
  381. size_t timeouts,
  382. const ares_dns_record_t *dnsrec);
  383. typedef void (*ares_host_callback)(void *arg, int status, int timeouts,
  384. struct hostent *hostent);
  385. typedef void (*ares_nameinfo_callback)(void *arg, int status, int timeouts,
  386. char *node, char *service);
  387. typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd, int type,
  388. void *data);
  389. typedef int (*ares_sock_config_callback)(ares_socket_t socket_fd, int type,
  390. void *data);
  391. typedef void (*ares_addrinfo_callback)(void *arg, int status, int timeouts,
  392. struct ares_addrinfo *res);
  393. typedef void (*ares_server_state_callback)(const char *server_string,
  394. ares_bool_t success, int flags,
  395. void *data);
  396. typedef void (*ares_pending_write_cb)(void *data);
  397. CARES_EXTERN int ares_library_init(int flags);
  398. CARES_EXTERN int ares_library_init_mem(int flags, void *(*amalloc)(size_t size),
  399. void (*afree)(void *ptr),
  400. void *(*arealloc)(void *ptr,
  401. size_t size));
  402. #if defined(ANDROID) || defined(__ANDROID__)
  403. CARES_EXTERN void ares_library_init_jvm(JavaVM *jvm);
  404. CARES_EXTERN int ares_library_init_android(jobject connectivity_manager);
  405. CARES_EXTERN int ares_library_android_initialized(void);
  406. #endif
  407. #define CARES_HAVE_ARES_LIBRARY_INIT 1
  408. #define CARES_HAVE_ARES_LIBRARY_CLEANUP 1
  409. CARES_EXTERN int ares_library_initialized(void);
  410. CARES_EXTERN void ares_library_cleanup(void);
  411. CARES_EXTERN const char *ares_version(int *version);
  412. CARES_EXTERN CARES_DEPRECATED_FOR(ares_init_options) int ares_init(
  413. ares_channel_t **channelptr);
  414. CARES_EXTERN int ares_init_options(ares_channel_t **channelptr,
  415. const struct ares_options *options,
  416. int optmask);
  417. CARES_EXTERN int ares_save_options(const ares_channel_t *channel,
  418. struct ares_options *options, int *optmask);
  419. CARES_EXTERN void ares_destroy_options(struct ares_options *options);
  420. CARES_EXTERN int ares_dup(ares_channel_t **dest, const ares_channel_t *src);
  421. CARES_EXTERN ares_status_t ares_reinit(ares_channel_t *channel);
  422. CARES_EXTERN void ares_destroy(ares_channel_t *channel);
  423. CARES_EXTERN void ares_cancel(ares_channel_t *channel);
  424. /* These next 3 configure local binding for the out-going socket
  425. * connection. Use these to specify source IP and/or network device
  426. * on multi-homed systems.
  427. */
  428. CARES_EXTERN void ares_set_local_ip4(ares_channel_t *channel,
  429. unsigned int local_ip);
  430. /* local_ip6 should be 16 bytes in length */
  431. CARES_EXTERN void ares_set_local_ip6(ares_channel_t *channel,
  432. const unsigned char *local_ip6);
  433. /* local_dev_name should be null terminated. */
  434. CARES_EXTERN void ares_set_local_dev(ares_channel_t *channel,
  435. const char *local_dev_name);
  436. CARES_EXTERN void ares_set_socket_callback(ares_channel_t *channel,
  437. ares_sock_create_callback callback,
  438. void *user_data);
  439. CARES_EXTERN void ares_set_socket_configure_callback(
  440. ares_channel_t *channel, ares_sock_config_callback callback, void *user_data);
  441. CARES_EXTERN void
  442. ares_set_server_state_callback(ares_channel_t *channel,
  443. ares_server_state_callback callback,
  444. void *user_data);
  445. CARES_EXTERN void ares_set_pending_write_cb(ares_channel_t *channel,
  446. ares_pending_write_cb callback,
  447. void *user_data);
  448. CARES_EXTERN void ares_process_pending_write(ares_channel_t *channel);
  449. CARES_EXTERN int ares_set_sortlist(ares_channel_t *channel,
  450. const char *sortstr);
  451. CARES_EXTERN void ares_getaddrinfo(ares_channel_t *channel, const char *node,
  452. const char *service,
  453. const struct ares_addrinfo_hints *hints,
  454. ares_addrinfo_callback callback, void *arg);
  455. CARES_EXTERN void ares_freeaddrinfo(struct ares_addrinfo *ai);
  456. /*
  457. * Virtual function set to have user-managed socket IO.
  458. * Note that all functions need to be defined, and when
  459. * set, the library will not do any bind nor set any
  460. * socket options, assuming the client handles these
  461. * through either socket creation or the
  462. * ares_sock_config_callback call.
  463. */
  464. struct iovec;
  465. struct ares_socket_functions {
  466. ares_socket_t (*asocket)(int, int, int, void *);
  467. int (*aclose)(ares_socket_t, void *);
  468. int (*aconnect)(ares_socket_t, const struct sockaddr *, ares_socklen_t,
  469. void *);
  470. ares_ssize_t (*arecvfrom)(ares_socket_t, void *, size_t, int,
  471. struct sockaddr *, ares_socklen_t *, void *);
  472. ares_ssize_t (*asendv)(ares_socket_t, const struct iovec *, int, void *);
  473. };
  474. CARES_EXTERN CARES_DEPRECATED_FOR(
  475. ares_set_socket_functions_ex) void ares_set_socket_functions(ares_channel_t
  476. *channel,
  477. const struct
  478. ares_socket_functions
  479. *funcs,
  480. void *user_data);
  481. /*! Flags defining behavior of socket functions */
  482. typedef enum {
  483. /*! Strongly recommended to create sockets as non-blocking and set this
  484. * flag */
  485. ARES_SOCKFUNC_FLAG_NONBLOCKING = 1 << 0
  486. } ares_sockfunc_flags_t;
  487. /*! Socket options in request to asetsockopt() in struct
  488. * ares_socket_functions_ex */
  489. typedef enum {
  490. /*! Set the send buffer size. Value is a pointer to an int. (SO_SNDBUF) */
  491. ARES_SOCKET_OPT_SENDBUF_SIZE,
  492. /*! Set the recv buffer size. Value is a pointer to an int. (SO_RCVBUF) */
  493. ARES_SOCKET_OPT_RECVBUF_SIZE,
  494. /*! Set the network interface to use as the source for communication.
  495. * Value is a C string. (SO_BINDTODEVICE) */
  496. ARES_SOCKET_OPT_BIND_DEVICE,
  497. /*! Enable TCP Fast Open. Value is a pointer to an ares_bool_t. On some
  498. * systems this could be a no-op if it is known it is on by default and
  499. * return success. Other systems may be a no-op if known the system does
  500. * not support the feature and returns failure with errno set to ENOSYS or
  501. * WSASetLastError(WSAEOPNOTSUPP).
  502. */
  503. ARES_SOCKET_OPT_TCP_FASTOPEN
  504. } ares_socket_opt_t;
  505. /*! Flags for behavior during connect */
  506. typedef enum {
  507. /*! Connect using TCP Fast Open */
  508. ARES_SOCKET_CONN_TCP_FASTOPEN = 1 << 0
  509. } ares_socket_connect_flags_t;
  510. /*! Flags for behavior during bind */
  511. typedef enum {
  512. /*! Bind is for a TCP connection */
  513. ARES_SOCKET_BIND_TCP = 1 << 0,
  514. /*! Bind is for a client connection, not server */
  515. ARES_SOCKET_BIND_CLIENT = 1 << 1
  516. } ares_socket_bind_flags_t;
  517. /*! Socket functions to call rather than using OS-native functions */
  518. struct ares_socket_functions_ex {
  519. /*! ABI Version: must be "1" */
  520. unsigned int version;
  521. /*! Flags indicating behavior of the subsystem. One or more
  522. * ares_sockfunc_flags_t */
  523. unsigned int flags;
  524. /*! REQUIRED. Create a new socket file descriptor. The file descriptor must
  525. * be opened in non-blocking mode (so that reads and writes never block).
  526. * Recommended other options would be to disable signals on write errors
  527. * (SO_NOSIGPIPE), Disable the Nagle algorithm on SOCK_STREAM (TCP_NODELAY),
  528. * and to automatically close file descriptors on exec (FD_CLOEXEC).
  529. *
  530. * \param[in] domain Socket domain. Valid values are AF_INET, AF_INET6.
  531. * \param[in] type Socket type. Valid values are SOCK_STREAM (tcp) and
  532. * SOCK_DGRAM (udp).
  533. * \param[in] protocol In general this should be ignored, may be passed as
  534. * 0 (use as default for type), or may be IPPROTO_UDP
  535. * or IPPROTO_TCP.
  536. * \param[in] user_data Pointer provided to ares_set_socket_functions_ex().
  537. * \return ARES_SOCKET_BAD on error, or socket file descriptor on success.
  538. * On error, it is expected to set errno (or WSASetLastError()) to an
  539. * appropriate reason code such as EAFNOSUPPORT / WSAAFNOSUPPORT. */
  540. ares_socket_t (*asocket)(int domain, int type, int protocol, void *user_data);
  541. /*! REQUIRED. Close a socket file descriptor.
  542. * \param[in] sock Socket file descriptor returned from asocket.
  543. * \param[in] user_data Pointer provided to ares_set_socket_functions_ex().
  544. * \return 0 on success. On failure, should set errno (or WSASetLastError)
  545. * to an appropriate code such as EBADF / WSAEBADF */
  546. int (*aclose)(ares_socket_t sock, void *user_data);
  547. /*! REQUIRED. Set socket option. This shares a similar syntax to the BSD
  548. * setsockopt() call, however we use our own options. The value is typically
  549. * a pointer to the desired value and each option has its own data type it
  550. * will express in the documentation.
  551. *
  552. * \param[in] sock Socket file descriptor returned from asocket.
  553. * \param[in] opt Option to set.
  554. * \param[in] val Pointer to value for option.
  555. * \param[in] val_size Size of value.
  556. * \param[in] user_data Pointer provided to
  557. * ares_set_socket_functions_ex().
  558. * \return Return 0 on success, otherwise -1 should be returned with an
  559. * appropriate errno (or WSASetLastError()) set. If error is ENOSYS /
  560. * WSAEOPNOTSUPP an error will not be propagated as it will take it
  561. * to mean it is an intentional decision to not support the feature.
  562. */
  563. int (*asetsockopt)(ares_socket_t sock, ares_socket_opt_t opt, const void *val,
  564. ares_socklen_t val_size, void *user_data);
  565. /*! REQUIRED. Connect to the remote using the supplied address. For UDP
  566. * sockets this will bind the file descriptor to only send and receive packets
  567. * from the remote address provided.
  568. *
  569. * \param[in] sock Socket file descriptor returned from asocket.
  570. * \param[in] address Address to connect to
  571. * \param[in] address_len Size of address structure passed
  572. * \param[in] flags One or more ares_socket_connect_flags_t
  573. * \param[in] user_data Pointer provided to
  574. * ares_set_socket_functions_ex().
  575. * \return Return 0 upon successful establishement, otherwise -1 should be
  576. * returned with an appropriate errno (or WSASetLastError()) set. It
  577. * is generally expected that most TCP connections (not using TCP Fast Open)
  578. * will return -1 with an error of EINPROGRESS / WSAEINPROGRESS due to the
  579. * non-blocking nature of the connection. It is then the responsibility of
  580. * the implementation to notify of writability on the socket to indicate the
  581. * connection has succeeded (or readability on failure to retrieve the
  582. * appropriate error).
  583. */
  584. int (*aconnect)(ares_socket_t sock, const struct sockaddr *address,
  585. ares_socklen_t address_len, unsigned int flags,
  586. void *user_data);
  587. /*! REQUIRED. Attempt to read data from the remote.
  588. *
  589. * \param[in] sock Socket file descriptor returned from asocket.
  590. * \param[in,out] buffer Allocated buffer to place data read from
  591. * socket.
  592. * \param[in] length Size of buffer
  593. * \param[in] flags Unused, always 0.
  594. * \param[in,out] address Buffer to hold address data was received from.
  595. * May be NULL if address not desired.
  596. * \param[in,out] address_len Input size of address buffer, output actual
  597. * written size. Must be NULL if address is NULL.
  598. * \param[in] user_data Pointer provided to
  599. * ares_set_socket_functions_ex().
  600. * \return -1 on error with appropriate errno (or WSASetLastError()) set,
  601. * such as EWOULDBLOCK / EAGAIN / WSAEWOULDBLOCK, or ECONNRESET /
  602. * WSAECONNRESET.
  603. */
  604. ares_ssize_t (*arecvfrom)(ares_socket_t sock, void *buffer, size_t length,
  605. int flags, struct sockaddr *address,
  606. ares_socklen_t *address_len, void *user_data);
  607. /*! REQUIRED. Attempt to send data to the remote. Optional address may be
  608. * specified which may be useful on unbound UDP sockets (though currently not
  609. * used), and TCP FastOpen where the connection is delayed until first write.
  610. *
  611. * \param[in] sock Socket file descriptor returned from asocket.
  612. * \param[in] buffer Containing data to place onto wire.
  613. * \param[in] length Size of buffer
  614. * \param[in] flags Flags for writing. Currently only used flag is
  615. * MSG_NOSIGNAL if the host OS has such a flag. In
  616. * general flags can be ignored.
  617. * \param[in] address Buffer containing address to send data to. May
  618. * be NULL.
  619. * \param[in,out] address_len Size of address buffer. Must be 0 if address
  620. * is NULL.
  621. * \param[in] user_data Pointer provided to
  622. * ares_set_socket_functions_ex().
  623. * \return Number of bytes written. -1 on error with appropriate errno (or
  624. * WSASetLastError()) set.
  625. */
  626. ares_ssize_t (*asendto)(ares_socket_t sock, const void *buffer, size_t length,
  627. int flags, const struct sockaddr *address,
  628. ares_socklen_t address_len, void *user_data);
  629. /*! Optional. Retrieve the local address of the socket.
  630. *
  631. * \param[in] sock Socket file descriptor returned from asocket
  632. * \param[in,out] address Buffer to hold address
  633. * \param[in,out] address_len Size of address buffer on input, written size
  634. * on output.
  635. * \param[in] user_data Pointer provided to
  636. * ares_set_socket_functions_ex().
  637. * \return 0 on success. -1 on error with an appropriate errno (or
  638. * WSASetLastError()) set.
  639. */
  640. int (*agetsockname)(ares_socket_t sock, struct sockaddr *address,
  641. ares_socklen_t *address_len, void *user_data);
  642. /*! Optional. Bind the socket to an address. This can be used for client
  643. * connections to bind the source address for packets before connect, or
  644. * for server connections to bind to an address and port before listening.
  645. * Currently c-ares only supports client connections.
  646. *
  647. * \param[in] sock Socket file descriptor returned from asocket
  648. * \param[in] flags ares_socket_bind_flags_t flags.
  649. * \param[in] address Buffer containing address.
  650. * \param[in] address_len Size of address buffer.
  651. * \param[in] user_data Pointer provided to
  652. * ares_set_socket_functions_ex().
  653. * \return 0 on success. -1 on error with an appropriate errno (or
  654. * WSASetLastError()) set.
  655. */
  656. int (*abind)(ares_socket_t sock, unsigned int flags,
  657. const struct sockaddr *address, socklen_t address_len,
  658. void *user_data);
  659. /* Optional. Convert an interface name into the interface index. If this
  660. * callback is not specified, then IPv6 Link-Local DNS servers cannot be used.
  661. *
  662. * \param[in] ifname Interface Name as NULL-terminated string.
  663. * \param[in] user_data Pointer provided to
  664. * ares_set_socket_functions_ex().
  665. * \return 0 on failure, otherwise interface index.
  666. */
  667. unsigned int (*aif_nametoindex)(const char *ifname, void *user_data);
  668. /* Optional. Convert an interface index into the interface name. If this
  669. * callback is not specified, then IPv6 Link-Local DNS servers cannot be used.
  670. *
  671. * \param[in] ifindex Interface index, must be > 0
  672. * \param[in] ifname_buf Buffer to hold interface name. Must be at least
  673. * IFNAMSIZ in length or 32 bytes if IFNAMSIZ isn't
  674. * defined.
  675. * \param[in] ifname_buf_len Size of ifname_buf for verification.
  676. * \param[in] user_data Pointer provided to
  677. * ares_set_socket_functions_ex().
  678. * \return NULL on failure, otherwise pointer to provided ifname_buf
  679. */
  680. const char *(*aif_indextoname)(unsigned int ifindex, char *ifname_buf,
  681. size_t ifname_buf_len, void *user_data);
  682. };
  683. /*! Override the native socket functions for the OS with the provided set.
  684. * An optional user data thunk may be specified which will be passed to
  685. * each registered callback. Replaces ares_set_socket_functions().
  686. *
  687. * \param[in] channel An initialized c-ares channel.
  688. * \param[in] funcs Structure registering the implementations for the
  689. * various functions. See the structure definition.
  690. * This will be duplicated and does not need to exist
  691. * past the life of this call.
  692. * \param[in] user_data User data thunk which will be passed to each call of
  693. * the registered callbacks.
  694. * \return ARES_SUCCESS on success, or another error code such as ARES_EFORMERR
  695. * on misuse.
  696. */
  697. CARES_EXTERN ares_status_t ares_set_socket_functions_ex(
  698. ares_channel_t *channel, const struct ares_socket_functions_ex *funcs,
  699. void *user_data);
  700. CARES_EXTERN CARES_DEPRECATED_FOR(ares_send_dnsrec) void ares_send(
  701. ares_channel_t *channel, const unsigned char *qbuf, int qlen,
  702. ares_callback callback, void *arg);
  703. /*! Send a DNS query as an ares_dns_record_t with a callback containing the
  704. * parsed DNS record.
  705. *
  706. * \param[in] channel Pointer to channel on which queries will be sent.
  707. * \param[in] dnsrec DNS Record to send
  708. * \param[in] callback Callback function invoked on completion or failure of
  709. * the query sequence.
  710. * \param[in] arg Additional argument passed to the callback function.
  711. * \param[out] qid Query ID
  712. * \return One of the c-ares status codes.
  713. */
  714. CARES_EXTERN ares_status_t ares_send_dnsrec(ares_channel_t *channel,
  715. const ares_dns_record_t *dnsrec,
  716. ares_callback_dnsrec callback,
  717. void *arg, unsigned short *qid);
  718. CARES_EXTERN CARES_DEPRECATED_FOR(ares_query_dnsrec) void ares_query(
  719. ares_channel_t *channel, const char *name, int dnsclass, int type,
  720. ares_callback callback, void *arg);
  721. /*! Perform a DNS query with a callback containing the parsed DNS record.
  722. *
  723. * \param[in] channel Pointer to channel on which queries will be sent.
  724. * \param[in] name Query name
  725. * \param[in] dnsclass DNS Class
  726. * \param[in] type DNS Record Type
  727. * \param[in] callback Callback function invoked on completion or failure of
  728. * the query sequence.
  729. * \param[in] arg Additional argument passed to the callback function.
  730. * \param[out] qid Query ID
  731. * \return One of the c-ares status codes.
  732. */
  733. CARES_EXTERN ares_status_t ares_query_dnsrec(ares_channel_t *channel,
  734. const char *name,
  735. ares_dns_class_t dnsclass,
  736. ares_dns_rec_type_t type,
  737. ares_callback_dnsrec callback,
  738. void *arg, unsigned short *qid);
  739. CARES_EXTERN CARES_DEPRECATED_FOR(ares_search_dnsrec) void ares_search(
  740. ares_channel_t *channel, const char *name, int dnsclass, int type,
  741. ares_callback callback, void *arg);
  742. /*! Search for a complete DNS message.
  743. *
  744. * \param[in] channel Pointer to channel on which queries will be sent.
  745. * \param[in] dnsrec Pointer to initialized and filled DNS record object.
  746. * \param[in] callback Callback function invoked on completion or failure of
  747. * the query sequence.
  748. * \param[in] arg Additional argument passed to the callback function.
  749. * \return One of the c-ares status codes. In all cases, except
  750. * ARES_EFORMERR due to misuse, this error code will also be sent
  751. * to the provided callback.
  752. */
  753. CARES_EXTERN ares_status_t ares_search_dnsrec(ares_channel_t *channel,
  754. const ares_dns_record_t *dnsrec,
  755. ares_callback_dnsrec callback,
  756. void *arg);
  757. CARES_EXTERN CARES_DEPRECATED_FOR(ares_getaddrinfo) void ares_gethostbyname(
  758. ares_channel_t *channel, const char *name, int family,
  759. ares_host_callback callback, void *arg);
  760. CARES_EXTERN int ares_gethostbyname_file(ares_channel_t *channel,
  761. const char *name, int family,
  762. struct hostent **host);
  763. CARES_EXTERN void ares_gethostbyaddr(ares_channel_t *channel, const void *addr,
  764. int addrlen, int family,
  765. ares_host_callback callback, void *arg);
  766. CARES_EXTERN void ares_getnameinfo(ares_channel_t *channel,
  767. const struct sockaddr *sa,
  768. ares_socklen_t salen, int flags,
  769. ares_nameinfo_callback callback, void *arg);
  770. CARES_EXTERN CARES_DEPRECATED_FOR(
  771. ARES_OPT_EVENT_THREAD or
  772. ARES_OPT_SOCK_STATE_CB) int ares_fds(const ares_channel_t *channel,
  773. fd_set *read_fds, fd_set *write_fds);
  774. CARES_EXTERN CARES_DEPRECATED_FOR(
  775. ARES_OPT_EVENT_THREAD or
  776. ARES_OPT_SOCK_STATE_CB) int ares_getsock(const ares_channel_t *channel,
  777. ares_socket_t *socks, int numsocks);
  778. CARES_EXTERN struct timeval *ares_timeout(const ares_channel_t *channel,
  779. struct timeval *maxtv,
  780. struct timeval *tv);
  781. CARES_EXTERN CARES_DEPRECATED_FOR(ares_process_fds) void ares_process(
  782. ares_channel_t *channel, fd_set *read_fds, fd_set *write_fds);
  783. /*! Events used by ares_fd_events_t */
  784. typedef enum {
  785. ARES_FD_EVENT_NONE = 0, /*!< No events */
  786. ARES_FD_EVENT_READ = 1 << 0, /*!< Read event (including disconnect/error) */
  787. ARES_FD_EVENT_WRITE = 1 << 1 /*!< Write event */
  788. } ares_fd_eventflag_t;
  789. /*! Type holding a file descriptor and mask of events, used by
  790. * ares_process_fds() */
  791. typedef struct {
  792. ares_socket_t fd; /*!< File descriptor */
  793. unsigned int events; /*!< Mask of ares_fd_eventflag_t */
  794. } ares_fd_events_t;
  795. /*! Flags used by ares_process_fds() */
  796. typedef enum {
  797. ARES_PROCESS_FLAG_NONE = 0, /*!< No flag value */
  798. ARES_PROCESS_FLAG_SKIP_NON_FD = 1 << 0 /*!< skip any processing unrelated to
  799. * the file descriptor events passed
  800. * in */
  801. } ares_process_flag_t;
  802. /*! Process events on multiple file descriptors based on the event mask
  803. * associated with each file descriptor. Recommended over calling
  804. * ares_process_fd() multiple times since it would trigger additional logic
  805. * such as timeout processing on each call.
  806. *
  807. * \param[in] channel Initialized ares channel
  808. * \param[in] events Array of file descriptors with events. May be NULL if
  809. * no events, but may have timeouts to process.
  810. * \param[in] nevents Number of elements in the events array. May be 0 if
  811. * no events, but may have timeouts to process.
  812. * \param[in] flags Flags to alter behavior of the process command.
  813. * \return ARES_ENOMEM on out of memory, ARES_EFORMERR on misuse,
  814. * otherwise ARES_SUCCESS
  815. */
  816. CARES_EXTERN ares_status_t ares_process_fds(ares_channel_t *channel,
  817. const ares_fd_events_t *events,
  818. size_t nevents, unsigned int flags);
  819. CARES_EXTERN void ares_process_fd(ares_channel_t *channel,
  820. ares_socket_t read_fd,
  821. ares_socket_t write_fd);
  822. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_record_create) int ares_create_query(
  823. const char *name, int dnsclass, int type, unsigned short id, int rd,
  824. unsigned char **buf, int *buflen, int max_udp_size);
  825. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_record_create) int ares_mkquery(
  826. const char *name, int dnsclass, int type, unsigned short id, int rd,
  827. unsigned char **buf, int *buflen);
  828. CARES_EXTERN int ares_expand_name(const unsigned char *encoded,
  829. const unsigned char *abuf, int alen, char **s,
  830. long *enclen);
  831. CARES_EXTERN int ares_expand_string(const unsigned char *encoded,
  832. const unsigned char *abuf, int alen,
  833. unsigned char **s, long *enclen);
  834. struct ares_addrttl {
  835. struct in_addr ipaddr;
  836. int ttl;
  837. };
  838. struct ares_addr6ttl {
  839. struct ares_in6_addr ip6addr;
  840. int ttl;
  841. };
  842. struct ares_caa_reply {
  843. struct ares_caa_reply *next;
  844. int critical;
  845. unsigned char *property;
  846. size_t plength; /* plength excludes null termination */
  847. unsigned char *value;
  848. size_t length; /* length excludes null termination */
  849. };
  850. struct ares_srv_reply {
  851. struct ares_srv_reply *next;
  852. char *host;
  853. unsigned short priority;
  854. unsigned short weight;
  855. unsigned short port;
  856. };
  857. struct ares_mx_reply {
  858. struct ares_mx_reply *next;
  859. char *host;
  860. unsigned short priority;
  861. };
  862. struct ares_txt_reply {
  863. struct ares_txt_reply *next;
  864. unsigned char *txt;
  865. size_t length; /* length excludes null termination */
  866. };
  867. /* NOTE: This structure is a superset of ares_txt_reply
  868. */
  869. struct ares_txt_ext {
  870. struct ares_txt_ext *next;
  871. unsigned char *txt;
  872. size_t length;
  873. /* 1 - if start of new record
  874. * 0 - if a chunk in the same record */
  875. unsigned char record_start;
  876. };
  877. struct ares_naptr_reply {
  878. struct ares_naptr_reply *next;
  879. unsigned char *flags;
  880. unsigned char *service;
  881. unsigned char *regexp;
  882. char *replacement;
  883. unsigned short order;
  884. unsigned short preference;
  885. };
  886. struct ares_soa_reply {
  887. char *nsname;
  888. char *hostmaster;
  889. unsigned int serial;
  890. unsigned int refresh;
  891. unsigned int retry;
  892. unsigned int expire;
  893. unsigned int minttl;
  894. };
  895. struct ares_uri_reply {
  896. struct ares_uri_reply *next;
  897. unsigned short priority;
  898. unsigned short weight;
  899. char *uri;
  900. int ttl;
  901. };
  902. /*
  903. * Similar to addrinfo, but with extra ttl and missing canonname.
  904. */
  905. struct ares_addrinfo_node {
  906. int ai_ttl;
  907. int ai_flags;
  908. int ai_family;
  909. int ai_socktype;
  910. int ai_protocol;
  911. ares_socklen_t ai_addrlen;
  912. struct sockaddr *ai_addr;
  913. struct ares_addrinfo_node *ai_next;
  914. };
  915. /*
  916. * alias - label of the resource record.
  917. * name - value (canonical name) of the resource record.
  918. * See RFC2181 10.1.1. CNAME terminology.
  919. */
  920. struct ares_addrinfo_cname {
  921. int ttl;
  922. char *alias;
  923. char *name;
  924. struct ares_addrinfo_cname *next;
  925. };
  926. struct ares_addrinfo {
  927. struct ares_addrinfo_cname *cnames;
  928. struct ares_addrinfo_node *nodes;
  929. char *name;
  930. };
  931. struct ares_addrinfo_hints {
  932. int ai_flags;
  933. int ai_family;
  934. int ai_socktype;
  935. int ai_protocol;
  936. };
  937. /*
  938. ** Parse the buffer, starting at *abuf and of length alen bytes, previously
  939. ** obtained from an ares_search call. Put the results in *host, if nonnull.
  940. ** Also, if addrttls is nonnull, put up to *naddrttls IPv4 addresses along with
  941. ** their TTLs in that array, and set *naddrttls to the number of addresses
  942. ** so written.
  943. */
  944. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_parse) int ares_parse_a_reply(
  945. const unsigned char *abuf, int alen, struct hostent **host,
  946. struct ares_addrttl *addrttls, int *naddrttls);
  947. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_parse) int ares_parse_aaaa_reply(
  948. const unsigned char *abuf, int alen, struct hostent **host,
  949. struct ares_addr6ttl *addrttls, int *naddrttls);
  950. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_parse) int ares_parse_caa_reply(
  951. const unsigned char *abuf, int alen, struct ares_caa_reply **caa_out);
  952. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_parse) int ares_parse_ptr_reply(
  953. const unsigned char *abuf, int alen, const void *addr, int addrlen,
  954. int family, struct hostent **host);
  955. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_parse) int ares_parse_ns_reply(
  956. const unsigned char *abuf, int alen, struct hostent **host);
  957. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_parse) int ares_parse_srv_reply(
  958. const unsigned char *abuf, int alen, struct ares_srv_reply **srv_out);
  959. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_parse) int ares_parse_mx_reply(
  960. const unsigned char *abuf, int alen, struct ares_mx_reply **mx_out);
  961. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_parse) int ares_parse_txt_reply(
  962. const unsigned char *abuf, int alen, struct ares_txt_reply **txt_out);
  963. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_parse) int ares_parse_txt_reply_ext(
  964. const unsigned char *abuf, int alen, struct ares_txt_ext **txt_out);
  965. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_parse) int ares_parse_naptr_reply(
  966. const unsigned char *abuf, int alen, struct ares_naptr_reply **naptr_out);
  967. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_parse) int ares_parse_soa_reply(
  968. const unsigned char *abuf, int alen, struct ares_soa_reply **soa_out);
  969. CARES_EXTERN CARES_DEPRECATED_FOR(ares_dns_parse) int ares_parse_uri_reply(
  970. const unsigned char *abuf, int alen, struct ares_uri_reply **uri_out);
  971. CARES_EXTERN void ares_free_string(void *str);
  972. CARES_EXTERN void ares_free_hostent(struct hostent *host);
  973. CARES_EXTERN void ares_free_data(void *dataptr);
  974. CARES_EXTERN const char *ares_strerror(int code);
  975. struct ares_addr_node {
  976. struct ares_addr_node *next;
  977. int family;
  978. union {
  979. struct in_addr addr4;
  980. struct ares_in6_addr addr6;
  981. } addr;
  982. };
  983. struct ares_addr_port_node {
  984. struct ares_addr_port_node *next;
  985. int family;
  986. union {
  987. struct in_addr addr4;
  988. struct ares_in6_addr addr6;
  989. } addr;
  990. int udp_port;
  991. int tcp_port;
  992. };
  993. CARES_EXTERN CARES_DEPRECATED_FOR(ares_set_servers_csv) int ares_set_servers(
  994. ares_channel_t *channel, const struct ares_addr_node *servers);
  995. CARES_EXTERN
  996. CARES_DEPRECATED_FOR(ares_set_servers_ports_csv)
  997. int ares_set_servers_ports(ares_channel_t *channel,
  998. const struct ares_addr_port_node *servers);
  999. /* Incoming string format: host[:port][,host[:port]]... */
  1000. CARES_EXTERN int ares_set_servers_csv(ares_channel_t *channel,
  1001. const char *servers);
  1002. CARES_EXTERN int ares_set_servers_ports_csv(ares_channel_t *channel,
  1003. const char *servers);
  1004. CARES_EXTERN char *ares_get_servers_csv(const ares_channel_t *channel);
  1005. CARES_EXTERN CARES_DEPRECATED_FOR(ares_get_servers_csv) int ares_get_servers(
  1006. const ares_channel_t *channel, struct ares_addr_node **servers);
  1007. CARES_EXTERN
  1008. CARES_DEPRECATED_FOR(ares_get_servers_csv)
  1009. int ares_get_servers_ports(const ares_channel_t *channel,
  1010. struct ares_addr_port_node **servers);
  1011. CARES_EXTERN const char *ares_inet_ntop(int af, const void *src, char *dst,
  1012. ares_socklen_t size);
  1013. CARES_EXTERN int ares_inet_pton(int af, const char *src, void *dst);
  1014. /*! Whether or not the c-ares library was built with threadsafety
  1015. *
  1016. * \return ARES_TRUE if built with threadsafety, ARES_FALSE if not
  1017. */
  1018. CARES_EXTERN ares_bool_t ares_threadsafety(void);
  1019. /*! Block until notified that there are no longer any queries in queue, or
  1020. * the specified timeout has expired.
  1021. *
  1022. * \param[in] channel Initialized ares channel
  1023. * \param[in] timeout_ms Number of milliseconds to wait for the queue to be
  1024. * empty. -1 for Infinite.
  1025. * \return ARES_ENOTIMP if not built with threading support, ARES_ETIMEOUT
  1026. * if requested timeout expires, ARES_SUCCESS when queue is empty.
  1027. */
  1028. CARES_EXTERN ares_status_t ares_queue_wait_empty(ares_channel_t *channel,
  1029. int timeout_ms);
  1030. /*! Retrieve the total number of active queries pending answers from servers.
  1031. * Some c-ares requests may spawn multiple queries, such as ares_getaddrinfo()
  1032. * when using AF_UNSPEC, which will be reflected in this number.
  1033. *
  1034. * \param[in] channel Initialized ares channel
  1035. * \return Number of active queries to servers
  1036. */
  1037. CARES_EXTERN size_t ares_queue_active_queries(const ares_channel_t *channel);
  1038. #ifdef __cplusplus
  1039. }
  1040. #endif
  1041. #endif /* ARES__H */