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__) 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 /* 222 * Typedef our socket type 223 */ 224 225 #ifndef ares_socket_typedef 226 #ifdef WIN32 227 typedef SOCKET ares_socket_t; 228 #define ARES_SOCKET_BAD INVALID_SOCKET 229 #else 230 typedef int ares_socket_t; 231 #define ARES_SOCKET_BAD -1 232 #endif 233 #define ares_socket_typedef 234 #endif /* ares_socket_typedef */ 235 236 typedef void (*ares_sock_state_cb)(void *data, 237 ares_socket_t socket_fd, 238 int readable, 239 int writable); 240 241 struct apattern; 242 243 /* NOTE about the ares_options struct to users and developers. 244 245 This struct will remain looking like this. It will not be extended nor 246 shrunk in future releases, but all new options will be set by ares_set_*() 247 options instead of with the ares_init_options() function. 248 249 Eventually (in a galaxy far far away), all options will be settable by 250 ares_set_*() options and the ares_init_options() function will become 251 deprecated. 252 253 When new options are added to c-ares, they are not added to this 254 struct. And they are not "saved" with the ares_save_options() function but 255 instead we encourage the use of the ares_dup() function. Needless to say, 256 if you add config options to c-ares you need to make sure ares_dup() 257 duplicates this new option. 258 259 */ 260 struct ares_options { 261 int flags; 262 int timeout; /* in seconds or milliseconds, depending on options */ 263 int tries; 264 int ndots; 265 unsigned short udp_port; 266 unsigned short tcp_port; 267 int socket_send_buffer_size; 268 int socket_receive_buffer_size; 269 struct in_addr *servers; 270 int nservers; 271 char **domains; 272 int ndomains; 273 char *lookups; 274 ares_sock_state_cb sock_state_cb; 275 void *sock_state_cb_data; 276 struct apattern *sortlist; 277 int nsort; 278 int ednspsz; 279 char *resolvconf_path; 280 }; 281 282 struct hostent; 283 struct timeval; 284 struct sockaddr; 285 struct ares_channeldata; 286 struct ares_addrinfo; 287 struct ares_addrinfo_hints; 288 289 typedef struct ares_channeldata *ares_channel; 290 291 typedef void (*ares_callback)(void *arg, 292 int status, 293 int timeouts, 294 unsigned char *abuf, 295 int alen); 296 297 typedef void (*ares_host_callback)(void *arg, 298 int status, 299 int timeouts, 300 struct hostent *hostent); 301 302 typedef void (*ares_nameinfo_callback)(void *arg, 303 int status, 304 int timeouts, 305 char *node, 306 char *service); 307 308 typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd, 309 int type, 310 void *data); 311 312 typedef int (*ares_sock_config_callback)(ares_socket_t socket_fd, 313 int type, 314 void *data); 315 316 typedef void (*ares_addrinfo_callback)(void *arg, 317 int status, 318 int timeouts, 319 struct ares_addrinfo *res); 320 321 CARES_EXTERN int ares_library_init(int flags); 322 323 CARES_EXTERN int ares_library_init_mem(int flags, 324 void *(*amalloc)(size_t size), 325 void (*afree)(void *ptr), 326 void *(*arealloc)(void *ptr, size_t size)); 327 328 #if defined(ANDROID) || defined(__ANDROID__) 329 CARES_EXTERN void ares_library_init_jvm(JavaVM *jvm); 330 CARES_EXTERN int ares_library_init_android(jobject connectivity_manager); 331 CARES_EXTERN int ares_library_android_initialized(void); 332 #endif 333 334 CARES_EXTERN int ares_library_initialized(void); 335 336 CARES_EXTERN void ares_library_cleanup(void); 337 338 CARES_EXTERN const char *ares_version(int *version); 339 340 CARES_EXTERN int ares_init(ares_channel *channelptr); 341 342 CARES_EXTERN int ares_init_options(ares_channel *channelptr, 343 struct ares_options *options, 344 int optmask); 345 346 CARES_EXTERN int ares_save_options(ares_channel channel, 347 struct ares_options *options, 348 int *optmask); 349 350 CARES_EXTERN void ares_destroy_options(struct ares_options *options); 351 352 CARES_EXTERN int ares_dup(ares_channel *dest, 353 ares_channel src); 354 355 CARES_EXTERN void ares_destroy(ares_channel channel); 356 357 CARES_EXTERN void ares_cancel(ares_channel channel); 358 359 /* These next 3 configure local binding for the out-going socket 360 * connection. Use these to specify source IP and/or network device 361 * on multi-homed systems. 362 */ 363 CARES_EXTERN void ares_set_local_ip4(ares_channel channel, unsigned int local_ip); 364 365 /* local_ip6 should be 16 bytes in length */ 366 CARES_EXTERN void ares_set_local_ip6(ares_channel channel, 367 const unsigned char* local_ip6); 368 369 /* local_dev_name should be null terminated. */ 370 CARES_EXTERN void ares_set_local_dev(ares_channel channel, 371 const char* local_dev_name); 372 373 CARES_EXTERN void ares_set_socket_callback(ares_channel channel, 374 ares_sock_create_callback callback, 375 void *user_data); 376 377 CARES_EXTERN void ares_set_socket_configure_callback(ares_channel channel, 378 ares_sock_config_callback callback, 379 void *user_data); 380 381 CARES_EXTERN int ares_set_sortlist(ares_channel channel, 382 const char *sortstr); 383 384 CARES_EXTERN void ares_getaddrinfo(ares_channel channel, 385 const char* node, 386 const char* service, 387 const struct ares_addrinfo_hints* hints, 388 ares_addrinfo_callback callback, 389 void* arg); 390 391 CARES_EXTERN void ares_freeaddrinfo(struct ares_addrinfo* ai); 392 393 /* 394 * Virtual function set to have user-managed socket IO. 395 * Note that all functions need to be defined, and when 396 * set, the library will not do any bind nor set any 397 * socket options, assuming the client handles these 398 * through either socket creation or the 399 * ares_sock_config_callback call. 400 */ 401 struct iovec; 402 struct ares_socket_functions { 403 ares_socket_t(*asocket)(int, int, int, void *); 404 int(*aclose)(ares_socket_t, void *); 405 int(*aconnect)(ares_socket_t, const struct sockaddr *, ares_socklen_t, void *); 406 ares_ssize_t(*arecvfrom)(ares_socket_t, void *, size_t, int, struct sockaddr *, ares_socklen_t *, void *); 407 ares_ssize_t(*asendv)(ares_socket_t, const struct iovec *, int, void *); 408 }; 409 410 CARES_EXTERN void ares_set_socket_functions(ares_channel channel, 411 const struct ares_socket_functions * funcs, 412 void *user_data); 413 414 CARES_EXTERN void ares_send(ares_channel channel, 415 const unsigned char *qbuf, 416 int qlen, 417 ares_callback callback, 418 void *arg); 419 420 CARES_EXTERN void ares_query(ares_channel channel, 421 const char *name, 422 int dnsclass, 423 int type, 424 ares_callback callback, 425 void *arg); 426 427 CARES_EXTERN void ares_search(ares_channel channel, 428 const char *name, 429 int dnsclass, 430 int type, 431 ares_callback callback, 432 void *arg); 433 434 CARES_EXTERN void ares_gethostbyname(ares_channel channel, 435 const char *name, 436 int family, 437 ares_host_callback callback, 438 void *arg); 439 440 CARES_EXTERN int ares_gethostbyname_file(ares_channel channel, 441 const char *name, 442 int family, 443 struct hostent **host); 444 445 CARES_EXTERN void ares_gethostbyaddr(ares_channel channel, 446 const void *addr, 447 int addrlen, 448 int family, 449 ares_host_callback callback, 450 void *arg); 451 452 CARES_EXTERN void ares_getnameinfo(ares_channel channel, 453 const struct sockaddr *sa, 454 ares_socklen_t salen, 455 int flags, 456 ares_nameinfo_callback callback, 457 void *arg); 458 459 CARES_EXTERN int ares_fds(ares_channel channel, 460 fd_set *read_fds, 461 fd_set *write_fds); 462 463 CARES_EXTERN int ares_getsock(ares_channel channel, 464 ares_socket_t *socks, 465 int numsocks); 466 467 CARES_EXTERN struct timeval *ares_timeout(ares_channel channel, 468 struct timeval *maxtv, 469 struct timeval *tv); 470 471 CARES_EXTERN void ares_process(ares_channel channel, 472 fd_set *read_fds, 473 fd_set *write_fds); 474 475 CARES_EXTERN void ares_process_fd(ares_channel channel, 476 ares_socket_t read_fd, 477 ares_socket_t write_fd); 478 479 CARES_EXTERN int ares_create_query(const char *name, 480 int dnsclass, 481 int type, 482 unsigned short id, 483 int rd, 484 unsigned char **buf, 485 int *buflen, 486 int max_udp_size); 487 488 CARES_EXTERN int ares_mkquery(const char *name, 489 int dnsclass, 490 int type, 491 unsigned short id, 492 int rd, 493 unsigned char **buf, 494 int *buflen); 495 496 CARES_EXTERN int ares_expand_name(const unsigned char *encoded, 497 const unsigned char *abuf, 498 int alen, 499 char **s, 500 long *enclen); 501 502 CARES_EXTERN int ares_expand_string(const unsigned char *encoded, 503 const unsigned char *abuf, 504 int alen, 505 unsigned char **s, 506 long *enclen); 507 508 /* 509 * NOTE: before c-ares 1.7.0 we would most often use the system in6_addr 510 * struct below when ares itself was built, but many apps would use this 511 * private version since the header checked a HAVE_* define for it. Starting 512 * with 1.7.0 we always declare and use our own to stop relying on the 513 * system's one. 514 */ 515 struct ares_in6_addr { 516 union { 517 unsigned char _S6_u8[16]; 518 } _S6_un; 519 }; 520 521 struct ares_addrttl { 522 struct in_addr ipaddr; 523 int ttl; 524 }; 525 526 struct ares_addr6ttl { 527 struct ares_in6_addr ip6addr; 528 int ttl; 529 }; 530 531 struct ares_srv_reply { 532 struct ares_srv_reply *next; 533 char *host; 534 unsigned short priority; 535 unsigned short weight; 536 unsigned short port; 537 }; 538 539 struct ares_mx_reply { 540 struct ares_mx_reply *next; 541 char *host; 542 unsigned short priority; 543 }; 544 545 struct ares_txt_reply { 546 struct ares_txt_reply *next; 547 unsigned char *txt; 548 size_t length; /* length excludes null termination */ 549 }; 550 551 /* NOTE: This structure is a superset of ares_txt_reply 552 */ 553 struct ares_txt_ext { 554 struct ares_txt_ext *next; 555 unsigned char *txt; 556 size_t length; 557 /* 1 - if start of new record 558 * 0 - if a chunk in the same record */ 559 unsigned char record_start; 560 }; 561 562 struct ares_naptr_reply { 563 struct ares_naptr_reply *next; 564 unsigned char *flags; 565 unsigned char *service; 566 unsigned char *regexp; 567 char *replacement; 568 unsigned short order; 569 unsigned short preference; 570 }; 571 572 struct ares_soa_reply { 573 char *nsname; 574 char *hostmaster; 575 unsigned int serial; 576 unsigned int refresh; 577 unsigned int retry; 578 unsigned int expire; 579 unsigned int minttl; 580 }; 581 582 /* 583 * Similar to addrinfo, but with extra ttl and missing canonname. 584 */ 585 struct ares_addrinfo_node { 586 int ai_ttl; 587 int ai_flags; 588 int ai_family; 589 int ai_socktype; 590 int ai_protocol; 591 ares_socklen_t ai_addrlen; 592 struct sockaddr *ai_addr; 593 struct ares_addrinfo_node *ai_next; 594 }; 595 596 /* 597 * alias - label of the resource record. 598 * name - value (canonical name) of the resource record. 599 * See RFC2181 10.1.1. CNAME terminology. 600 */ 601 struct ares_addrinfo_cname { 602 int ttl; 603 char *alias; 604 char *name; 605 struct ares_addrinfo_cname *next; 606 }; 607 608 struct ares_addrinfo { 609 struct ares_addrinfo_cname *cnames; 610 struct ares_addrinfo_node *nodes; 611 }; 612 613 struct ares_addrinfo_hints { 614 int ai_flags; 615 int ai_family; 616 int ai_socktype; 617 int ai_protocol; 618 }; 619 620 /* 621 ** Parse the buffer, starting at *abuf and of length alen bytes, previously 622 ** obtained from an ares_search call. Put the results in *host, if nonnull. 623 ** Also, if addrttls is nonnull, put up to *naddrttls IPv4 addresses along with 624 ** their TTLs in that array, and set *naddrttls to the number of addresses 625 ** so written. 626 */ 627 628 CARES_EXTERN int ares_parse_a_reply(const unsigned char *abuf, 629 int alen, 630 struct hostent **host, 631 struct ares_addrttl *addrttls, 632 int *naddrttls); 633 634 CARES_EXTERN int ares_parse_aaaa_reply(const unsigned char *abuf, 635 int alen, 636 struct hostent **host, 637 struct ares_addr6ttl *addrttls, 638 int *naddrttls); 639 640 CARES_EXTERN int ares_parse_ptr_reply(const unsigned char *abuf, 641 int alen, 642 const void *addr, 643 int addrlen, 644 int family, 645 struct hostent **host); 646 647 CARES_EXTERN int ares_parse_ns_reply(const unsigned char *abuf, 648 int alen, 649 struct hostent **host); 650 651 CARES_EXTERN int ares_parse_srv_reply(const unsigned char* abuf, 652 int alen, 653 struct ares_srv_reply** srv_out); 654 655 CARES_EXTERN int ares_parse_mx_reply(const unsigned char* abuf, 656 int alen, 657 struct ares_mx_reply** mx_out); 658 659 CARES_EXTERN int ares_parse_txt_reply(const unsigned char* abuf, 660 int alen, 661 struct ares_txt_reply** txt_out); 662 663 CARES_EXTERN int ares_parse_txt_reply_ext(const unsigned char* abuf, 664 int alen, 665 struct ares_txt_ext** txt_out); 666 667 CARES_EXTERN int ares_parse_naptr_reply(const unsigned char* abuf, 668 int alen, 669 struct ares_naptr_reply** naptr_out); 670 671 CARES_EXTERN int ares_parse_soa_reply(const unsigned char* abuf, 672 int alen, 673 struct ares_soa_reply** soa_out); 674 675 CARES_EXTERN void ares_free_string(void *str); 676 677 CARES_EXTERN void ares_free_hostent(struct hostent *host); 678 679 CARES_EXTERN void ares_free_data(void *dataptr); 680 681 CARES_EXTERN const char *ares_strerror(int code); 682 683 struct ares_addr_node { 684 struct ares_addr_node *next; 685 int family; 686 union { 687 struct in_addr addr4; 688 struct ares_in6_addr addr6; 689 } addr; 690 }; 691 692 struct ares_addr_port_node { 693 struct ares_addr_port_node *next; 694 int family; 695 union { 696 struct in_addr addr4; 697 struct ares_in6_addr addr6; 698 } addr; 699 int udp_port; 700 int tcp_port; 701 }; 702 703 CARES_EXTERN int ares_set_servers(ares_channel channel, 704 struct ares_addr_node *servers); 705 CARES_EXTERN int ares_set_servers_ports(ares_channel channel, 706 struct ares_addr_port_node *servers); 707 708 /* Incomming string format: host[:port][,host[:port]]... */ 709 CARES_EXTERN int ares_set_servers_csv(ares_channel channel, 710 const char* servers); 711 CARES_EXTERN int ares_set_servers_ports_csv(ares_channel channel, 712 const char* servers); 713 714 CARES_EXTERN int ares_get_servers(ares_channel channel, 715 struct ares_addr_node **servers); 716 CARES_EXTERN int ares_get_servers_ports(ares_channel channel, 717 struct ares_addr_port_node **servers); 718 719 CARES_EXTERN const char *ares_inet_ntop(int af, const void *src, char *dst, 720 ares_socklen_t size); 721 722 CARES_EXTERN int ares_inet_pton(int af, const char *src, void *dst); 723 724 725 #ifdef __cplusplus 726 } 727 #endif 728 729 #endif /* ARES__H */ 730