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