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