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