include sys/select.h
[platform/upstream/c-ares.git] / ares.h
1 /* $Id$ */
2
3 /* Copyright 1998 by the Massachusetts Institute of Technology.
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 <sys/types.h>
22
23 #ifdef HAVE_SYS_SELECT_H
24 #include <sys/select.h>
25 #endif
26
27 #ifdef WIN32
28 #include <winsock.h>
29 #include <windows.h>
30 #else
31 #include <netinet/in.h>
32 #endif
33
34 #define ARES_SUCCESS            0
35
36 /* Server error codes (ARES_ENODATA indicates no relevant answer) */
37 #define ARES_ENODATA            1
38 #define ARES_EFORMERR           2
39 #define ARES_ESERVFAIL          3
40 #define ARES_ENOTFOUND          4
41 #define ARES_ENOTIMP            5
42 #define ARES_EREFUSED           6
43
44 /* Locally generated error codes */
45 #define ARES_EBADQUERY          7
46 #define ARES_EBADNAME           8
47 #define ARES_EBADFAMILY         9
48 #define ARES_EBADRESP           10
49 #define ARES_ECONNREFUSED       11
50 #define ARES_ETIMEOUT           12
51 #define ARES_EOF                13
52 #define ARES_EFILE              14
53 #define ARES_ENOMEM             15
54 #define ARES_EDESTRUCTION       16
55
56 /* Flag values */
57 #define ARES_FLAG_USEVC         (1 << 0)
58 #define ARES_FLAG_PRIMARY       (1 << 1)
59 #define ARES_FLAG_IGNTC         (1 << 2)
60 #define ARES_FLAG_NORECURSE     (1 << 3)
61 #define ARES_FLAG_STAYOPEN      (1 << 4)
62 #define ARES_FLAG_NOSEARCH      (1 << 5)
63 #define ARES_FLAG_NOALIASES     (1 << 6)
64 #define ARES_FLAG_NOCHECKRESP   (1 << 7)
65
66 /* Option mask values */
67 #define ARES_OPT_FLAGS          (1 << 0)
68 #define ARES_OPT_TIMEOUT        (1 << 1)
69 #define ARES_OPT_TRIES          (1 << 2)
70 #define ARES_OPT_NDOTS          (1 << 3)
71 #define ARES_OPT_UDP_PORT       (1 << 4)
72 #define ARES_OPT_TCP_PORT       (1 << 5)
73 #define ARES_OPT_SERVERS        (1 << 6)
74 #define ARES_OPT_DOMAINS        (1 << 7)
75 #define ARES_OPT_LOOKUPS        (1 << 8)
76
77 struct ares_options {
78   int flags;
79   int timeout;
80   int tries;
81   int ndots;
82   unsigned short udp_port;
83   unsigned short tcp_port;
84   struct in_addr *servers;
85   int nservers;
86   char **domains;
87   int ndomains;
88   char *lookups;
89 };
90
91 struct hostent;
92 struct timeval;
93 struct ares_channeldata;
94 typedef struct ares_channeldata *ares_channel;
95 typedef void (*ares_callback)(void *arg, int status, unsigned char *abuf,
96                               int alen);
97 typedef void (*ares_host_callback)(void *arg, int status,
98                                    struct hostent *hostent);
99
100 int ares_init(ares_channel *channelptr);
101 int ares_init_options(ares_channel *channelptr, struct ares_options *options,
102                       int optmask);
103 void ares_destroy(ares_channel channel);
104
105 void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
106                ares_callback callback, void *arg);
107 void ares_query(ares_channel channel, const char *name, int dnsclass,
108                 int type, ares_callback callback, void *arg);
109 void ares_search(ares_channel channel, const char *name, int dnsclass,
110                  int type, ares_callback callback, void *arg);
111 void ares_gethostbyname(ares_channel channel, const char *name, int family,
112                         ares_host_callback callback, void *arg);
113 void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
114                         int family, ares_host_callback callback, void *arg);
115
116 int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
117 struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
118                              struct timeval *tv);
119 void ares_process(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
120
121 int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id,
122                  int rd, unsigned char **buf, int *buflen);
123 int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
124                      int alen, char **s, long *enclen);
125 int ares_parse_a_reply(const unsigned char *abuf, int alen,
126                        struct hostent **host);
127 int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
128                          int addrlen, int family, struct hostent **host);
129 void ares_free_string(void *str);
130 void ares_free_hostent(struct hostent *host);
131 const char *ares_strerror(int code);
132 void ares_free_errmem(char *mem);
133
134 #endif /* ARES__H */