11cb0ef41Sopenharmony_ci/* MIT License 21cb0ef41Sopenharmony_ci * 31cb0ef41Sopenharmony_ci * Copyright (c) Massachusetts Institute of Technology 41cb0ef41Sopenharmony_ci * Copyright (c) Daniel Stenberg 51cb0ef41Sopenharmony_ci * 61cb0ef41Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 71cb0ef41Sopenharmony_ci * of this software and associated documentation files (the "Software"), to deal 81cb0ef41Sopenharmony_ci * in the Software without restriction, including without limitation the rights 91cb0ef41Sopenharmony_ci * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 101cb0ef41Sopenharmony_ci * copies of the Software, and to permit persons to whom the Software is 111cb0ef41Sopenharmony_ci * furnished to do so, subject to the following conditions: 121cb0ef41Sopenharmony_ci * 131cb0ef41Sopenharmony_ci * The above copyright notice and this permission notice (including the next 141cb0ef41Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 151cb0ef41Sopenharmony_ci * Software. 161cb0ef41Sopenharmony_ci * 171cb0ef41Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 181cb0ef41Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 191cb0ef41Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 201cb0ef41Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 211cb0ef41Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 221cb0ef41Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 231cb0ef41Sopenharmony_ci * SOFTWARE. 241cb0ef41Sopenharmony_ci * 251cb0ef41Sopenharmony_ci * SPDX-License-Identifier: MIT 261cb0ef41Sopenharmony_ci */ 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci#ifndef ARES__H 291cb0ef41Sopenharmony_ci#define ARES__H 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci#include "ares_version.h" /* c-ares version defines */ 321cb0ef41Sopenharmony_ci#include "ares_build.h" /* c-ares build definitions */ 331cb0ef41Sopenharmony_ci#include "ares_rules.h" /* c-ares rules enforcement */ 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci/* 361cb0ef41Sopenharmony_ci * Define WIN32 when build target is Win32 API 371cb0ef41Sopenharmony_ci */ 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) && \ 401cb0ef41Sopenharmony_ci !defined(__SYMBIAN32__) 411cb0ef41Sopenharmony_ci# define WIN32 421cb0ef41Sopenharmony_ci#endif 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci#include <sys/types.h> 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish 471cb0ef41Sopenharmony_ci libc5-based Linux systems. Only include it on system that are known to 481cb0ef41Sopenharmony_ci require it! */ 491cb0ef41Sopenharmony_ci#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \ 501cb0ef41Sopenharmony_ci defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \ 511cb0ef41Sopenharmony_ci defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \ 521cb0ef41Sopenharmony_ci defined(__QNXNTO__) || defined(__MVS__) || defined(__HAIKU__) 531cb0ef41Sopenharmony_ci# include <sys/select.h> 541cb0ef41Sopenharmony_ci#endif 551cb0ef41Sopenharmony_ci#if (defined(NETWARE) && !defined(__NOVELL_LIBC__)) 561cb0ef41Sopenharmony_ci# include <sys/bsdskt.h> 571cb0ef41Sopenharmony_ci#endif 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci#if defined(WATT32) 601cb0ef41Sopenharmony_ci# include <netinet/in.h> 611cb0ef41Sopenharmony_ci# include <sys/socket.h> 621cb0ef41Sopenharmony_ci# include <tcp.h> 631cb0ef41Sopenharmony_ci#elif defined(_WIN32_WCE) 641cb0ef41Sopenharmony_ci# ifndef WIN32_LEAN_AND_MEAN 651cb0ef41Sopenharmony_ci# define WIN32_LEAN_AND_MEAN 661cb0ef41Sopenharmony_ci# endif 671cb0ef41Sopenharmony_ci# include <windows.h> 681cb0ef41Sopenharmony_ci# include <winsock.h> 691cb0ef41Sopenharmony_ci#elif defined(WIN32) 701cb0ef41Sopenharmony_ci# ifndef WIN32_LEAN_AND_MEAN 711cb0ef41Sopenharmony_ci# define WIN32_LEAN_AND_MEAN 721cb0ef41Sopenharmony_ci# endif 731cb0ef41Sopenharmony_ci# include <windows.h> 741cb0ef41Sopenharmony_ci# include <winsock2.h> 751cb0ef41Sopenharmony_ci# include <ws2tcpip.h> 761cb0ef41Sopenharmony_ci/* To aid with linking against a static c-ares build, lets tell the microsoft 771cb0ef41Sopenharmony_ci * compiler to pull in needed dependencies */ 781cb0ef41Sopenharmony_ci# ifdef _MSC_VER 791cb0ef41Sopenharmony_ci# pragma comment(lib, "ws2_32") 801cb0ef41Sopenharmony_ci# pragma comment(lib, "advapi32") 811cb0ef41Sopenharmony_ci# pragma comment(lib, "iphlpapi") 821cb0ef41Sopenharmony_ci# endif 831cb0ef41Sopenharmony_ci#else 841cb0ef41Sopenharmony_ci# include <sys/socket.h> 851cb0ef41Sopenharmony_ci# include <netinet/in.h> 861cb0ef41Sopenharmony_ci#endif 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ci#if defined(ANDROID) || defined(__ANDROID__) 891cb0ef41Sopenharmony_ci# include <jni.h> 901cb0ef41Sopenharmony_ci#endif 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_ci#ifdef __cplusplus 931cb0ef41Sopenharmony_ciextern "C" { 941cb0ef41Sopenharmony_ci#endif 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ci/* 971cb0ef41Sopenharmony_ci** c-ares external API function linkage decorations. 981cb0ef41Sopenharmony_ci*/ 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci#if defined(_WIN32) || defined(__CYGWIN__) || defined(__SYMBIAN32__) 1011cb0ef41Sopenharmony_ci# ifdef CARES_STATICLIB 1021cb0ef41Sopenharmony_ci# define CARES_EXTERN 1031cb0ef41Sopenharmony_ci# else 1041cb0ef41Sopenharmony_ci# ifdef CARES_BUILDING_LIBRARY 1051cb0ef41Sopenharmony_ci# define CARES_EXTERN __declspec(dllexport) 1061cb0ef41Sopenharmony_ci# else 1071cb0ef41Sopenharmony_ci# define CARES_EXTERN __declspec(dllimport) 1081cb0ef41Sopenharmony_ci# endif 1091cb0ef41Sopenharmony_ci# endif 1101cb0ef41Sopenharmony_ci#else 1111cb0ef41Sopenharmony_ci# if defined(__GNUC__) && __GNUC__ >= 4 1121cb0ef41Sopenharmony_ci# define CARES_EXTERN __attribute__((visibility("default"))) 1131cb0ef41Sopenharmony_ci# elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 900 1141cb0ef41Sopenharmony_ci# define CARES_EXTERN __attribute__((visibility("default"))) 1151cb0ef41Sopenharmony_ci# elif defined(__SUNPRO_C) 1161cb0ef41Sopenharmony_ci# define CARES_EXTERN _global 1171cb0ef41Sopenharmony_ci# else 1181cb0ef41Sopenharmony_ci# define CARES_EXTERN 1191cb0ef41Sopenharmony_ci# endif 1201cb0ef41Sopenharmony_ci#endif 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_citypedef enum { 1231cb0ef41Sopenharmony_ci ARES_SUCCESS = 0, 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_ci /* Server error codes (ARES_ENODATA indicates no relevant answer) */ 1261cb0ef41Sopenharmony_ci ARES_ENODATA = 1, 1271cb0ef41Sopenharmony_ci ARES_EFORMERR = 2, 1281cb0ef41Sopenharmony_ci ARES_ESERVFAIL = 3, 1291cb0ef41Sopenharmony_ci ARES_ENOTFOUND = 4, 1301cb0ef41Sopenharmony_ci ARES_ENOTIMP = 5, 1311cb0ef41Sopenharmony_ci ARES_EREFUSED = 6, 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci /* Locally generated error codes */ 1341cb0ef41Sopenharmony_ci ARES_EBADQUERY = 7, 1351cb0ef41Sopenharmony_ci ARES_EBADNAME = 8, 1361cb0ef41Sopenharmony_ci ARES_EBADFAMILY = 9, 1371cb0ef41Sopenharmony_ci ARES_EBADRESP = 10, 1381cb0ef41Sopenharmony_ci ARES_ECONNREFUSED = 11, 1391cb0ef41Sopenharmony_ci ARES_ETIMEOUT = 12, 1401cb0ef41Sopenharmony_ci ARES_EOF = 13, 1411cb0ef41Sopenharmony_ci ARES_EFILE = 14, 1421cb0ef41Sopenharmony_ci ARES_ENOMEM = 15, 1431cb0ef41Sopenharmony_ci ARES_EDESTRUCTION = 16, 1441cb0ef41Sopenharmony_ci ARES_EBADSTR = 17, 1451cb0ef41Sopenharmony_ci 1461cb0ef41Sopenharmony_ci /* ares_getnameinfo error codes */ 1471cb0ef41Sopenharmony_ci ARES_EBADFLAGS = 18, 1481cb0ef41Sopenharmony_ci 1491cb0ef41Sopenharmony_ci /* ares_getaddrinfo error codes */ 1501cb0ef41Sopenharmony_ci ARES_ENONAME = 19, 1511cb0ef41Sopenharmony_ci ARES_EBADHINTS = 20, 1521cb0ef41Sopenharmony_ci 1531cb0ef41Sopenharmony_ci /* Uninitialized library error code */ 1541cb0ef41Sopenharmony_ci ARES_ENOTINITIALIZED = 21, /* introduced in 1.7.0 */ 1551cb0ef41Sopenharmony_ci 1561cb0ef41Sopenharmony_ci /* ares_library_init error codes */ 1571cb0ef41Sopenharmony_ci ARES_ELOADIPHLPAPI = 22, /* introduced in 1.7.0 */ 1581cb0ef41Sopenharmony_ci ARES_EADDRGETNETWORKPARAMS = 23, /* introduced in 1.7.0 */ 1591cb0ef41Sopenharmony_ci 1601cb0ef41Sopenharmony_ci /* More error codes */ 1611cb0ef41Sopenharmony_ci ARES_ECANCELLED = 24, /* introduced in 1.7.0 */ 1621cb0ef41Sopenharmony_ci 1631cb0ef41Sopenharmony_ci /* More ares_getaddrinfo error codes */ 1641cb0ef41Sopenharmony_ci ARES_ESERVICE = 25, /* ares_getaddrinfo() was passed a text service name that 1651cb0ef41Sopenharmony_ci * is not recognized. introduced in 1.16.0 */ 1661cb0ef41Sopenharmony_ci 1671cb0ef41Sopenharmony_ci ARES_ENOSERVER = 26 /* No DNS servers were configured */ 1681cb0ef41Sopenharmony_ci} ares_status_t; 1691cb0ef41Sopenharmony_ci 1701cb0ef41Sopenharmony_citypedef enum { 1711cb0ef41Sopenharmony_ci ARES_FALSE = 0, 1721cb0ef41Sopenharmony_ci ARES_TRUE = 1 1731cb0ef41Sopenharmony_ci} ares_bool_t; 1741cb0ef41Sopenharmony_ci 1751cb0ef41Sopenharmony_ci/*! Values for ARES_OPT_EVENT_THREAD */ 1761cb0ef41Sopenharmony_citypedef enum { 1771cb0ef41Sopenharmony_ci /*! Default (best choice) event system */ 1781cb0ef41Sopenharmony_ci ARES_EVSYS_DEFAULT = 0, 1791cb0ef41Sopenharmony_ci /*! Win32 IOCP/AFD_POLL event system */ 1801cb0ef41Sopenharmony_ci ARES_EVSYS_WIN32 = 1, 1811cb0ef41Sopenharmony_ci /*! Linux epoll */ 1821cb0ef41Sopenharmony_ci ARES_EVSYS_EPOLL = 2, 1831cb0ef41Sopenharmony_ci /*! BSD/MacOS kqueue */ 1841cb0ef41Sopenharmony_ci ARES_EVSYS_KQUEUE = 3, 1851cb0ef41Sopenharmony_ci /*! POSIX poll() */ 1861cb0ef41Sopenharmony_ci ARES_EVSYS_POLL = 4, 1871cb0ef41Sopenharmony_ci /*! last fallback on Unix-like systems, select() */ 1881cb0ef41Sopenharmony_ci ARES_EVSYS_SELECT = 5 1891cb0ef41Sopenharmony_ci} ares_evsys_t; 1901cb0ef41Sopenharmony_ci 1911cb0ef41Sopenharmony_ci/* Flag values */ 1921cb0ef41Sopenharmony_ci#define ARES_FLAG_USEVC (1 << 0) 1931cb0ef41Sopenharmony_ci#define ARES_FLAG_PRIMARY (1 << 1) 1941cb0ef41Sopenharmony_ci#define ARES_FLAG_IGNTC (1 << 2) 1951cb0ef41Sopenharmony_ci#define ARES_FLAG_NORECURSE (1 << 3) 1961cb0ef41Sopenharmony_ci#define ARES_FLAG_STAYOPEN (1 << 4) 1971cb0ef41Sopenharmony_ci#define ARES_FLAG_NOSEARCH (1 << 5) 1981cb0ef41Sopenharmony_ci#define ARES_FLAG_NOALIASES (1 << 6) 1991cb0ef41Sopenharmony_ci#define ARES_FLAG_NOCHECKRESP (1 << 7) 2001cb0ef41Sopenharmony_ci#define ARES_FLAG_EDNS (1 << 8) 2011cb0ef41Sopenharmony_ci#define ARES_FLAG_NO_DFLT_SVR (1 << 9) 2021cb0ef41Sopenharmony_ci 2031cb0ef41Sopenharmony_ci/* Option mask values */ 2041cb0ef41Sopenharmony_ci#define ARES_OPT_FLAGS (1 << 0) 2051cb0ef41Sopenharmony_ci#define ARES_OPT_TIMEOUT (1 << 1) 2061cb0ef41Sopenharmony_ci#define ARES_OPT_TRIES (1 << 2) 2071cb0ef41Sopenharmony_ci#define ARES_OPT_NDOTS (1 << 3) 2081cb0ef41Sopenharmony_ci#define ARES_OPT_UDP_PORT (1 << 4) 2091cb0ef41Sopenharmony_ci#define ARES_OPT_TCP_PORT (1 << 5) 2101cb0ef41Sopenharmony_ci#define ARES_OPT_SERVERS (1 << 6) 2111cb0ef41Sopenharmony_ci#define ARES_OPT_DOMAINS (1 << 7) 2121cb0ef41Sopenharmony_ci#define ARES_OPT_LOOKUPS (1 << 8) 2131cb0ef41Sopenharmony_ci#define ARES_OPT_SOCK_STATE_CB (1 << 9) 2141cb0ef41Sopenharmony_ci#define ARES_OPT_SORTLIST (1 << 10) 2151cb0ef41Sopenharmony_ci#define ARES_OPT_SOCK_SNDBUF (1 << 11) 2161cb0ef41Sopenharmony_ci#define ARES_OPT_SOCK_RCVBUF (1 << 12) 2171cb0ef41Sopenharmony_ci#define ARES_OPT_TIMEOUTMS (1 << 13) 2181cb0ef41Sopenharmony_ci#define ARES_OPT_ROTATE (1 << 14) 2191cb0ef41Sopenharmony_ci#define ARES_OPT_EDNSPSZ (1 << 15) 2201cb0ef41Sopenharmony_ci#define ARES_OPT_NOROTATE (1 << 16) 2211cb0ef41Sopenharmony_ci#define ARES_OPT_RESOLVCONF (1 << 17) 2221cb0ef41Sopenharmony_ci#define ARES_OPT_HOSTS_FILE (1 << 18) 2231cb0ef41Sopenharmony_ci#define ARES_OPT_UDP_MAX_QUERIES (1 << 19) 2241cb0ef41Sopenharmony_ci#define ARES_OPT_MAXTIMEOUTMS (1 << 20) 2251cb0ef41Sopenharmony_ci#define ARES_OPT_QUERY_CACHE (1 << 21) 2261cb0ef41Sopenharmony_ci#define ARES_OPT_EVENT_THREAD (1 << 22) 2271cb0ef41Sopenharmony_ci 2281cb0ef41Sopenharmony_ci/* Nameinfo flag values */ 2291cb0ef41Sopenharmony_ci#define ARES_NI_NOFQDN (1 << 0) 2301cb0ef41Sopenharmony_ci#define ARES_NI_NUMERICHOST (1 << 1) 2311cb0ef41Sopenharmony_ci#define ARES_NI_NAMEREQD (1 << 2) 2321cb0ef41Sopenharmony_ci#define ARES_NI_NUMERICSERV (1 << 3) 2331cb0ef41Sopenharmony_ci#define ARES_NI_DGRAM (1 << 4) 2341cb0ef41Sopenharmony_ci#define ARES_NI_TCP 0 2351cb0ef41Sopenharmony_ci#define ARES_NI_UDP ARES_NI_DGRAM 2361cb0ef41Sopenharmony_ci#define ARES_NI_SCTP (1 << 5) 2371cb0ef41Sopenharmony_ci#define ARES_NI_DCCP (1 << 6) 2381cb0ef41Sopenharmony_ci#define ARES_NI_NUMERICSCOPE (1 << 7) 2391cb0ef41Sopenharmony_ci#define ARES_NI_LOOKUPHOST (1 << 8) 2401cb0ef41Sopenharmony_ci#define ARES_NI_LOOKUPSERVICE (1 << 9) 2411cb0ef41Sopenharmony_ci/* Reserved for future use */ 2421cb0ef41Sopenharmony_ci#define ARES_NI_IDN (1 << 10) 2431cb0ef41Sopenharmony_ci#define ARES_NI_IDN_ALLOW_UNASSIGNED (1 << 11) 2441cb0ef41Sopenharmony_ci#define ARES_NI_IDN_USE_STD3_ASCII_RULES (1 << 12) 2451cb0ef41Sopenharmony_ci 2461cb0ef41Sopenharmony_ci/* Addrinfo flag values */ 2471cb0ef41Sopenharmony_ci#define ARES_AI_CANONNAME (1 << 0) 2481cb0ef41Sopenharmony_ci#define ARES_AI_NUMERICHOST (1 << 1) 2491cb0ef41Sopenharmony_ci#define ARES_AI_PASSIVE (1 << 2) 2501cb0ef41Sopenharmony_ci#define ARES_AI_NUMERICSERV (1 << 3) 2511cb0ef41Sopenharmony_ci#define ARES_AI_V4MAPPED (1 << 4) 2521cb0ef41Sopenharmony_ci#define ARES_AI_ALL (1 << 5) 2531cb0ef41Sopenharmony_ci#define ARES_AI_ADDRCONFIG (1 << 6) 2541cb0ef41Sopenharmony_ci#define ARES_AI_NOSORT (1 << 7) 2551cb0ef41Sopenharmony_ci#define ARES_AI_ENVHOSTS (1 << 8) 2561cb0ef41Sopenharmony_ci/* Reserved for future use */ 2571cb0ef41Sopenharmony_ci#define ARES_AI_IDN (1 << 10) 2581cb0ef41Sopenharmony_ci#define ARES_AI_IDN_ALLOW_UNASSIGNED (1 << 11) 2591cb0ef41Sopenharmony_ci#define ARES_AI_IDN_USE_STD3_ASCII_RULES (1 << 12) 2601cb0ef41Sopenharmony_ci#define ARES_AI_CANONIDN (1 << 13) 2611cb0ef41Sopenharmony_ci 2621cb0ef41Sopenharmony_ci#define ARES_AI_MASK \ 2631cb0ef41Sopenharmony_ci (ARES_AI_CANONNAME | ARES_AI_NUMERICHOST | ARES_AI_PASSIVE | \ 2641cb0ef41Sopenharmony_ci ARES_AI_NUMERICSERV | ARES_AI_V4MAPPED | ARES_AI_ALL | ARES_AI_ADDRCONFIG) 2651cb0ef41Sopenharmony_ci#define ARES_GETSOCK_MAXNUM \ 2661cb0ef41Sopenharmony_ci 16 /* ares_getsock() can return info about this \ 2671cb0ef41Sopenharmony_ci many sockets */ 2681cb0ef41Sopenharmony_ci#define ARES_GETSOCK_READABLE(bits, num) (bits & (1 << (num))) 2691cb0ef41Sopenharmony_ci#define ARES_GETSOCK_WRITABLE(bits, num) \ 2701cb0ef41Sopenharmony_ci (bits & (1 << ((num) + ARES_GETSOCK_MAXNUM))) 2711cb0ef41Sopenharmony_ci 2721cb0ef41Sopenharmony_ci/* c-ares library initialization flag values */ 2731cb0ef41Sopenharmony_ci#define ARES_LIB_INIT_NONE (0) 2741cb0ef41Sopenharmony_ci#define ARES_LIB_INIT_WIN32 (1 << 0) 2751cb0ef41Sopenharmony_ci#define ARES_LIB_INIT_ALL (ARES_LIB_INIT_WIN32) 2761cb0ef41Sopenharmony_ci 2771cb0ef41Sopenharmony_ci 2781cb0ef41Sopenharmony_ci/* 2791cb0ef41Sopenharmony_ci * Typedef our socket type 2801cb0ef41Sopenharmony_ci */ 2811cb0ef41Sopenharmony_ci 2821cb0ef41Sopenharmony_ci#ifndef ares_socket_typedef 2831cb0ef41Sopenharmony_ci# ifdef WIN32 2841cb0ef41Sopenharmony_citypedef SOCKET ares_socket_t; 2851cb0ef41Sopenharmony_ci# define ARES_SOCKET_BAD INVALID_SOCKET 2861cb0ef41Sopenharmony_ci# else 2871cb0ef41Sopenharmony_citypedef int ares_socket_t; 2881cb0ef41Sopenharmony_ci# define ARES_SOCKET_BAD -1 2891cb0ef41Sopenharmony_ci# endif 2901cb0ef41Sopenharmony_ci# define ares_socket_typedef 2911cb0ef41Sopenharmony_ci#endif /* ares_socket_typedef */ 2921cb0ef41Sopenharmony_ci 2931cb0ef41Sopenharmony_citypedef void (*ares_sock_state_cb)(void *data, ares_socket_t socket_fd, 2941cb0ef41Sopenharmony_ci int readable, int writable); 2951cb0ef41Sopenharmony_ci 2961cb0ef41Sopenharmony_cistruct apattern; 2971cb0ef41Sopenharmony_ci 2981cb0ef41Sopenharmony_ci/* NOTE about the ares_options struct to users and developers. 2991cb0ef41Sopenharmony_ci 3001cb0ef41Sopenharmony_ci This struct will remain looking like this. It will not be extended nor 3011cb0ef41Sopenharmony_ci shrunk in future releases, but all new options will be set by ares_set_*() 3021cb0ef41Sopenharmony_ci options instead of with the ares_init_options() function. 3031cb0ef41Sopenharmony_ci 3041cb0ef41Sopenharmony_ci Eventually (in a galaxy far far away), all options will be settable by 3051cb0ef41Sopenharmony_ci ares_set_*() options and the ares_init_options() function will become 3061cb0ef41Sopenharmony_ci deprecated. 3071cb0ef41Sopenharmony_ci 3081cb0ef41Sopenharmony_ci When new options are added to c-ares, they are not added to this 3091cb0ef41Sopenharmony_ci struct. And they are not "saved" with the ares_save_options() function but 3101cb0ef41Sopenharmony_ci instead we encourage the use of the ares_dup() function. Needless to say, 3111cb0ef41Sopenharmony_ci if you add config options to c-ares you need to make sure ares_dup() 3121cb0ef41Sopenharmony_ci duplicates this new option. 3131cb0ef41Sopenharmony_ci 3141cb0ef41Sopenharmony_ci */ 3151cb0ef41Sopenharmony_cistruct ares_options { 3161cb0ef41Sopenharmony_ci int flags; 3171cb0ef41Sopenharmony_ci int timeout; /* in seconds or milliseconds, depending on options */ 3181cb0ef41Sopenharmony_ci int tries; 3191cb0ef41Sopenharmony_ci int ndots; 3201cb0ef41Sopenharmony_ci unsigned short udp_port; /* host byte order */ 3211cb0ef41Sopenharmony_ci unsigned short tcp_port; /* host byte order */ 3221cb0ef41Sopenharmony_ci int socket_send_buffer_size; 3231cb0ef41Sopenharmony_ci int socket_receive_buffer_size; 3241cb0ef41Sopenharmony_ci struct in_addr *servers; 3251cb0ef41Sopenharmony_ci int nservers; 3261cb0ef41Sopenharmony_ci char **domains; 3271cb0ef41Sopenharmony_ci int ndomains; 3281cb0ef41Sopenharmony_ci char *lookups; 3291cb0ef41Sopenharmony_ci ares_sock_state_cb sock_state_cb; 3301cb0ef41Sopenharmony_ci void *sock_state_cb_data; 3311cb0ef41Sopenharmony_ci struct apattern *sortlist; 3321cb0ef41Sopenharmony_ci int nsort; 3331cb0ef41Sopenharmony_ci int ednspsz; 3341cb0ef41Sopenharmony_ci char *resolvconf_path; 3351cb0ef41Sopenharmony_ci char *hosts_path; 3361cb0ef41Sopenharmony_ci int udp_max_queries; 3371cb0ef41Sopenharmony_ci int maxtimeout; /* in milliseconds */ 3381cb0ef41Sopenharmony_ci unsigned int qcache_max_ttl; /* Maximum TTL for query cache, 0=disabled */ 3391cb0ef41Sopenharmony_ci ares_evsys_t evsys; 3401cb0ef41Sopenharmony_ci}; 3411cb0ef41Sopenharmony_ci 3421cb0ef41Sopenharmony_cistruct hostent; 3431cb0ef41Sopenharmony_cistruct timeval; 3441cb0ef41Sopenharmony_cistruct sockaddr; 3451cb0ef41Sopenharmony_cistruct ares_channeldata; 3461cb0ef41Sopenharmony_cistruct ares_addrinfo; 3471cb0ef41Sopenharmony_cistruct ares_addrinfo_hints; 3481cb0ef41Sopenharmony_ci 3491cb0ef41Sopenharmony_ci/* Legacy typedef, don't use, you can't specify "const" */ 3501cb0ef41Sopenharmony_citypedef struct ares_channeldata *ares_channel; 3511cb0ef41Sopenharmony_ci 3521cb0ef41Sopenharmony_ci/* Current main channel typedef */ 3531cb0ef41Sopenharmony_citypedef struct ares_channeldata ares_channel_t; 3541cb0ef41Sopenharmony_ci 3551cb0ef41Sopenharmony_ci 3561cb0ef41Sopenharmony_citypedef void (*ares_callback)(void *arg, int status, int timeouts, 3571cb0ef41Sopenharmony_ci unsigned char *abuf, int alen); 3581cb0ef41Sopenharmony_ci 3591cb0ef41Sopenharmony_citypedef void (*ares_host_callback)(void *arg, int status, int timeouts, 3601cb0ef41Sopenharmony_ci struct hostent *hostent); 3611cb0ef41Sopenharmony_ci 3621cb0ef41Sopenharmony_citypedef void (*ares_nameinfo_callback)(void *arg, int status, int timeouts, 3631cb0ef41Sopenharmony_ci char *node, char *service); 3641cb0ef41Sopenharmony_ci 3651cb0ef41Sopenharmony_citypedef int (*ares_sock_create_callback)(ares_socket_t socket_fd, int type, 3661cb0ef41Sopenharmony_ci void *data); 3671cb0ef41Sopenharmony_ci 3681cb0ef41Sopenharmony_citypedef int (*ares_sock_config_callback)(ares_socket_t socket_fd, int type, 3691cb0ef41Sopenharmony_ci void *data); 3701cb0ef41Sopenharmony_ci 3711cb0ef41Sopenharmony_citypedef void (*ares_addrinfo_callback)(void *arg, int status, int timeouts, 3721cb0ef41Sopenharmony_ci struct ares_addrinfo *res); 3731cb0ef41Sopenharmony_ci 3741cb0ef41Sopenharmony_ciCARES_EXTERN int ares_library_init(int flags); 3751cb0ef41Sopenharmony_ci 3761cb0ef41Sopenharmony_ciCARES_EXTERN int ares_library_init_mem(int flags, void *(*amalloc)(size_t size), 3771cb0ef41Sopenharmony_ci void (*afree)(void *ptr), 3781cb0ef41Sopenharmony_ci void *(*arealloc)(void *ptr, 3791cb0ef41Sopenharmony_ci size_t size)); 3801cb0ef41Sopenharmony_ci 3811cb0ef41Sopenharmony_ci#if defined(ANDROID) || defined(__ANDROID__) 3821cb0ef41Sopenharmony_ciCARES_EXTERN void ares_library_init_jvm(JavaVM *jvm); 3831cb0ef41Sopenharmony_ciCARES_EXTERN int ares_library_init_android(jobject connectivity_manager); 3841cb0ef41Sopenharmony_ciCARES_EXTERN int ares_library_android_initialized(void); 3851cb0ef41Sopenharmony_ci#endif 3861cb0ef41Sopenharmony_ci 3871cb0ef41Sopenharmony_ciCARES_EXTERN int ares_library_initialized(void); 3881cb0ef41Sopenharmony_ci 3891cb0ef41Sopenharmony_ciCARES_EXTERN void ares_library_cleanup(void); 3901cb0ef41Sopenharmony_ci 3911cb0ef41Sopenharmony_ciCARES_EXTERN const char *ares_version(int *version); 3921cb0ef41Sopenharmony_ci 3931cb0ef41Sopenharmony_ciCARES_EXTERN int ares_init(ares_channel_t **channelptr); 3941cb0ef41Sopenharmony_ci 3951cb0ef41Sopenharmony_ciCARES_EXTERN int ares_init_options(ares_channel_t **channelptr, 3961cb0ef41Sopenharmony_ci const struct ares_options *options, 3971cb0ef41Sopenharmony_ci int optmask); 3981cb0ef41Sopenharmony_ci 3991cb0ef41Sopenharmony_ciCARES_EXTERN int ares_save_options(ares_channel_t *channel, 4001cb0ef41Sopenharmony_ci struct ares_options *options, int *optmask); 4011cb0ef41Sopenharmony_ci 4021cb0ef41Sopenharmony_ciCARES_EXTERN void ares_destroy_options(struct ares_options *options); 4031cb0ef41Sopenharmony_ci 4041cb0ef41Sopenharmony_ciCARES_EXTERN int ares_dup(ares_channel_t **dest, ares_channel_t *src); 4051cb0ef41Sopenharmony_ci 4061cb0ef41Sopenharmony_ciCARES_EXTERN ares_status_t ares_reinit(ares_channel_t *channel); 4071cb0ef41Sopenharmony_ci 4081cb0ef41Sopenharmony_ciCARES_EXTERN void ares_destroy(ares_channel_t *channel); 4091cb0ef41Sopenharmony_ci 4101cb0ef41Sopenharmony_ciCARES_EXTERN void ares_cancel(ares_channel_t *channel); 4111cb0ef41Sopenharmony_ci 4121cb0ef41Sopenharmony_ci/* These next 3 configure local binding for the out-going socket 4131cb0ef41Sopenharmony_ci * connection. Use these to specify source IP and/or network device 4141cb0ef41Sopenharmony_ci * on multi-homed systems. 4151cb0ef41Sopenharmony_ci */ 4161cb0ef41Sopenharmony_ciCARES_EXTERN void ares_set_local_ip4(ares_channel_t *channel, 4171cb0ef41Sopenharmony_ci unsigned int local_ip); 4181cb0ef41Sopenharmony_ci 4191cb0ef41Sopenharmony_ci/* local_ip6 should be 16 bytes in length */ 4201cb0ef41Sopenharmony_ciCARES_EXTERN void ares_set_local_ip6(ares_channel_t *channel, 4211cb0ef41Sopenharmony_ci const unsigned char *local_ip6); 4221cb0ef41Sopenharmony_ci 4231cb0ef41Sopenharmony_ci/* local_dev_name should be null terminated. */ 4241cb0ef41Sopenharmony_ciCARES_EXTERN void ares_set_local_dev(ares_channel_t *channel, 4251cb0ef41Sopenharmony_ci const char *local_dev_name); 4261cb0ef41Sopenharmony_ci 4271cb0ef41Sopenharmony_ciCARES_EXTERN void ares_set_socket_callback(ares_channel_t *channel, 4281cb0ef41Sopenharmony_ci ares_sock_create_callback callback, 4291cb0ef41Sopenharmony_ci void *user_data); 4301cb0ef41Sopenharmony_ci 4311cb0ef41Sopenharmony_ciCARES_EXTERN void ares_set_socket_configure_callback( 4321cb0ef41Sopenharmony_ci ares_channel_t *channel, ares_sock_config_callback callback, void *user_data); 4331cb0ef41Sopenharmony_ci 4341cb0ef41Sopenharmony_ciCARES_EXTERN int ares_set_sortlist(ares_channel_t *channel, 4351cb0ef41Sopenharmony_ci const char *sortstr); 4361cb0ef41Sopenharmony_ci 4371cb0ef41Sopenharmony_ciCARES_EXTERN void ares_getaddrinfo(ares_channel_t *channel, const char *node, 4381cb0ef41Sopenharmony_ci const char *service, 4391cb0ef41Sopenharmony_ci const struct ares_addrinfo_hints *hints, 4401cb0ef41Sopenharmony_ci ares_addrinfo_callback callback, void *arg); 4411cb0ef41Sopenharmony_ci 4421cb0ef41Sopenharmony_ciCARES_EXTERN void ares_freeaddrinfo(struct ares_addrinfo *ai); 4431cb0ef41Sopenharmony_ci 4441cb0ef41Sopenharmony_ci/* 4451cb0ef41Sopenharmony_ci * Virtual function set to have user-managed socket IO. 4461cb0ef41Sopenharmony_ci * Note that all functions need to be defined, and when 4471cb0ef41Sopenharmony_ci * set, the library will not do any bind nor set any 4481cb0ef41Sopenharmony_ci * socket options, assuming the client handles these 4491cb0ef41Sopenharmony_ci * through either socket creation or the 4501cb0ef41Sopenharmony_ci * ares_sock_config_callback call. 4511cb0ef41Sopenharmony_ci */ 4521cb0ef41Sopenharmony_cistruct iovec; 4531cb0ef41Sopenharmony_ci 4541cb0ef41Sopenharmony_cistruct ares_socket_functions { 4551cb0ef41Sopenharmony_ci ares_socket_t (*asocket)(int, int, int, void *); 4561cb0ef41Sopenharmony_ci int (*aclose)(ares_socket_t, void *); 4571cb0ef41Sopenharmony_ci int (*aconnect)(ares_socket_t, const struct sockaddr *, ares_socklen_t, 4581cb0ef41Sopenharmony_ci void *); 4591cb0ef41Sopenharmony_ci ares_ssize_t (*arecvfrom)(ares_socket_t, void *, size_t, int, 4601cb0ef41Sopenharmony_ci struct sockaddr *, ares_socklen_t *, void *); 4611cb0ef41Sopenharmony_ci ares_ssize_t (*asendv)(ares_socket_t, const struct iovec *, int, void *); 4621cb0ef41Sopenharmony_ci}; 4631cb0ef41Sopenharmony_ci 4641cb0ef41Sopenharmony_ciCARES_EXTERN void 4651cb0ef41Sopenharmony_ci ares_set_socket_functions(ares_channel_t *channel, 4661cb0ef41Sopenharmony_ci const struct ares_socket_functions *funcs, 4671cb0ef41Sopenharmony_ci void *user_data); 4681cb0ef41Sopenharmony_ci 4691cb0ef41Sopenharmony_ciCARES_EXTERN void ares_send(ares_channel_t *channel, const unsigned char *qbuf, 4701cb0ef41Sopenharmony_ci int qlen, ares_callback callback, void *arg); 4711cb0ef41Sopenharmony_ci 4721cb0ef41Sopenharmony_ciCARES_EXTERN void ares_query(ares_channel_t *channel, const char *name, 4731cb0ef41Sopenharmony_ci int dnsclass, int type, ares_callback callback, 4741cb0ef41Sopenharmony_ci void *arg); 4751cb0ef41Sopenharmony_ci 4761cb0ef41Sopenharmony_ciCARES_EXTERN void ares_search(ares_channel_t *channel, const char *name, 4771cb0ef41Sopenharmony_ci int dnsclass, int type, ares_callback callback, 4781cb0ef41Sopenharmony_ci void *arg); 4791cb0ef41Sopenharmony_ci 4801cb0ef41Sopenharmony_ciCARES_EXTERN void ares_gethostbyname(ares_channel_t *channel, const char *name, 4811cb0ef41Sopenharmony_ci int family, ares_host_callback callback, 4821cb0ef41Sopenharmony_ci void *arg); 4831cb0ef41Sopenharmony_ci 4841cb0ef41Sopenharmony_ciCARES_EXTERN int ares_gethostbyname_file(ares_channel_t *channel, 4851cb0ef41Sopenharmony_ci const char *name, int family, 4861cb0ef41Sopenharmony_ci struct hostent **host); 4871cb0ef41Sopenharmony_ci 4881cb0ef41Sopenharmony_ciCARES_EXTERN void ares_gethostbyaddr(ares_channel_t *channel, const void *addr, 4891cb0ef41Sopenharmony_ci int addrlen, int family, 4901cb0ef41Sopenharmony_ci ares_host_callback callback, void *arg); 4911cb0ef41Sopenharmony_ci 4921cb0ef41Sopenharmony_ciCARES_EXTERN void ares_getnameinfo(ares_channel_t *channel, 4931cb0ef41Sopenharmony_ci const struct sockaddr *sa, 4941cb0ef41Sopenharmony_ci ares_socklen_t salen, int flags, 4951cb0ef41Sopenharmony_ci ares_nameinfo_callback callback, void *arg); 4961cb0ef41Sopenharmony_ci 4971cb0ef41Sopenharmony_ciCARES_EXTERN int ares_fds(ares_channel_t *channel, fd_set *read_fds, 4981cb0ef41Sopenharmony_ci fd_set *write_fds); 4991cb0ef41Sopenharmony_ci 5001cb0ef41Sopenharmony_ciCARES_EXTERN int ares_getsock(ares_channel_t *channel, ares_socket_t *socks, 5011cb0ef41Sopenharmony_ci int numsocks); 5021cb0ef41Sopenharmony_ci 5031cb0ef41Sopenharmony_ciCARES_EXTERN struct timeval *ares_timeout(ares_channel_t *channel, 5041cb0ef41Sopenharmony_ci struct timeval *maxtv, 5051cb0ef41Sopenharmony_ci struct timeval *tv); 5061cb0ef41Sopenharmony_ci 5071cb0ef41Sopenharmony_ciCARES_EXTERN void ares_process(ares_channel_t *channel, fd_set *read_fds, 5081cb0ef41Sopenharmony_ci fd_set *write_fds); 5091cb0ef41Sopenharmony_ci 5101cb0ef41Sopenharmony_ciCARES_EXTERN void ares_process_fd(ares_channel_t *channel, 5111cb0ef41Sopenharmony_ci ares_socket_t read_fd, 5121cb0ef41Sopenharmony_ci ares_socket_t write_fd); 5131cb0ef41Sopenharmony_ci 5141cb0ef41Sopenharmony_ciCARES_EXTERN int ares_create_query(const char *name, int dnsclass, int type, 5151cb0ef41Sopenharmony_ci unsigned short id, int rd, 5161cb0ef41Sopenharmony_ci unsigned char **buf, int *buflen, 5171cb0ef41Sopenharmony_ci int max_udp_size); 5181cb0ef41Sopenharmony_ci 5191cb0ef41Sopenharmony_ciCARES_EXTERN int ares_mkquery(const char *name, int dnsclass, int type, 5201cb0ef41Sopenharmony_ci unsigned short id, int rd, unsigned char **buf, 5211cb0ef41Sopenharmony_ci int *buflen); 5221cb0ef41Sopenharmony_ci 5231cb0ef41Sopenharmony_ciCARES_EXTERN int ares_expand_name(const unsigned char *encoded, 5241cb0ef41Sopenharmony_ci const unsigned char *abuf, int alen, char **s, 5251cb0ef41Sopenharmony_ci long *enclen); 5261cb0ef41Sopenharmony_ci 5271cb0ef41Sopenharmony_ciCARES_EXTERN int ares_expand_string(const unsigned char *encoded, 5281cb0ef41Sopenharmony_ci const unsigned char *abuf, int alen, 5291cb0ef41Sopenharmony_ci unsigned char **s, long *enclen); 5301cb0ef41Sopenharmony_ci 5311cb0ef41Sopenharmony_ci/* 5321cb0ef41Sopenharmony_ci * NOTE: before c-ares 1.7.0 we would most often use the system in6_addr 5331cb0ef41Sopenharmony_ci * struct below when ares itself was built, but many apps would use this 5341cb0ef41Sopenharmony_ci * private version since the header checked a HAVE_* define for it. Starting 5351cb0ef41Sopenharmony_ci * with 1.7.0 we always declare and use our own to stop relying on the 5361cb0ef41Sopenharmony_ci * system's one. 5371cb0ef41Sopenharmony_ci */ 5381cb0ef41Sopenharmony_cistruct ares_in6_addr { 5391cb0ef41Sopenharmony_ci union { 5401cb0ef41Sopenharmony_ci unsigned char _S6_u8[16]; 5411cb0ef41Sopenharmony_ci } _S6_un; 5421cb0ef41Sopenharmony_ci}; 5431cb0ef41Sopenharmony_ci 5441cb0ef41Sopenharmony_cistruct ares_addr { 5451cb0ef41Sopenharmony_ci int family; 5461cb0ef41Sopenharmony_ci 5471cb0ef41Sopenharmony_ci union { 5481cb0ef41Sopenharmony_ci struct in_addr addr4; 5491cb0ef41Sopenharmony_ci struct ares_in6_addr addr6; 5501cb0ef41Sopenharmony_ci } addr; 5511cb0ef41Sopenharmony_ci}; 5521cb0ef41Sopenharmony_ci 5531cb0ef41Sopenharmony_cistruct ares_addrttl { 5541cb0ef41Sopenharmony_ci struct in_addr ipaddr; 5551cb0ef41Sopenharmony_ci int ttl; 5561cb0ef41Sopenharmony_ci}; 5571cb0ef41Sopenharmony_ci 5581cb0ef41Sopenharmony_cistruct ares_addr6ttl { 5591cb0ef41Sopenharmony_ci struct ares_in6_addr ip6addr; 5601cb0ef41Sopenharmony_ci int ttl; 5611cb0ef41Sopenharmony_ci}; 5621cb0ef41Sopenharmony_ci 5631cb0ef41Sopenharmony_cistruct ares_caa_reply { 5641cb0ef41Sopenharmony_ci struct ares_caa_reply *next; 5651cb0ef41Sopenharmony_ci int critical; 5661cb0ef41Sopenharmony_ci unsigned char *property; 5671cb0ef41Sopenharmony_ci size_t plength; /* plength excludes null termination */ 5681cb0ef41Sopenharmony_ci unsigned char *value; 5691cb0ef41Sopenharmony_ci size_t length; /* length excludes null termination */ 5701cb0ef41Sopenharmony_ci}; 5711cb0ef41Sopenharmony_ci 5721cb0ef41Sopenharmony_cistruct ares_srv_reply { 5731cb0ef41Sopenharmony_ci struct ares_srv_reply *next; 5741cb0ef41Sopenharmony_ci char *host; 5751cb0ef41Sopenharmony_ci unsigned short priority; 5761cb0ef41Sopenharmony_ci unsigned short weight; 5771cb0ef41Sopenharmony_ci unsigned short port; 5781cb0ef41Sopenharmony_ci}; 5791cb0ef41Sopenharmony_ci 5801cb0ef41Sopenharmony_cistruct ares_mx_reply { 5811cb0ef41Sopenharmony_ci struct ares_mx_reply *next; 5821cb0ef41Sopenharmony_ci char *host; 5831cb0ef41Sopenharmony_ci unsigned short priority; 5841cb0ef41Sopenharmony_ci}; 5851cb0ef41Sopenharmony_ci 5861cb0ef41Sopenharmony_cistruct ares_txt_reply { 5871cb0ef41Sopenharmony_ci struct ares_txt_reply *next; 5881cb0ef41Sopenharmony_ci unsigned char *txt; 5891cb0ef41Sopenharmony_ci size_t length; /* length excludes null termination */ 5901cb0ef41Sopenharmony_ci}; 5911cb0ef41Sopenharmony_ci 5921cb0ef41Sopenharmony_ci/* NOTE: This structure is a superset of ares_txt_reply 5931cb0ef41Sopenharmony_ci */ 5941cb0ef41Sopenharmony_cistruct ares_txt_ext { 5951cb0ef41Sopenharmony_ci struct ares_txt_ext *next; 5961cb0ef41Sopenharmony_ci unsigned char *txt; 5971cb0ef41Sopenharmony_ci size_t length; 5981cb0ef41Sopenharmony_ci /* 1 - if start of new record 5991cb0ef41Sopenharmony_ci * 0 - if a chunk in the same record */ 6001cb0ef41Sopenharmony_ci unsigned char record_start; 6011cb0ef41Sopenharmony_ci}; 6021cb0ef41Sopenharmony_ci 6031cb0ef41Sopenharmony_cistruct ares_naptr_reply { 6041cb0ef41Sopenharmony_ci struct ares_naptr_reply *next; 6051cb0ef41Sopenharmony_ci unsigned char *flags; 6061cb0ef41Sopenharmony_ci unsigned char *service; 6071cb0ef41Sopenharmony_ci unsigned char *regexp; 6081cb0ef41Sopenharmony_ci char *replacement; 6091cb0ef41Sopenharmony_ci unsigned short order; 6101cb0ef41Sopenharmony_ci unsigned short preference; 6111cb0ef41Sopenharmony_ci}; 6121cb0ef41Sopenharmony_ci 6131cb0ef41Sopenharmony_cistruct ares_soa_reply { 6141cb0ef41Sopenharmony_ci char *nsname; 6151cb0ef41Sopenharmony_ci char *hostmaster; 6161cb0ef41Sopenharmony_ci unsigned int serial; 6171cb0ef41Sopenharmony_ci unsigned int refresh; 6181cb0ef41Sopenharmony_ci unsigned int retry; 6191cb0ef41Sopenharmony_ci unsigned int expire; 6201cb0ef41Sopenharmony_ci unsigned int minttl; 6211cb0ef41Sopenharmony_ci}; 6221cb0ef41Sopenharmony_ci 6231cb0ef41Sopenharmony_cistruct ares_uri_reply { 6241cb0ef41Sopenharmony_ci struct ares_uri_reply *next; 6251cb0ef41Sopenharmony_ci unsigned short priority; 6261cb0ef41Sopenharmony_ci unsigned short weight; 6271cb0ef41Sopenharmony_ci char *uri; 6281cb0ef41Sopenharmony_ci int ttl; 6291cb0ef41Sopenharmony_ci}; 6301cb0ef41Sopenharmony_ci 6311cb0ef41Sopenharmony_ci/* 6321cb0ef41Sopenharmony_ci * Similar to addrinfo, but with extra ttl and missing canonname. 6331cb0ef41Sopenharmony_ci */ 6341cb0ef41Sopenharmony_cistruct ares_addrinfo_node { 6351cb0ef41Sopenharmony_ci int ai_ttl; 6361cb0ef41Sopenharmony_ci int ai_flags; 6371cb0ef41Sopenharmony_ci int ai_family; 6381cb0ef41Sopenharmony_ci int ai_socktype; 6391cb0ef41Sopenharmony_ci int ai_protocol; 6401cb0ef41Sopenharmony_ci ares_socklen_t ai_addrlen; 6411cb0ef41Sopenharmony_ci struct sockaddr *ai_addr; 6421cb0ef41Sopenharmony_ci struct ares_addrinfo_node *ai_next; 6431cb0ef41Sopenharmony_ci}; 6441cb0ef41Sopenharmony_ci 6451cb0ef41Sopenharmony_ci/* 6461cb0ef41Sopenharmony_ci * alias - label of the resource record. 6471cb0ef41Sopenharmony_ci * name - value (canonical name) of the resource record. 6481cb0ef41Sopenharmony_ci * See RFC2181 10.1.1. CNAME terminology. 6491cb0ef41Sopenharmony_ci */ 6501cb0ef41Sopenharmony_cistruct ares_addrinfo_cname { 6511cb0ef41Sopenharmony_ci int ttl; 6521cb0ef41Sopenharmony_ci char *alias; 6531cb0ef41Sopenharmony_ci char *name; 6541cb0ef41Sopenharmony_ci struct ares_addrinfo_cname *next; 6551cb0ef41Sopenharmony_ci}; 6561cb0ef41Sopenharmony_ci 6571cb0ef41Sopenharmony_cistruct ares_addrinfo { 6581cb0ef41Sopenharmony_ci struct ares_addrinfo_cname *cnames; 6591cb0ef41Sopenharmony_ci struct ares_addrinfo_node *nodes; 6601cb0ef41Sopenharmony_ci char *name; 6611cb0ef41Sopenharmony_ci}; 6621cb0ef41Sopenharmony_ci 6631cb0ef41Sopenharmony_cistruct ares_addrinfo_hints { 6641cb0ef41Sopenharmony_ci int ai_flags; 6651cb0ef41Sopenharmony_ci int ai_family; 6661cb0ef41Sopenharmony_ci int ai_socktype; 6671cb0ef41Sopenharmony_ci int ai_protocol; 6681cb0ef41Sopenharmony_ci}; 6691cb0ef41Sopenharmony_ci 6701cb0ef41Sopenharmony_ci/* 6711cb0ef41Sopenharmony_ci** Parse the buffer, starting at *abuf and of length alen bytes, previously 6721cb0ef41Sopenharmony_ci** obtained from an ares_search call. Put the results in *host, if nonnull. 6731cb0ef41Sopenharmony_ci** Also, if addrttls is nonnull, put up to *naddrttls IPv4 addresses along with 6741cb0ef41Sopenharmony_ci** their TTLs in that array, and set *naddrttls to the number of addresses 6751cb0ef41Sopenharmony_ci** so written. 6761cb0ef41Sopenharmony_ci*/ 6771cb0ef41Sopenharmony_ci 6781cb0ef41Sopenharmony_ciCARES_EXTERN int ares_parse_a_reply(const unsigned char *abuf, int alen, 6791cb0ef41Sopenharmony_ci struct hostent **host, 6801cb0ef41Sopenharmony_ci struct ares_addrttl *addrttls, 6811cb0ef41Sopenharmony_ci int *naddrttls); 6821cb0ef41Sopenharmony_ci 6831cb0ef41Sopenharmony_ciCARES_EXTERN int ares_parse_aaaa_reply(const unsigned char *abuf, int alen, 6841cb0ef41Sopenharmony_ci struct hostent **host, 6851cb0ef41Sopenharmony_ci struct ares_addr6ttl *addrttls, 6861cb0ef41Sopenharmony_ci int *naddrttls); 6871cb0ef41Sopenharmony_ci 6881cb0ef41Sopenharmony_ciCARES_EXTERN int ares_parse_caa_reply(const unsigned char *abuf, int alen, 6891cb0ef41Sopenharmony_ci struct ares_caa_reply **caa_out); 6901cb0ef41Sopenharmony_ci 6911cb0ef41Sopenharmony_ciCARES_EXTERN int ares_parse_ptr_reply(const unsigned char *abuf, int alen, 6921cb0ef41Sopenharmony_ci const void *addr, int addrlen, int family, 6931cb0ef41Sopenharmony_ci struct hostent **host); 6941cb0ef41Sopenharmony_ci 6951cb0ef41Sopenharmony_ciCARES_EXTERN int ares_parse_ns_reply(const unsigned char *abuf, int alen, 6961cb0ef41Sopenharmony_ci struct hostent **host); 6971cb0ef41Sopenharmony_ci 6981cb0ef41Sopenharmony_ciCARES_EXTERN int ares_parse_srv_reply(const unsigned char *abuf, int alen, 6991cb0ef41Sopenharmony_ci struct ares_srv_reply **srv_out); 7001cb0ef41Sopenharmony_ci 7011cb0ef41Sopenharmony_ciCARES_EXTERN int ares_parse_mx_reply(const unsigned char *abuf, int alen, 7021cb0ef41Sopenharmony_ci struct ares_mx_reply **mx_out); 7031cb0ef41Sopenharmony_ci 7041cb0ef41Sopenharmony_ciCARES_EXTERN int ares_parse_txt_reply(const unsigned char *abuf, int alen, 7051cb0ef41Sopenharmony_ci struct ares_txt_reply **txt_out); 7061cb0ef41Sopenharmony_ci 7071cb0ef41Sopenharmony_ciCARES_EXTERN int ares_parse_txt_reply_ext(const unsigned char *abuf, int alen, 7081cb0ef41Sopenharmony_ci struct ares_txt_ext **txt_out); 7091cb0ef41Sopenharmony_ci 7101cb0ef41Sopenharmony_ciCARES_EXTERN int ares_parse_naptr_reply(const unsigned char *abuf, int alen, 7111cb0ef41Sopenharmony_ci struct ares_naptr_reply **naptr_out); 7121cb0ef41Sopenharmony_ci 7131cb0ef41Sopenharmony_ciCARES_EXTERN int ares_parse_soa_reply(const unsigned char *abuf, int alen, 7141cb0ef41Sopenharmony_ci struct ares_soa_reply **soa_out); 7151cb0ef41Sopenharmony_ci 7161cb0ef41Sopenharmony_ciCARES_EXTERN int ares_parse_uri_reply(const unsigned char *abuf, int alen, 7171cb0ef41Sopenharmony_ci struct ares_uri_reply **uri_out); 7181cb0ef41Sopenharmony_ci 7191cb0ef41Sopenharmony_ciCARES_EXTERN void ares_free_string(void *str); 7201cb0ef41Sopenharmony_ci 7211cb0ef41Sopenharmony_ciCARES_EXTERN void ares_free_hostent(struct hostent *host); 7221cb0ef41Sopenharmony_ci 7231cb0ef41Sopenharmony_ciCARES_EXTERN void ares_free_data(void *dataptr); 7241cb0ef41Sopenharmony_ci 7251cb0ef41Sopenharmony_ciCARES_EXTERN const char *ares_strerror(int code); 7261cb0ef41Sopenharmony_ci 7271cb0ef41Sopenharmony_cistruct ares_addr_node { 7281cb0ef41Sopenharmony_ci struct ares_addr_node *next; 7291cb0ef41Sopenharmony_ci int family; 7301cb0ef41Sopenharmony_ci 7311cb0ef41Sopenharmony_ci union { 7321cb0ef41Sopenharmony_ci struct in_addr addr4; 7331cb0ef41Sopenharmony_ci struct ares_in6_addr addr6; 7341cb0ef41Sopenharmony_ci } addr; 7351cb0ef41Sopenharmony_ci}; 7361cb0ef41Sopenharmony_ci 7371cb0ef41Sopenharmony_cistruct ares_addr_port_node { 7381cb0ef41Sopenharmony_ci struct ares_addr_port_node *next; 7391cb0ef41Sopenharmony_ci int family; 7401cb0ef41Sopenharmony_ci 7411cb0ef41Sopenharmony_ci union { 7421cb0ef41Sopenharmony_ci struct in_addr addr4; 7431cb0ef41Sopenharmony_ci struct ares_in6_addr addr6; 7441cb0ef41Sopenharmony_ci } addr; 7451cb0ef41Sopenharmony_ci 7461cb0ef41Sopenharmony_ci int udp_port; 7471cb0ef41Sopenharmony_ci int tcp_port; 7481cb0ef41Sopenharmony_ci}; 7491cb0ef41Sopenharmony_ci 7501cb0ef41Sopenharmony_ciCARES_EXTERN int ares_set_servers(ares_channel_t *channel, 7511cb0ef41Sopenharmony_ci const struct ares_addr_node *servers); 7521cb0ef41Sopenharmony_ciCARES_EXTERN int 7531cb0ef41Sopenharmony_ci ares_set_servers_ports(ares_channel_t *channel, 7541cb0ef41Sopenharmony_ci const struct ares_addr_port_node *servers); 7551cb0ef41Sopenharmony_ci 7561cb0ef41Sopenharmony_ci/* Incoming string format: host[:port][,host[:port]]... */ 7571cb0ef41Sopenharmony_ciCARES_EXTERN int ares_set_servers_csv(ares_channel_t *channel, 7581cb0ef41Sopenharmony_ci const char *servers); 7591cb0ef41Sopenharmony_ciCARES_EXTERN int ares_set_servers_ports_csv(ares_channel_t *channel, 7601cb0ef41Sopenharmony_ci const char *servers); 7611cb0ef41Sopenharmony_ciCARES_EXTERN char *ares_get_servers_csv(ares_channel_t *channel); 7621cb0ef41Sopenharmony_ci 7631cb0ef41Sopenharmony_ciCARES_EXTERN int ares_get_servers(ares_channel_t *channel, 7641cb0ef41Sopenharmony_ci struct ares_addr_node **servers); 7651cb0ef41Sopenharmony_ciCARES_EXTERN int ares_get_servers_ports(ares_channel_t *channel, 7661cb0ef41Sopenharmony_ci struct ares_addr_port_node **servers); 7671cb0ef41Sopenharmony_ci 7681cb0ef41Sopenharmony_ciCARES_EXTERN const char *ares_inet_ntop(int af, const void *src, char *dst, 7691cb0ef41Sopenharmony_ci ares_socklen_t size); 7701cb0ef41Sopenharmony_ci 7711cb0ef41Sopenharmony_ciCARES_EXTERN int ares_inet_pton(int af, const char *src, void *dst); 7721cb0ef41Sopenharmony_ci 7731cb0ef41Sopenharmony_ci/*! Whether or not the c-ares library was built with threadsafety 7741cb0ef41Sopenharmony_ci * 7751cb0ef41Sopenharmony_ci * \return ARES_TRUE if built with threadsafety, ARES_FALSE if not 7761cb0ef41Sopenharmony_ci */ 7771cb0ef41Sopenharmony_ciCARES_EXTERN ares_bool_t ares_threadsafety(void); 7781cb0ef41Sopenharmony_ci 7791cb0ef41Sopenharmony_ci 7801cb0ef41Sopenharmony_ci/*! Block until notified that there are no longer any queries in queue, or 7811cb0ef41Sopenharmony_ci * the specified timeout has expired. 7821cb0ef41Sopenharmony_ci * 7831cb0ef41Sopenharmony_ci * \param[in] channel Initialized ares channel 7841cb0ef41Sopenharmony_ci * \param[in] timeout_ms Number of milliseconds to wait for the queue to be 7851cb0ef41Sopenharmony_ci * empty. -1 for Infinite. 7861cb0ef41Sopenharmony_ci * \return ARES_ENOTIMP if not built with threading support, ARES_ETIMEOUT 7871cb0ef41Sopenharmony_ci * if requested timeout expires, ARES_SUCCESS when queue is empty. 7881cb0ef41Sopenharmony_ci */ 7891cb0ef41Sopenharmony_ciCARES_EXTERN ares_status_t ares_queue_wait_empty(ares_channel_t *channel, 7901cb0ef41Sopenharmony_ci int timeout_ms); 7911cb0ef41Sopenharmony_ci 7921cb0ef41Sopenharmony_ci 7931cb0ef41Sopenharmony_ci/*! Retrieve the total number of active queries pending answers from servers. 7941cb0ef41Sopenharmony_ci * Some c-ares requests may spawn multiple queries, such as ares_getaddrinfo() 7951cb0ef41Sopenharmony_ci * when using AF_UNSPEC, which will be reflected in this number. 7961cb0ef41Sopenharmony_ci * 7971cb0ef41Sopenharmony_ci * \param[in] channel Initialized ares channel 7981cb0ef41Sopenharmony_ci * \return Number of active queries to servers 7991cb0ef41Sopenharmony_ci */ 8001cb0ef41Sopenharmony_ciCARES_EXTERN size_t ares_queue_active_queries(ares_channel_t *channel); 8011cb0ef41Sopenharmony_ci 8021cb0ef41Sopenharmony_ci#ifdef __cplusplus 8031cb0ef41Sopenharmony_ci} 8041cb0ef41Sopenharmony_ci#endif 8051cb0ef41Sopenharmony_ci 8061cb0ef41Sopenharmony_ci/* DNS record parser, writer, and helpers */ 8071cb0ef41Sopenharmony_ci#include "ares_dns_record.h" 8081cb0ef41Sopenharmony_ci 8091cb0ef41Sopenharmony_ci#endif /* ARES__H */ 810