reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ares.h
Go to the documentation of this file.
1/* Copyright 1998 by the Massachusetts Institute of Technology.
2 *
3 * Permission to use, copy, modify, and distribute this
4 * software and its documentation for any purpose and without
5 * fee is hereby granted, provided that the above copyright
6 * notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting
8 * documentation, and that the name of M.I.T. not be used in
9 * advertising or publicity pertaining to distribution of the
10 * software without specific, written prior permission.
11 * M.I.T. makes no representations about the suitability of
12 * this software for any purpose. It is provided "as is"
13 * without express or implied warranty.
14 */
15
16#ifndef ARES__H
17#define ARES__H
18
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#ifdef WIN32
24 #include <winsock2.h>
25 #include <stdlib.h>
26 #include <errno.h>
27 #include <io.h>
28 #include <string.h>
29 #include <stdio.h>
30 #include <WS2tcpip.h>
31 // Remove compiler warnings: "warning C4996: 'xxxxx': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _xxxxxx."
32 #define strdup _strdup
33 #define stricmp _stricmp
34 #define strnicmp _strnicmp
35 #define write _write
36#endif
37
38// include this early to resolve some build issues
39// FIXME: maybe we need to update our copy of c-ares
40// with the upstream version that resolves
41// a lot of these issues
42#include "ares_nameser.h"
43
44#if !defined(DNS__16BIT)
45# define DNS__16BIT(p) (((p)[0] << 8) | (p)[1])
46# define DNS__32BIT(p) (((p)[0] << 24) | ((p)[1] << 16) | \
47 ((p)[2] << 8) | (p)[3])
48# define DNS_HEADER_QDCOUNT(h) DNS__16BIT((h) + 4)
49# define DNS_HEADER_ANCOUNT(h) DNS__16BIT((h) + 6)
50# define DNS_HEADER_NSCOUNT(h) DNS__16BIT((h) + 8)
51# define DNS_HEADER_ARCOUNT(h) DNS__16BIT((h) + 10)
52# define DNS_RR_TYPE(r) DNS__16BIT(r)
53# define DNS_RR_LEN(r) DNS__16BIT((r) + 8)
54# define DNS_RR_TTL(r) DNS__32BIT((r) + 4)
55#endif
56
57#if defined(__cplusplus)
58extern "C" {
59#endif
60
61#if defined(__APPLE__)
62#include "ares_nameser.h"
63#if !defined(MAC_OS_X_VERSION_MIN_REQUIRED) || (MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_2)
64#include "ares_nameser.h"
65#endif
66#endif
67
68#include <sys/types.h>
69#if defined(__ANDROID__)
70#include <sys/select.h>
71#endif
72#ifndef WIN32
73/* why was this commented out?! ah, it was a 'fix for windows' */
74#include <netinet/in.h>
75#endif
76
77#include "ares_socketfunc.h"
78
79#define ARES_SUCCESS 0
80
81/* Server error codes (ARES_ENODATA indicates no relevant answer) */
82#define ARES_ENODATA 1
83#define ARES_EFORMERR 2
84#define ARES_ESERVFAIL 3
85#define ARES_ENOTFOUND 4
86#define ARES_ENOTIMP 5
87#define ARES_EREFUSED 6
88
89/* Locally generated error codes */
90#define ARES_EBADQUERY 7
91#define ARES_EBADNAME 8
92#define ARES_EBADFAMILY 9
93#define ARES_EBADRESP 10
94#define ARES_ECONNREFUSED 11
95#define ARES_ETIMEOUT 12
96#define ARES_EOF 13
97#define ARES_EFILE 14
98#define ARES_ENOMEM 15
99#define ARES_EDESTRUCTION 16
100
101/* Flag values */
102#define ARES_FLAG_USEVC (1 << 0)
103#define ARES_FLAG_PRIMARY (1 << 1)
104#define ARES_FLAG_IGNTC (1 << 2)
105#define ARES_FLAG_NORECURSE (1 << 3)
106#define ARES_FLAG_STAYOPEN (1 << 4)
107#define ARES_FLAG_NOSEARCH (1 << 5)
108#define ARES_FLAG_NOALIASES (1 << 6)
109#define ARES_FLAG_NOCHECKRESP (1 << 7)
110#define ARES_FLAG_TRY_NEXT_SERVER_ON_RCODE3 (1 << 8) /* when rcode of 3 ('No such name') is recvd */
111
112/* Option mask values */
113#define ARES_OPT_FLAGS (1 << 0)
114#define ARES_OPT_TIMEOUT (1 << 1)
115#define ARES_OPT_TRIES (1 << 2)
116#define ARES_OPT_NDOTS (1 << 3)
117#define ARES_OPT_UDP_PORT (1 << 4)
118#define ARES_OPT_TCP_PORT (1 << 5)
119#define ARES_OPT_SERVERS (1 << 6)
120#define ARES_OPT_DOMAINS (1 << 7)
121#define ARES_OPT_LOOKUPS (1 << 8)
122
123/* Capability mask values */
124
125#define ARES_CAP_IPV6 (1 << 0)
126
127typedef enum ares_poll_action {
129 ARES_POLLACTION_OPEN= (1), // ares just opened this
130 ARES_POLLACTION_CLOSE= (2), // ares just closed this
131 ARES_POLLACTION_WRITEON= (3), // tell ares when writable
132 ARES_POLLACTION_WRITEOFF= (4) // don't tell ares when writable
134struct ares_channeldata;
136 int fd, int using_tcp, ares_poll_action_t act);
137
138#if defined(WIN32) || defined(sun)
139typedef unsigned char u_int8_t;
140#endif
141
142#ifdef USE_IPV6
148#endif
149
151 int flags;
153 int tries;
154 int ndots;
155 unsigned short udp_port;
156 unsigned short tcp_port;
157#ifdef USE_IPV6
159#else
160 struct in_addr *servers;
161#endif
163 char **domains;
165 char *lookups;
166};
167
168struct hostent;
169struct timeval;
170struct ares_channeldata;
172typedef void (*ares_callback)(void *arg, int status, unsigned char *abuf,
173 int alen);
174typedef void (*ares_host_callback)(void *arg, int status,
175 struct hostent *hostent);
176
179
180extern int ares_capabilities(int capmask);
181
183 int optmask);
184
187extern void ares_destroy(ares_channel channel);
189
191
192extern void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
193 ares_callback callback, void *arg);
194extern void ares_query(ares_channel channel, const char *name, int dnsclass,
195 int type, ares_callback callback, void *arg);
196extern void ares_search(ares_channel channel, const char *name, int dnsclass,
197 int type, ares_callback callback, void *arg);
198extern void ares_gethostbyname(ares_channel channel, const char *name, int family,
199 ares_host_callback callback, void *arg);
200extern void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
201 int family, ares_host_callback callback, void *arg);
202extern int hostfile_lookup(const char *name, struct hostent **host);
203
204extern int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
205extern struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
206 struct timeval *tv);
209extern void ares_process_poll(ares_channel channel, int server_idx,
210 int rdFd, int wrFd, time_t now);
211
212
213extern int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id,
214 int rd, unsigned char **buf, int *buflen);
215extern int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
216 int alen, char **s, long *enclen);
217extern int ares_parse_a_reply(const unsigned char *abuf, int alen,
218 struct hostent **host);
219extern int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
220 int addrlen, int family, struct hostent **host);
221extern void ares_free_string(char *str);
222extern void ares_free_hostent(struct hostent *host);
223extern const char *ares_strerror(int code);
224extern void ares_free_errmem(char *mem);
225
226
227#if defined(WIN32) || defined (__CYGWIN__) || defined (__ANDROID__)
228
229#define T_A 1 /* host address */
230#define T_NS 2 /* authoritative server */
231#define T_MD 3 /* mail destination */
232#define T_MF 4 /* mail forwarder */
233#define T_CNAME 5 /* canonical name */
234#define T_SOA 6 /* start of authority zone */
235#define T_MB 7 /* mailbox domain name */
236#define T_MG 8 /* mail group member */
237#define T_MR 9 /* mail rename name */
238#define T_NULL 10 /* null resource record */
239#define T_WKS 11 /* well known service */
240#define T_PTR 12 /* domain name pointer */
241#define T_HINFO 13 /* host information */
242#define T_MINFO 14 /* mailbox information */
243#define T_MX 15 /* mail routing information */
244#define T_TXT 16 /* text strings */
245#define T_RP 17 /* responsible person */
246#define T_AFSDB 18 /* AFS cell database */
247#define T_X25 19 /* X_25 calling address */
248#define T_ISDN 20 /* ISDN calling address */
249#define T_RT 21 /* router */
250#define T_NSAP 22 /* NSAP address */
251#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
252#define T_SIG 24 /* security signature */
253#define T_KEY 25 /* security key */
254#define T_PX 26 /* X.400 mail mapping */
255#define T_GPOS 27 /* geographical position (withdrawn) */
256#define T_AAAA 28 /* IP6 Address */
257#define T_LOC 29 /* Location Information */
258 /* non standard */
259#define T_UINFO 100 /* user (finger) information */
260#define T_UID 101 /* user ID */
261#define T_GID 102 /* group ID */
262#define T_UNSPEC 103 /* Unspecified format (binary data) */
263 /* Query type values which do not appear in resource records */
264#define T_AXFR 252 /* transfer zone of authority */
265#define T_MAILB 253 /* transfer mailbox records */
266#define T_MAILA 254 /* transfer mail agent records */
267#define T_ANY 255 /* wildcard match */
268
269/* These are now defined in ares_nameserv.h
270 Some compilers error when the macro is redefined so
271 we disable them without the macro LEGACY_DEFINES */
272#ifdef ARES_LEGACY_DEFINES
273#define C_IN 1
274#define C_CHAOS 3
275#define C_HS 4
276#define C_ANY 255
277
278#define INDIR_MASK 0xc0
279#define HFIXEDSZ 12
280#define QFIXEDSZ 4
281#define RRFIXEDSZ 10
282
283#define NOERROR 0
284#define FORMERR 1
285#define SERVFAIL 2
286#define NXDOMAIN 3
287#define NOTIMP 4
288#define REFUSED 5
289
290#define PACKETSZ 512
291#endif
292
293#ifndef MAXHOSTNAMELEN
294#define MAXHOSTNAMELEN 256
295
296#ifndef MAXCDNAME
297#define MAXCDNAME 255 /* maximum compressed domain name */
298#endif
299
300#define NS_DEFAULTPORT 53
301#define NAMESERVER_PORT NS_DEFAULTPORT
302
303#ifndef QUERY
304#define QUERY 0
305#endif
306
307#ifndef MAXLABEL
308#define MAXLABEL 63
309#endif
310
311#endif
312
313#endif
314
315#if defined(__cplusplus)
316}
317#endif
318
319
320#endif /* ARES__H */
static void callback(void *arg, int status, unsigned char *abuf, int alen)
Definition adig.c:388
void ares_destroy_internal(ares_channel channel, int suppressCallbacks)
void ares_gethostbyname(ares_channel channel, const char *name, int family, ares_host_callback callback, void *arg)
int ares_capabilities(int capmask)
Definition ares_init.c:94
ares_poll_action
Definition ares.h:127
@ ARES_POLLACTION_WRITEOFF
Definition ares.h:132
@ ARES_POLLACTION_NULL
Definition ares.h:128
@ ARES_POLLACTION_WRITEON
Definition ares.h:131
@ ARES_POLLACTION_CLOSE
Definition ares.h:130
@ ARES_POLLACTION_OPEN
Definition ares.h:129
void ares_free_string(char *str)
struct ares_channeldata * ares_channel
Definition ares.h:171
int ares_init(ares_channel *channelptr)
Definition ares_init.c:104
int ares_init_with_socket_function(ares_channel *channelptr, socket_function_ptr)
Definition ares_init.c:109
void() ares_poll_cb_func(void *cb_data, struct ares_channeldata *chan, int sockidx, int fd, int using_tcp, ares_poll_action_t act)
Definition ares.h:135
int ares_init_options_with_socket_function(ares_channel *channelptr, struct ares_options *options, int optmask, socket_function_ptr)
Definition ares_init.c:120
struct timeval * ares_timeout(ares_channel channel, struct timeval *maxtv, struct timeval *tv)
void ares_process(ares_channel channel, fd_set *read_fds, fd_set *write_fds)
void ares_search(ares_channel channel, const char *name, int dnsclass, int type, ares_callback callback, void *arg)
Definition ares_search.c:45
int ares_parse_a_reply(const unsigned char *abuf, int alen, struct hostent **host)
const char * ares_strerror(int code)
void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen, int family, ares_host_callback callback, void *arg)
void ares_destroy(ares_channel channel)
int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id, int rd, unsigned char **buf, int *buflen)
void ares_process_poll(ares_channel channel, int server_idx, int rdFd, int wrFd, time_t now)
int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf, int alen, char **s, long *enclen)
int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds)
Definition ares_fds.c:22
int hostfile_lookup(const char *name, struct hostent **host)
void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen, ares_callback callback, void *arg)
Definition ares_send.c:33
void ares_free_hostent(struct hostent *host)
void(* ares_host_callback)(void *arg, int status, struct hostent *hostent)
Definition ares.h:174
void ares_query(ares_channel channel, const char *name, int dnsclass, int type, ares_callback callback, void *arg)
Definition ares_query.c:38
void(* ares_callback)(void *arg, int status, unsigned char *abuf, int alen)
Definition ares.h:172
int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr, int addrlen, int family, struct hostent **host)
int ares_init_options(ares_channel *channelptr, struct ares_options *options, int optmask)
Definition ares_init.c:114
enum ares_poll_action ares_poll_action_t
void ares_destroy_suppress_callbacks(ares_channel channel)
void ares_free_errmem(char *mem)
void ares_process_set_poll_cb(ares_channel channel, ares_poll_cb_func *cb_func, void *cb_data)
void(* socket_function_ptr)(Socket s, int transportType, const char *file, int line)
unsigned short tcp_port
Definition ares.h:156
int tries
Definition ares.h:153
int flags
Definition ares.h:151
int nservers
Definition ares.h:162
int ndomains
Definition ares.h:164
int timeout
Definition ares.h:152
unsigned short udp_port
Definition ares.h:155
struct multiFamilyAddr * servers
Definition ares.h:158
char * lookups
Definition ares.h:165
int ndots
Definition ares.h:154
char ** domains
Definition ares.h:163
struct in_addr addr
Definition ares.h:146
u_int8_t family
Definition ares.h:144
struct in6_addr addr6
Definition ares.h:145
void list()
Definition userAdmin.cxx:66