ares.h 26 KB

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