Permalink
Newer
Older
100644 510 lines (420 sloc) 17.3 KB
1
/* $Id$ */
2
3
/* Copyright 1998, 2009 by the Massachusetts Institute of Technology.
4
* Copyright (C) 2007-2010 by Daniel Stenberg
5
*
6
* Permission to use, copy, modify, and distribute this
7
* software and its documentation for any purpose and without
8
* fee is hereby granted, provided that the above copyright
9
* notice appear in all copies and that both that copyright
10
* notice and this permission notice appear in supporting
11
* documentation, and that the name of M.I.T. not be used in
12
* advertising or publicity pertaining to distribution of the
13
* software without specific, written prior permission.
14
* M.I.T. makes no representations about the suitability of
15
* this software for any purpose. It is provided "as is"
16
* without express or implied warranty.
17
*/
18
19
#ifndef ARES__H
20
#define ARES__H
21
22
#include "ares_version.h" /* c-ares version defines */
23
#include "ares_build.h" /* c-ares build definitions */
24
#include "ares_rules.h" /* c-ares rules enforcement */
26
/*
27
* Define WIN32 when build target is Win32 API
28
*/
29
30
#if (defined(_WIN32) || defined(__WIN32__)) && \
31
!defined(WIN32) && !defined(__SYMBIAN32__)
32
# define WIN32
35
#include <sys/types.h>
36
37
/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
38
libc5-based Linux systems. Only include it on system that are known to
39
require it! */
40
#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \
41
defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY)
Feb 23, 2004
42
#include <sys/select.h>
43
#endif
44
#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
45
#include <sys/bsdskt.h>
46
#endif
Feb 23, 2004
47
48
#if defined(WATT32)
49
# include <netinet/in.h>
50
# include <sys/socket.h>
51
# include <tcp.h>
52
#elif defined(WIN32)
53
# ifndef WIN32_LEAN_AND_MEAN
54
# define WIN32_LEAN_AND_MEAN
55
# endif
56
# include <windows.h>
57
# include <winsock2.h>
58
# include <ws2tcpip.h>
60
# include <sys/socket.h>
61
# include <netinet/in.h>
Gisle Vanem
Nov 11, 2004
64
#ifdef __cplusplus
65
extern "C" {
66
#endif
67
68
/*
69
** c-ares external API function linkage decorations.
70
*/
71
72
#if !defined(CARES_STATICLIB) && \
73
(defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__))
74
/* __declspec function decoration for Win32 and Symbian DLL's */
75
# if defined(CARES_BUILDING_LIBRARY)
76
# define CARES_EXTERN __declspec(dllexport)
77
# else
78
# define CARES_EXTERN __declspec(dllimport)
79
# endif
80
#else
81
/* visibility function decoration for other cases */
82
# if !defined(CARES_SYMBOL_HIDING) || \
83
defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__)
86
# define CARES_EXTERN CARES_SYMBOL_SCOPE_EXTERN
91
#define ARES_SUCCESS 0
92
93
/* Server error codes (ARES_ENODATA indicates no relevant answer) */
94
#define ARES_ENODATA 1
95
#define ARES_EFORMERR 2
96
#define ARES_ESERVFAIL 3
97
#define ARES_ENOTFOUND 4
98
#define ARES_ENOTIMP 5
99
#define ARES_EREFUSED 6
100
101
/* Locally generated error codes */
102
#define ARES_EBADQUERY 7
103
#define ARES_EBADNAME 8
104
#define ARES_EBADFAMILY 9
105
#define ARES_EBADRESP 10
106
#define ARES_ECONNREFUSED 11
107
#define ARES_ETIMEOUT 12
108
#define ARES_EOF 13
109
#define ARES_EFILE 14
110
#define ARES_ENOMEM 15
111
#define ARES_EDESTRUCTION 16
112
#define ARES_EBADSTR 17
114
/* ares_getnameinfo error codes */
Aug 18, 2005
115
#define ARES_EBADFLAGS 18
117
/* ares_getaddrinfo error codes */
118
#define ARES_ENONAME 19
119
#define ARES_EBADHINTS 20
121
/* Uninitialized library error code */
122
#define ARES_ENOTINITIALIZED 21 /* introduced in 1.7.0 */
124
/* ares_library_init error codes */
125
#define ARES_ELOADIPHLPAPI 22 /* introduced in 1.7.0 */
126
#define ARES_EADDRGETNETWORKPARAMS 23 /* introduced in 1.7.0 */
129
#define ARES_ECANCELLED 24 /* introduced in 1.7.0 */
131
/* Flag values */
132
#define ARES_FLAG_USEVC (1 << 0)
133
#define ARES_FLAG_PRIMARY (1 << 1)
134
#define ARES_FLAG_IGNTC (1 << 2)
135
#define ARES_FLAG_NORECURSE (1 << 3)
136
#define ARES_FLAG_STAYOPEN (1 << 4)
137
#define ARES_FLAG_NOSEARCH (1 << 5)
138
#define ARES_FLAG_NOALIASES (1 << 6)
139
#define ARES_FLAG_NOCHECKRESP (1 << 7)
140
141
/* Option mask values */
142
#define ARES_OPT_FLAGS (1 << 0)
143
#define ARES_OPT_TIMEOUT (1 << 1)
144
#define ARES_OPT_TRIES (1 << 2)
145
#define ARES_OPT_NDOTS (1 << 3)
146
#define ARES_OPT_UDP_PORT (1 << 4)
147
#define ARES_OPT_TCP_PORT (1 << 5)
148
#define ARES_OPT_SERVERS (1 << 6)
149
#define ARES_OPT_DOMAINS (1 << 7)
150
#define ARES_OPT_LOOKUPS (1 << 8)
151
#define ARES_OPT_SOCK_STATE_CB (1 << 9)
152
#define ARES_OPT_SORTLIST (1 << 10)
153
#define ARES_OPT_SOCK_SNDBUF (1 << 11)
154
#define ARES_OPT_SOCK_RCVBUF (1 << 12)
155
#define ARES_OPT_TIMEOUTMS (1 << 13)
156
#define ARES_OPT_ROTATE (1 << 14)
158
/* Nameinfo flag values */
Aug 18, 2005
159
#define ARES_NI_NOFQDN (1 << 0)
160
#define ARES_NI_NUMERICHOST (1 << 1)
161
#define ARES_NI_NAMEREQD (1 << 2)
162
#define ARES_NI_NUMERICSERV (1 << 3)
163
#define ARES_NI_DGRAM (1 << 4)
164
#define ARES_NI_TCP 0
165
#define ARES_NI_UDP ARES_NI_DGRAM
166
#define ARES_NI_SCTP (1 << 5)
167
#define ARES_NI_DCCP (1 << 6)
168
#define ARES_NI_NUMERICSCOPE (1 << 7)
169
#define ARES_NI_LOOKUPHOST (1 << 8)
170
#define ARES_NI_LOOKUPSERVICE (1 << 9)
171
/* Reserved for future use */
172
#define ARES_NI_IDN (1 << 10)
173
#define ARES_NI_IDN_ALLOW_UNASSIGNED (1 << 11)
174
#define ARES_NI_IDN_USE_STD3_ASCII_RULES (1 << 12)
175
176
/* Addrinfo flag values */
177
#define ARES_AI_CANONNAME (1 << 0)
178
#define ARES_AI_NUMERICHOST (1 << 1)
179
#define ARES_AI_PASSIVE (1 << 2)
180
#define ARES_AI_NUMERICSERV (1 << 3)
181
#define ARES_AI_V4MAPPED (1 << 4)
182
#define ARES_AI_ALL (1 << 5)
183
#define ARES_AI_ADDRCONFIG (1 << 6)
185
#define ARES_AI_IDN (1 << 10)
186
#define ARES_AI_IDN_ALLOW_UNASSIGNED (1 << 11)
187
#define ARES_AI_IDN_USE_STD3_ASCII_RULES (1 << 12)
188
#define ARES_AI_CANONIDN (1 << 13)
190
#define ARES_AI_MASK (ARES_AI_CANONNAME|ARES_AI_NUMERICHOST|ARES_AI_PASSIVE| \
191
ARES_AI_NUMERICSERV|ARES_AI_V4MAPPED|ARES_AI_ALL| \
192
ARES_AI_ADDRCONFIG)
193
#define ARES_GETSOCK_MAXNUM 16 /* ares_getsock() can return info about this
194
many sockets */
195
#define ARES_GETSOCK_READABLE(bits,num) (bits & (1<< (num)))
196
#define ARES_GETSOCK_WRITABLE(bits,num) (bits & (1 << ((num) + \
197
ARES_GETSOCK_MAXNUM)))
199
/* c-ares library initialization flag values */
200
#define ARES_LIB_INIT_NONE (0)
201
#define ARES_LIB_INIT_WIN32 (1 << 0)
202
#define ARES_LIB_INIT_ALL (ARES_LIB_INIT_WIN32)
203
204
205
/*
206
* Typedef our socket type
207
*/
208
209
#ifndef ares_socket_typedef
210
#ifdef WIN32
211
typedef SOCKET ares_socket_t;
212
#define ARES_SOCKET_BAD INVALID_SOCKET
213
#else
214
typedef int ares_socket_t;
215
#define ARES_SOCKET_BAD -1
216
#endif
217
#define ares_socket_typedef
218
#endif /* ares_socket_typedef */
219
220
typedef void (*ares_sock_state_cb)(void *data,
221
ares_socket_t socket_fd,
222
int readable,
223
int writable);
224
227
/* NOTE about the ares_options struct to users and developers.
228
229
This struct will remain looking like this. It will not be extended nor
230
shrunk in future releases, but all new options will be set by ares_set_*()
231
options instead of with the ares_init_options() function.
232
233
Eventually (in a galaxy far far away), all options will be settable by
234
ares_set_*() options and the ares_init_options() function will become
235
deprecated.
236
237
When new options are added to c-ares, they are not added to this
238
struct. And they are not "saved" with the ares_save_options() function but
239
instead we encourage the use of the ares_dup() function. Needless to say,
240
if you add config options to c-ares you need to make sure ares_dup()
241
duplicates this new option.
244
struct ares_options {
245
int flags;
246
int timeout; /* in seconds or milliseconds, depending on options */
247
int tries;
248
int ndots;
249
unsigned short udp_port;
250
unsigned short tcp_port;
251
int socket_send_buffer_size;
252
int socket_receive_buffer_size;
253
struct in_addr *servers;
254
int nservers;
255
char **domains;
256
int ndomains;
257
char *lookups;
258
ares_sock_state_cb sock_state_cb;
259
void *sock_state_cb_data;
260
struct apattern *sortlist;
261
int nsort;
262
};
263
264
struct hostent;
265
struct timeval;
267
struct ares_channeldata;
269
typedef struct ares_channeldata *ares_channel;
270
271
typedef void (*ares_callback)(void *arg,
272
int status,
273
int timeouts,
274
unsigned char *abuf,
275
int alen);
276
277
typedef void (*ares_host_callback)(void *arg,
278
int status,
279
int timeouts,
280
struct hostent *hostent);
281
282
typedef void (*ares_nameinfo_callback)(void *arg,
283
int status,
284
int timeouts,
285
char *node,
286
char *service);
287
288
typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd,
289
int type,
290
void *data);
291
292
CARES_EXTERN int ares_library_init(int flags);
293
294
CARES_EXTERN void ares_library_cleanup(void);
295
296
CARES_EXTERN const char *ares_version(int *version);
297
298
CARES_EXTERN int ares_init(ares_channel *channelptr);
299
300
CARES_EXTERN int ares_init_options(ares_channel *channelptr,
301
struct ares_options *options,
302
int optmask);
303
304
CARES_EXTERN int ares_save_options(ares_channel channel,
305
struct ares_options *options,
306
int *optmask);
307
308
CARES_EXTERN void ares_destroy_options(struct ares_options *options);
309
310
CARES_EXTERN int ares_dup(ares_channel *dest,
311
ares_channel src);
312
313
CARES_EXTERN void ares_destroy(ares_channel channel);
314
315
CARES_EXTERN void ares_cancel(ares_channel channel);
316
317
CARES_EXTERN void ares_set_socket_callback(ares_channel channel,
318
ares_sock_create_callback callback,
319
void *user_data);
320
321
CARES_EXTERN void ares_send(ares_channel channel,
322
const unsigned char *qbuf,
323
int qlen,
324
ares_callback callback,
325
void *arg);
326
327
CARES_EXTERN void ares_query(ares_channel channel,
328
const char *name,
329
int dnsclass,
330
int type,
331
ares_callback callback,
332
void *arg);
333
334
CARES_EXTERN void ares_search(ares_channel channel,
335
const char *name,
336
int dnsclass,
337
int type,
338
ares_callback callback,
339
void *arg);
340
341
CARES_EXTERN void ares_gethostbyname(ares_channel channel,
342
const char *name,
343
int family,
344
ares_host_callback callback,
345
void *arg);
346
347
CARES_EXTERN int ares_gethostbyname_file(ares_channel channel,
348
const char *name,
349
int family,
350
struct hostent **host);
351
352
CARES_EXTERN void ares_gethostbyaddr(ares_channel channel,
353
const void *addr,
354
int addrlen,
355
int family,
356
ares_host_callback callback,
357
void *arg);
358
359
CARES_EXTERN void ares_getnameinfo(ares_channel channel,
360
const struct sockaddr *sa,
361
ares_socklen_t salen,
362
int flags,
363
ares_nameinfo_callback callback,
364
void *arg);
365
366
CARES_EXTERN int ares_fds(ares_channel channel,
367
fd_set *read_fds,
368
fd_set *write_fds);
369
370
CARES_EXTERN int ares_getsock(ares_channel channel,
Mar 11, 2010
371
ares_socket_t *socks,
372
int numsocks);
373
374
CARES_EXTERN struct timeval *ares_timeout(ares_channel channel,
375
struct timeval *maxtv,
376
struct timeval *tv);
377
378
CARES_EXTERN void ares_process(ares_channel channel,
379
fd_set *read_fds,
380
fd_set *write_fds);
381
382
CARES_EXTERN void ares_process_fd(ares_channel channel,
383
ares_socket_t read_fd,
384
ares_socket_t write_fd);
385
386
CARES_EXTERN int ares_mkquery(const char *name,
387
int dnsclass,
388
int type,
389
unsigned short id,
390
int rd,
391
unsigned char **buf,
392
int *buflen);
393
394
CARES_EXTERN int ares_expand_name(const unsigned char *encoded,
395
const unsigned char *abuf,
396
int alen,
397
char **s,
398
long *enclen);
399
400
CARES_EXTERN int ares_expand_string(const unsigned char *encoded,
401
const unsigned char *abuf,
402
int alen,
403
unsigned char **s,
404
long *enclen);
407
* NOTE: before c-ares 1.7.0 we would most often use the system in6_addr
408
* struct below when ares itself was built, but many apps would use this
409
* private version since the header checked a HAVE_* define for it. Starting
410
* with 1.7.0 we always declare and use our own to stop relying on the
411
* system's one.
412
*/
413
struct ares_in6_addr {
414
union {
415
unsigned char _S6_u8[16];
416
} _S6_un;
417
};
418
420
struct in_addr ipaddr;
421
int ttl;
422
};
429
struct ares_srv_reply {
430
struct ares_srv_reply *next;
431
char *host;
432
unsigned short priority;
433
unsigned short weight;
434
unsigned short port;
437
struct ares_txt_reply {
438
struct ares_txt_reply *next;
439
unsigned char *txt;
440
size_t length; /* length excludes null termination */
443
/*
444
** Parse the buffer, starting at *abuf and of length alen bytes, previously
445
** obtained from an ares_search call. Put the results in *host, if nonnull.
446
** Also, if addrttls is nonnull, put up to *naddrttls IPv4 addresses along with
447
** their TTLs in that array, and set *naddrttls to the number of addresses
448
** so written.
449
*/
450
451
CARES_EXTERN int ares_parse_a_reply(const unsigned char *abuf,
452
int alen,
453
struct hostent **host,
455
int *naddrttls);
456
457
CARES_EXTERN int ares_parse_aaaa_reply(const unsigned char *abuf,
458
int alen,
459
struct hostent **host,
460
struct ares_addr6ttl *addrttls,
461
int *naddrttls);
462
463
CARES_EXTERN int ares_parse_ptr_reply(const unsigned char *abuf,
464
int alen,
465
const void *addr,
466
int addrlen,
467
int family,
468
struct hostent **host);
469
470
CARES_EXTERN int ares_parse_ns_reply(const unsigned char *abuf,
471
int alen,
472
struct hostent **host);
473
474
CARES_EXTERN int ares_parse_srv_reply(const unsigned char* abuf,
475
int alen,
476
struct ares_srv_reply** srv_out);
478
CARES_EXTERN int ares_parse_txt_reply(const unsigned char* abuf,
479
int alen,
480
struct ares_txt_reply** txt_out);
482
CARES_EXTERN void ares_free_string(void *str);
483
484
CARES_EXTERN void ares_free_hostent(struct hostent *host);
485
486
CARES_EXTERN void ares_free_data(void *dataptr);
487
488
CARES_EXTERN const char *ares_strerror(int code);
490
struct ares_addr_node {
491
struct ares_addr_node *next;
492
int family;
493
union {
494
struct in_addr addr4;
495
struct ares_in6_addr addr6;
496
} addr;
497
};
498
499
CARES_EXTERN int ares_set_servers(ares_channel channel,
500
struct ares_addr_node *servers);
501
502
CARES_EXTERN int ares_get_servers(ares_channel channel,
503
struct ares_addr_node **servers);
504
Gisle Vanem
Nov 11, 2004
505
#ifdef __cplusplus
506
}
507
#endif
508
509
#endif /* ARES__H */