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