ares.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. #include "ares_rules.h" /* c-ares rules enforcement */
  32. /*
  33. * Define WIN32 when build target is Win32 API
  34. */
  35. #if (defined(_WIN32) || defined(__WIN32__)) && \
  36. !defined(WIN32) && !defined(__SYMBIAN32__)
  37. # define WIN32
  38. #endif
  39. #include <sys/types.h>
  40. /* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
  41. libc5-based Linux systems. Only include it on system that are known to
  42. require it! */
  43. #if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \
  44. defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \
  45. defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \
  46. defined(__QNXNTO__) || defined(__MVS__) || defined(__HAIKU__)
  47. #include <sys/select.h>
  48. #endif
  49. #if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
  50. #include <sys/bsdskt.h>
  51. #endif
  52. #if defined(WATT32)
  53. # include <netinet/in.h>
  54. # include <sys/socket.h>
  55. # include <tcp.h>
  56. #elif defined(_WIN32_WCE)
  57. # ifndef WIN32_LEAN_AND_MEAN
  58. # define WIN32_LEAN_AND_MEAN
  59. # endif
  60. # include <windows.h>
  61. # include <winsock.h>
  62. #elif defined(WIN32)
  63. # ifndef WIN32_LEAN_AND_MEAN
  64. # define WIN32_LEAN_AND_MEAN
  65. # endif
  66. # include <windows.h>
  67. # include <winsock2.h>
  68. # include <ws2tcpip.h>
  69. /* To aid with linking against a static c-ares build, lets tell the microsoft
  70. * compiler to pull in needed dependencies */
  71. # ifdef _MSC_VER
  72. # pragma comment(lib, "ws2_32")
  73. # pragma comment(lib, "advapi32")
  74. # pragma comment(lib, "iphlpapi")
  75. # endif
  76. #else
  77. # include <sys/socket.h>
  78. # include <netinet/in.h>
  79. #endif
  80. #if defined(ANDROID) || defined(__ANDROID__)
  81. #include <jni.h>
  82. #endif
  83. #ifdef __cplusplus
  84. extern "C" {
  85. #endif
  86. /*
  87. ** c-ares external API function linkage decorations.
  88. */
  89. #ifdef CARES_STATICLIB
  90. # define CARES_EXTERN
  91. #elif defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__)
  92. # if defined(CARES_BUILDING_LIBRARY)
  93. # define CARES_EXTERN __declspec(dllexport)
  94. # else
  95. # define CARES_EXTERN __declspec(dllimport)
  96. # endif
  97. #elif defined(CARES_BUILDING_LIBRARY) && defined(CARES_SYMBOL_HIDING)
  98. # define CARES_EXTERN CARES_SYMBOL_SCOPE_EXTERN
  99. #else
  100. # define CARES_EXTERN
  101. #endif
  102. #define ARES_SUCCESS 0
  103. /* Server error codes (ARES_ENODATA indicates no relevant answer) */
  104. #define ARES_ENODATA 1
  105. #define ARES_EFORMERR 2
  106. #define ARES_ESERVFAIL 3
  107. #define ARES_ENOTFOUND 4
  108. #define ARES_ENOTIMP 5
  109. #define ARES_EREFUSED 6
  110. /* Locally generated error codes */
  111. #define ARES_EBADQUERY 7
  112. #define ARES_EBADNAME 8
  113. #define ARES_EBADFAMILY 9
  114. #define ARES_EBADRESP 10
  115. #define ARES_ECONNREFUSED 11
  116. #define ARES_ETIMEOUT 12
  117. #define ARES_EOF 13
  118. #define ARES_EFILE 14
  119. #define ARES_ENOMEM 15
  120. #define ARES_EDESTRUCTION 16
  121. #define ARES_EBADSTR 17
  122. /* ares_getnameinfo error codes */
  123. #define ARES_EBADFLAGS 18
  124. /* ares_getaddrinfo error codes */
  125. #define ARES_ENONAME 19
  126. #define ARES_EBADHINTS 20
  127. /* Uninitialized library error code */
  128. #define ARES_ENOTINITIALIZED 21 /* introduced in 1.7.0 */
  129. /* ares_library_init error codes */
  130. #define ARES_ELOADIPHLPAPI 22 /* introduced in 1.7.0 */
  131. #define ARES_EADDRGETNETWORKPARAMS 23 /* introduced in 1.7.0 */
  132. /* More error codes */
  133. #define ARES_ECANCELLED 24 /* introduced in 1.7.0 */
  134. /* More ares_getaddrinfo error codes */
  135. #define ARES_ESERVICE 25 /* introduced in 1.?.0 */
  136. /* Flag values */
  137. #define ARES_FLAG_USEVC (1 << 0)
  138. #define ARES_FLAG_PRIMARY (1 << 1)
  139. #define ARES_FLAG_IGNTC (1 << 2)
  140. #define ARES_FLAG_NORECURSE (1 << 3)
  141. #define ARES_FLAG_STAYOPEN (1 << 4)
  142. #define ARES_FLAG_NOSEARCH (1 << 5)
  143. #define ARES_FLAG_NOALIASES (1 << 6)
  144. #define ARES_FLAG_NOCHECKRESP (1 << 7)
  145. #define ARES_FLAG_EDNS (1 << 8)
  146. /* Option mask values */
  147. #define ARES_OPT_FLAGS (1 << 0)
  148. #define ARES_OPT_TIMEOUT (1 << 1)
  149. #define ARES_OPT_TRIES (1 << 2)
  150. #define ARES_OPT_NDOTS (1 << 3)
  151. #define ARES_OPT_UDP_PORT (1 << 4)
  152. #define ARES_OPT_TCP_PORT (1 << 5)
  153. #define ARES_OPT_SERVERS (1 << 6)
  154. #define ARES_OPT_DOMAINS (1 << 7)
  155. #define ARES_OPT_LOOKUPS (1 << 8)
  156. #define ARES_OPT_SOCK_STATE_CB (1 << 9)
  157. #define ARES_OPT_SORTLIST (1 << 10)
  158. #define ARES_OPT_SOCK_SNDBUF (1 << 11)
  159. #define ARES_OPT_SOCK_RCVBUF (1 << 12)
  160. #define ARES_OPT_TIMEOUTMS (1 << 13)
  161. #define ARES_OPT_ROTATE (1 << 14)
  162. #define ARES_OPT_EDNSPSZ (1 << 15)
  163. #define ARES_OPT_NOROTATE (1 << 16)
  164. #define ARES_OPT_RESOLVCONF (1 << 17)
  165. #define ARES_OPT_HOSTS_FILE (1 << 18)
  166. #define ARES_OPT_UDP_MAX_QUERIES (1 << 19)
  167. #define ARES_OPT_MAXTIMEOUTMS (1 << 20)
  168. #define ARES_OPT_JITTER (1 << 21)
  169. /* Nameinfo flag values */
  170. #define ARES_NI_NOFQDN (1 << 0)
  171. #define ARES_NI_NUMERICHOST (1 << 1)
  172. #define ARES_NI_NAMEREQD (1 << 2)
  173. #define ARES_NI_NUMERICSERV (1 << 3)
  174. #define ARES_NI_DGRAM (1 << 4)
  175. #define ARES_NI_TCP 0
  176. #define ARES_NI_UDP ARES_NI_DGRAM
  177. #define ARES_NI_SCTP (1 << 5)
  178. #define ARES_NI_DCCP (1 << 6)
  179. #define ARES_NI_NUMERICSCOPE (1 << 7)
  180. #define ARES_NI_LOOKUPHOST (1 << 8)
  181. #define ARES_NI_LOOKUPSERVICE (1 << 9)
  182. /* Reserved for future use */
  183. #define ARES_NI_IDN (1 << 10)
  184. #define ARES_NI_IDN_ALLOW_UNASSIGNED (1 << 11)
  185. #define ARES_NI_IDN_USE_STD3_ASCII_RULES (1 << 12)
  186. /* Addrinfo flag values */
  187. #define ARES_AI_CANONNAME (1 << 0)
  188. #define ARES_AI_NUMERICHOST (1 << 1)
  189. #define ARES_AI_PASSIVE (1 << 2)
  190. #define ARES_AI_NUMERICSERV (1 << 3)
  191. #define ARES_AI_V4MAPPED (1 << 4)
  192. #define ARES_AI_ALL (1 << 5)
  193. #define ARES_AI_ADDRCONFIG (1 << 6)
  194. #define ARES_AI_NOSORT (1 << 7)
  195. #define ARES_AI_ENVHOSTS (1 << 8)
  196. /* Reserved for future use */
  197. #define ARES_AI_IDN (1 << 10)
  198. #define ARES_AI_IDN_ALLOW_UNASSIGNED (1 << 11)
  199. #define ARES_AI_IDN_USE_STD3_ASCII_RULES (1 << 12)
  200. #define ARES_AI_CANONIDN (1 << 13)
  201. #define ARES_AI_MASK (ARES_AI_CANONNAME|ARES_AI_NUMERICHOST|ARES_AI_PASSIVE| \
  202. ARES_AI_NUMERICSERV|ARES_AI_V4MAPPED|ARES_AI_ALL| \
  203. ARES_AI_ADDRCONFIG)
  204. #define ARES_GETSOCK_MAXNUM 16 /* ares_getsock() can return info about this
  205. many sockets */
  206. #define ARES_GETSOCK_READABLE(bits,num) (bits & (1<< (num)))
  207. #define ARES_GETSOCK_WRITABLE(bits,num) (bits & (1 << ((num) + \
  208. ARES_GETSOCK_MAXNUM)))
  209. /* c-ares library initialization flag values */
  210. #define ARES_LIB_INIT_NONE (0)
  211. #define ARES_LIB_INIT_WIN32 (1 << 0)
  212. #define ARES_LIB_INIT_ALL (ARES_LIB_INIT_WIN32)
  213. /*
  214. * Typedef our socket type
  215. */
  216. #ifndef ares_socket_typedef
  217. #ifdef WIN32
  218. typedef SOCKET ares_socket_t;
  219. #define ARES_SOCKET_BAD INVALID_SOCKET
  220. #else
  221. typedef int ares_socket_t;
  222. #define ARES_SOCKET_BAD -1
  223. #endif
  224. #define ares_socket_typedef
  225. #endif /* ares_socket_typedef */
  226. typedef void (*ares_sock_state_cb)(void *data,
  227. ares_socket_t socket_fd,
  228. int readable,
  229. int writable);
  230. struct apattern;
  231. /* NOTE about the ares_options struct to users and developers.
  232. This struct will remain looking like this. It will not be extended nor
  233. shrunk in future releases, but all new options will be set by ares_set_*()
  234. options instead of with the ares_init_options() function.
  235. Eventually (in a galaxy far far away), all options will be settable by
  236. ares_set_*() options and the ares_init_options() function will become
  237. deprecated.
  238. When new options are added to c-ares, they are not added to this
  239. struct. And they are not "saved" with the ares_save_options() function but
  240. instead we encourage the use of the ares_dup() function. Needless to say,
  241. if you add config options to c-ares you need to make sure ares_dup()
  242. duplicates this new option.
  243. */
  244. struct ares_options {
  245. int flags;
  246. int timeout; /* in seconds or milliseconds, depending on options */
  247. int maxtimeout; /* in milliseconds */
  248. int jitter; /* in .001 */
  249. unsigned int jitter_rand_seed;
  250. int tries;
  251. int ndots;
  252. unsigned short udp_port;
  253. unsigned short tcp_port;
  254. int socket_send_buffer_size;
  255. int socket_receive_buffer_size;
  256. struct in_addr *servers;
  257. int nservers;
  258. char **domains;
  259. int ndomains;
  260. char *lookups;
  261. ares_sock_state_cb sock_state_cb;
  262. void *sock_state_cb_data;
  263. struct apattern *sortlist;
  264. int nsort;
  265. int ednspsz;
  266. char *resolvconf_path;
  267. char *hosts_path;
  268. int udp_max_queries;
  269. };
  270. struct hostent;
  271. struct timeval;
  272. struct sockaddr;
  273. struct ares_channeldata;
  274. struct ares_addrinfo;
  275. struct ares_addrinfo_hints;
  276. typedef struct ares_channeldata *ares_channel;
  277. typedef void (*ares_callback)(void *arg,
  278. int status,
  279. int timeouts,
  280. unsigned char *abuf,
  281. int alen);
  282. typedef void (*ares_host_callback)(void *arg,
  283. int status,
  284. int timeouts,
  285. struct hostent *hostent);
  286. typedef void (*ares_nameinfo_callback)(void *arg,
  287. int status,
  288. int timeouts,
  289. char *node,
  290. char *service);
  291. typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd,
  292. int type,
  293. void *data);
  294. typedef int (*ares_sock_config_callback)(ares_socket_t socket_fd,
  295. int type,
  296. void *data);
  297. typedef void (*ares_addrinfo_callback)(void *arg,
  298. int status,
  299. int timeouts,
  300. struct ares_addrinfo *res);
  301. CARES_EXTERN int ares_library_init(int flags);
  302. CARES_EXTERN int ares_library_init_mem(int flags,
  303. void *(*amalloc)(size_t size),
  304. void (*afree)(void *ptr),
  305. void *(*arealloc)(void *ptr, size_t size));
  306. #if defined(ANDROID) || defined(__ANDROID__)
  307. CARES_EXTERN void ares_library_init_jvm(JavaVM *jvm);
  308. CARES_EXTERN int ares_library_init_android(jobject connectivity_manager);
  309. CARES_EXTERN int ares_library_android_initialized(void);
  310. #endif
  311. CARES_EXTERN int ares_library_initialized(void);
  312. CARES_EXTERN void ares_library_cleanup(void);
  313. CARES_EXTERN const char *ares_version(int *version);
  314. CARES_EXTERN int ares_init(ares_channel *channelptr);
  315. CARES_EXTERN int ares_init_options(ares_channel *channelptr,
  316. struct ares_options *options,
  317. int optmask);
  318. CARES_EXTERN int ares_save_options(ares_channel channel,
  319. struct ares_options *options,
  320. int *optmask);
  321. CARES_EXTERN void ares_destroy_options(struct ares_options *options);
  322. CARES_EXTERN int ares_dup(ares_channel *dest,
  323. ares_channel src);
  324. CARES_EXTERN void ares_destroy(ares_channel channel);
  325. CARES_EXTERN void ares_cancel(ares_channel channel);
  326. /* These next 3 configure local binding for the out-going socket
  327. * connection. Use these to specify source IP and/or network device
  328. * on multi-homed systems.
  329. */
  330. CARES_EXTERN void ares_set_local_ip4(ares_channel channel, unsigned int local_ip);
  331. /* local_ip6 should be 16 bytes in length */
  332. CARES_EXTERN void ares_set_local_ip6(ares_channel channel,
  333. const unsigned char* local_ip6);
  334. /* local_dev_name should be null terminated. */
  335. CARES_EXTERN void ares_set_local_dev(ares_channel channel,
  336. const char* local_dev_name);
  337. CARES_EXTERN void ares_set_socket_callback(ares_channel channel,
  338. ares_sock_create_callback callback,
  339. void *user_data);
  340. CARES_EXTERN void ares_set_socket_configure_callback(ares_channel channel,
  341. ares_sock_config_callback callback,
  342. void *user_data);
  343. CARES_EXTERN int ares_set_sortlist(ares_channel channel,
  344. const char *sortstr);
  345. CARES_EXTERN void ares_getaddrinfo(ares_channel channel,
  346. const char* node,
  347. const char* service,
  348. const struct ares_addrinfo_hints* hints,
  349. ares_addrinfo_callback callback,
  350. void* arg);
  351. CARES_EXTERN void ares_freeaddrinfo(struct ares_addrinfo* ai);
  352. /*
  353. * Virtual function set to have user-managed socket IO.
  354. * Note that all functions need to be defined, and when
  355. * set, the library will not do any bind nor set any
  356. * socket options, assuming the client handles these
  357. * through either socket creation or the
  358. * ares_sock_config_callback call.
  359. */
  360. struct iovec;
  361. struct ares_socket_functions {
  362. ares_socket_t(*asocket)(int, int, int, void *);
  363. int(*aclose)(ares_socket_t, void *);
  364. int(*aconnect)(ares_socket_t, const struct sockaddr *, ares_socklen_t, void *);
  365. ares_ssize_t(*arecvfrom)(ares_socket_t, void *, size_t, int, struct sockaddr *, ares_socklen_t *, void *);
  366. ares_ssize_t(*asendv)(ares_socket_t, const struct iovec *, int, void *);
  367. };
  368. CARES_EXTERN void ares_set_socket_functions(ares_channel channel,
  369. const struct ares_socket_functions * funcs,
  370. void *user_data);
  371. CARES_EXTERN void ares_send(ares_channel channel,
  372. const unsigned char *qbuf,
  373. int qlen,
  374. ares_callback callback,
  375. void *arg);
  376. CARES_EXTERN void ares_query(ares_channel channel,
  377. const char *name,
  378. int dnsclass,
  379. int type,
  380. ares_callback callback,
  381. void *arg);
  382. CARES_EXTERN void ares_search(ares_channel channel,
  383. const char *name,
  384. int dnsclass,
  385. int type,
  386. ares_callback callback,
  387. void *arg);
  388. CARES_EXTERN void ares_gethostbyname(ares_channel channel,
  389. const char *name,
  390. int family,
  391. ares_host_callback callback,
  392. void *arg);
  393. CARES_EXTERN int ares_gethostbyname_file(ares_channel channel,
  394. const char *name,
  395. int family,
  396. struct hostent **host);
  397. CARES_EXTERN void ares_gethostbyaddr(ares_channel channel,
  398. const void *addr,
  399. int addrlen,
  400. int family,
  401. ares_host_callback callback,
  402. void *arg);
  403. CARES_EXTERN void ares_getnameinfo(ares_channel channel,
  404. const struct sockaddr *sa,
  405. ares_socklen_t salen,
  406. int flags,
  407. ares_nameinfo_callback callback,
  408. void *arg);
  409. CARES_EXTERN int ares_fds(ares_channel channel,
  410. fd_set *read_fds,
  411. fd_set *write_fds);
  412. CARES_EXTERN int ares_getsock(ares_channel channel,
  413. ares_socket_t *socks,
  414. int numsocks);
  415. CARES_EXTERN struct timeval *ares_timeout(ares_channel channel,
  416. struct timeval *maxtv,
  417. struct timeval *tv);
  418. CARES_EXTERN void ares_process(ares_channel channel,
  419. fd_set *read_fds,
  420. fd_set *write_fds);
  421. CARES_EXTERN void ares_process_fd(ares_channel channel,
  422. ares_socket_t read_fd,
  423. ares_socket_t write_fd);
  424. CARES_EXTERN int ares_create_query(const char *name,
  425. int dnsclass,
  426. int type,
  427. unsigned short id,
  428. int rd,
  429. unsigned char **buf,
  430. int *buflen,
  431. int max_udp_size);
  432. CARES_EXTERN int ares_mkquery(const char *name,
  433. int dnsclass,
  434. int type,
  435. unsigned short id,
  436. int rd,
  437. unsigned char **buf,
  438. int *buflen);
  439. CARES_EXTERN int ares_expand_name(const unsigned char *encoded,
  440. const unsigned char *abuf,
  441. int alen,
  442. char **s,
  443. long *enclen);
  444. CARES_EXTERN int ares_expand_string(const unsigned char *encoded,
  445. const unsigned char *abuf,
  446. int alen,
  447. unsigned char **s,
  448. long *enclen);
  449. /*
  450. * NOTE: before c-ares 1.7.0 we would most often use the system in6_addr
  451. * struct below when ares itself was built, but many apps would use this
  452. * private version since the header checked a HAVE_* define for it. Starting
  453. * with 1.7.0 we always declare and use our own to stop relying on the
  454. * system's one.
  455. */
  456. struct ares_in6_addr {
  457. union {
  458. unsigned char _S6_u8[16];
  459. } _S6_un;
  460. };
  461. struct ares_addrttl {
  462. struct in_addr ipaddr;
  463. int ttl;
  464. };
  465. struct ares_addr6ttl {
  466. struct ares_in6_addr ip6addr;
  467. int ttl;
  468. };
  469. struct ares_caa_reply {
  470. struct ares_caa_reply *next;
  471. int critical;
  472. unsigned char *property;
  473. size_t plength; /* plength excludes null termination */
  474. unsigned char *value;
  475. size_t length; /* length excludes null termination */
  476. };
  477. struct ares_srv_reply {
  478. struct ares_srv_reply *next;
  479. char *host;
  480. unsigned short priority;
  481. unsigned short weight;
  482. unsigned short port;
  483. };
  484. struct ares_mx_reply {
  485. struct ares_mx_reply *next;
  486. char *host;
  487. unsigned short priority;
  488. };
  489. struct ares_txt_reply {
  490. struct ares_txt_reply *next;
  491. unsigned char *txt;
  492. size_t length; /* length excludes null termination */
  493. };
  494. /* NOTE: This structure is a superset of ares_txt_reply
  495. */
  496. struct ares_txt_ext {
  497. struct ares_txt_ext *next;
  498. unsigned char *txt;
  499. size_t length;
  500. /* 1 - if start of new record
  501. * 0 - if a chunk in the same record */
  502. unsigned char record_start;
  503. };
  504. struct ares_naptr_reply {
  505. struct ares_naptr_reply *next;
  506. unsigned char *flags;
  507. unsigned char *service;
  508. unsigned char *regexp;
  509. char *replacement;
  510. unsigned short order;
  511. unsigned short preference;
  512. };
  513. struct ares_soa_reply {
  514. char *nsname;
  515. char *hostmaster;
  516. unsigned int serial;
  517. unsigned int refresh;
  518. unsigned int retry;
  519. unsigned int expire;
  520. unsigned int minttl;
  521. };
  522. struct ares_uri_reply {
  523. struct ares_uri_reply *next;
  524. unsigned short priority;
  525. unsigned short weight;
  526. char *uri;
  527. int ttl;
  528. };
  529. /*
  530. * Similar to addrinfo, but with extra ttl and missing canonname.
  531. */
  532. struct ares_addrinfo_node {
  533. int ai_ttl;
  534. int ai_flags;
  535. int ai_family;
  536. int ai_socktype;
  537. int ai_protocol;
  538. ares_socklen_t ai_addrlen;
  539. struct sockaddr *ai_addr;
  540. struct ares_addrinfo_node *ai_next;
  541. };
  542. /*
  543. * alias - label of the resource record.
  544. * name - value (canonical name) of the resource record.
  545. * See RFC2181 10.1.1. CNAME terminology.
  546. */
  547. struct ares_addrinfo_cname {
  548. int ttl;
  549. char *alias;
  550. char *name;
  551. struct ares_addrinfo_cname *next;
  552. };
  553. struct ares_addrinfo {
  554. struct ares_addrinfo_cname *cnames;
  555. struct ares_addrinfo_node *nodes;
  556. char *name;
  557. };
  558. struct ares_addrinfo_hints {
  559. int ai_flags;
  560. int ai_family;
  561. int ai_socktype;
  562. int ai_protocol;
  563. };
  564. /*
  565. ** Parse the buffer, starting at *abuf and of length alen bytes, previously
  566. ** obtained from an ares_search call. Put the results in *host, if nonnull.
  567. ** Also, if addrttls is nonnull, put up to *naddrttls IPv4 addresses along with
  568. ** their TTLs in that array, and set *naddrttls to the number of addresses
  569. ** so written.
  570. */
  571. CARES_EXTERN int ares_parse_a_reply(const unsigned char *abuf,
  572. int alen,
  573. struct hostent **host,
  574. struct ares_addrttl *addrttls,
  575. int *naddrttls);
  576. CARES_EXTERN int ares_parse_aaaa_reply(const unsigned char *abuf,
  577. int alen,
  578. struct hostent **host,
  579. struct ares_addr6ttl *addrttls,
  580. int *naddrttls);
  581. CARES_EXTERN int ares_parse_caa_reply(const unsigned char* abuf,
  582. int alen,
  583. struct ares_caa_reply** caa_out);
  584. CARES_EXTERN int ares_parse_ptr_reply(const unsigned char *abuf,
  585. int alen,
  586. const void *addr,
  587. int addrlen,
  588. int family,
  589. struct hostent **host);
  590. CARES_EXTERN int ares_parse_ns_reply(const unsigned char *abuf,
  591. int alen,
  592. struct hostent **host);
  593. CARES_EXTERN int ares_parse_srv_reply(const unsigned char* abuf,
  594. int alen,
  595. struct ares_srv_reply** srv_out);
  596. CARES_EXTERN int ares_parse_mx_reply(const unsigned char* abuf,
  597. int alen,
  598. struct ares_mx_reply** mx_out);
  599. CARES_EXTERN int ares_parse_txt_reply(const unsigned char* abuf,
  600. int alen,
  601. struct ares_txt_reply** txt_out);
  602. CARES_EXTERN int ares_parse_txt_reply_ext(const unsigned char* abuf,
  603. int alen,
  604. struct ares_txt_ext** txt_out);
  605. CARES_EXTERN int ares_parse_naptr_reply(const unsigned char* abuf,
  606. int alen,
  607. struct ares_naptr_reply** naptr_out);
  608. CARES_EXTERN int ares_parse_soa_reply(const unsigned char* abuf,
  609. int alen,
  610. struct ares_soa_reply** soa_out);
  611. CARES_EXTERN int ares_parse_uri_reply(const unsigned char* abuf,
  612. int alen,
  613. struct ares_uri_reply** uri_out);
  614. CARES_EXTERN void ares_free_string(void *str);
  615. CARES_EXTERN void ares_free_hostent(struct hostent *host);
  616. CARES_EXTERN void ares_free_data(void *dataptr);
  617. CARES_EXTERN const char *ares_strerror(int code);
  618. struct ares_addr_node {
  619. struct ares_addr_node *next;
  620. int family;
  621. union {
  622. struct in_addr addr4;
  623. struct ares_in6_addr addr6;
  624. } addr;
  625. };
  626. struct ares_addr_port_node {
  627. struct ares_addr_port_node *next;
  628. int family;
  629. union {
  630. struct in_addr addr4;
  631. struct ares_in6_addr addr6;
  632. } addr;
  633. int udp_port;
  634. int tcp_port;
  635. };
  636. CARES_EXTERN int ares_set_servers(ares_channel channel,
  637. struct ares_addr_node *servers);
  638. CARES_EXTERN int ares_set_servers_ports(ares_channel channel,
  639. struct ares_addr_port_node *servers);
  640. /* Incomming string format: host[:port][,host[:port]]... */
  641. CARES_EXTERN int ares_set_servers_csv(ares_channel channel,
  642. const char* servers);
  643. CARES_EXTERN int ares_set_servers_ports_csv(ares_channel channel,
  644. const char* servers);
  645. CARES_EXTERN int ares_get_servers(ares_channel channel,
  646. struct ares_addr_node **servers);
  647. CARES_EXTERN int ares_get_servers_ports(ares_channel channel,
  648. struct ares_addr_port_node **servers);
  649. CARES_EXTERN const char *ares_inet_ntop(int af, const void *src, char *dst,
  650. ares_socklen_t size);
  651. CARES_EXTERN int ares_inet_pton(int af, const char *src, void *dst);
  652. #ifdef __cplusplus
  653. }
  654. #endif
  655. #endif /* ARES__H */