Cleanup windows header includes. Where aplicable, inclusion of
[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 #if defined(_AIX) || defined(NETWARE)
24 /* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
25    libc5-based Linux systems. Only include it on system that are known to
26    require it! */
27 #include <sys/select.h>
28 #endif
29
30 #if defined(WATT32)
31   #include <netinet/in.h>
32   #include <sys/socket.h>
33   #include <tcp.h>
34 #elif !defined(WIN32)
35   #include <netinet/in.h>
36   #include <sys/socket.h>
37 #endif
38
39 #ifdef  __cplusplus
40 extern "C" {
41 #endif
42
43 #define ARES_SUCCESS            0
44
45 /* Server error codes (ARES_ENODATA indicates no relevant answer) */
46 #define ARES_ENODATA            1
47 #define ARES_EFORMERR           2
48 #define ARES_ESERVFAIL          3
49 #define ARES_ENOTFOUND          4
50 #define ARES_ENOTIMP            5
51 #define ARES_EREFUSED           6
52
53 /* Locally generated error codes */
54 #define ARES_EBADQUERY          7
55 #define ARES_EBADNAME           8
56 #define ARES_EBADFAMILY         9
57 #define ARES_EBADRESP           10
58 #define ARES_ECONNREFUSED       11
59 #define ARES_ETIMEOUT           12
60 #define ARES_EOF                13
61 #define ARES_EFILE              14
62 #define ARES_ENOMEM             15
63 #define ARES_EDESTRUCTION       16
64 #define ARES_EBADSTR            17
65
66 /* ares_getnameinfo error codes */
67 #define ARES_EBADFLAGS          18
68
69 /* ares_getaddrinfo error codes */
70 #define ARES_ENONAME            19
71 #define ARES_EBADHINTS          20
72
73 /* Flag values */
74 #define ARES_FLAG_USEVC         (1 << 0)
75 #define ARES_FLAG_PRIMARY       (1 << 1)
76 #define ARES_FLAG_IGNTC         (1 << 2)
77 #define ARES_FLAG_NORECURSE     (1 << 3)
78 #define ARES_FLAG_STAYOPEN      (1 << 4)
79 #define ARES_FLAG_NOSEARCH      (1 << 5)
80 #define ARES_FLAG_NOALIASES     (1 << 6)
81 #define ARES_FLAG_NOCHECKRESP   (1 << 7)
82
83 /* Option mask values */
84 #define ARES_OPT_FLAGS          (1 << 0)
85 #define ARES_OPT_TIMEOUT        (1 << 1)
86 #define ARES_OPT_TRIES          (1 << 2)
87 #define ARES_OPT_NDOTS          (1 << 3)
88 #define ARES_OPT_UDP_PORT       (1 << 4)
89 #define ARES_OPT_TCP_PORT       (1 << 5)
90 #define ARES_OPT_SERVERS        (1 << 6)
91 #define ARES_OPT_DOMAINS        (1 << 7)
92 #define ARES_OPT_LOOKUPS        (1 << 8)
93
94 /* Nameinfo flag values */
95 #define ARES_NI_NOFQDN                  (1 << 0)
96 #define ARES_NI_NUMERICHOST             (1 << 1)
97 #define ARES_NI_NAMEREQD                (1 << 2)
98 #define ARES_NI_NUMERICSERV             (1 << 3)
99 #define ARES_NI_DGRAM                   (1 << 4)
100 #define ARES_NI_TCP                     0
101 #define ARES_NI_UDP                     ARES_NI_DGRAM
102 #define ARES_NI_SCTP                    (1 << 5)
103 #define ARES_NI_DCCP                    (1 << 6)
104 #define ARES_NI_NUMERICSCOPE            (1 << 7)
105 #define ARES_NI_LOOKUPHOST              (1 << 8)
106 #define ARES_NI_LOOKUPSERVICE           (1 << 9)
107 /* Reserved for future use */
108 #define ARES_NI_IDN                     (1 << 10)
109 #define ARES_NI_IDN_ALLOW_UNASSIGNED    (1 << 11)
110 #define ARES_NI_IDN_USE_STD3_ASCII_RULES (1 << 12)
111
112 /* Addrinfo flag values */
113 #define ARES_AI_CANONNAME               (1 << 0)
114 #define ARES_AI_NUMERICHOST             (1 << 1)
115 #define ARES_AI_PASSIVE                 (1 << 2)
116 #define ARES_AI_NUMERICSERV             (1 << 3)
117 #define ARES_AI_V4MAPPED                (1 << 4)
118 #define ARES_AI_ALL                     (1 << 5)
119 #define ARES_AI_ADDRCONFIG              (1 << 6)
120 /* Reserved for future use */
121 #define ARES_AI_IDN                     (1 << 10)
122 #define ARES_AI_IDN_ALLOW_UNASSIGNED    (1 << 11)
123 #define ARES_AI_IDN_USE_STD3_ASCII_RULES (1 << 12)
124 #define ARES_AI_CANONIDN                (1 << 13)
125
126 #define ARES_AI_MASK                    (ARES_AI_CANONNAME|ARES_AI_NUMERICHOST|ARES_AI_PASSIVE| \
127                                          ARES_AI_NUMERICSERV|ARES_AI_V4MAPPED|ARES_AI_ALL| \
128                                          ARES_AI_ADDRCONFIG)
129
130 struct ares_options {
131   int flags;
132   int timeout;
133   int tries;
134   int ndots;
135   unsigned short udp_port;
136   unsigned short tcp_port;
137   struct in_addr *servers;
138   int nservers;
139   char **domains;
140   int ndomains;
141   char *lookups;
142 };
143
144 struct hostent;
145 struct timeval;
146 struct sockaddr;
147 struct ares_channeldata;
148 typedef struct ares_channeldata *ares_channel;
149 typedef void (*ares_callback)(void *arg, int status, unsigned char *abuf,
150                               int alen);
151 typedef void (*ares_host_callback)(void *arg, int status,
152                                    struct hostent *hostent);
153 typedef void (*ares_nameinfo_callback)(void *arg, int status,
154                                        char *node, char *service);
155
156 int ares_init(ares_channel *channelptr);
157 int ares_init_options(ares_channel *channelptr, struct ares_options *options,
158                       int optmask);
159 void ares_destroy(ares_channel channel);
160 void ares_cancel(ares_channel channel);
161 void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
162                ares_callback callback, void *arg);
163 void ares_query(ares_channel channel, const char *name, int dnsclass,
164                 int type, ares_callback callback, void *arg);
165 void ares_search(ares_channel channel, const char *name, int dnsclass,
166                  int type, ares_callback callback, void *arg);
167 void ares_gethostbyname(ares_channel channel, const char *name, int family,
168                         ares_host_callback callback, void *arg);
169 void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
170                         int family, ares_host_callback callback, void *arg);
171 void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
172                       socklen_t salen, int flags, ares_nameinfo_callback callback,
173                       void *arg);
174 int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
175 struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
176                              struct timeval *tv);
177 void ares_process(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
178
179 int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id,
180                  int rd, unsigned char **buf, int *buflen);
181 int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
182                      int alen, char **s, long *enclen);
183 int ares_expand_string(const unsigned char *encoded, const unsigned char *abuf,
184                      int alen, unsigned char **s, long *enclen);
185 int ares_parse_a_reply(const unsigned char *abuf, int alen,
186                        struct hostent **host);
187 int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
188                        struct hostent **host);
189 int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
190                          int addrlen, int family, struct hostent **host);
191 void ares_free_string(void *str);
192 void ares_free_hostent(struct hostent *host);
193 const char *ares_strerror(int code);
194
195 #ifdef  __cplusplus
196 }
197 #endif
198
199 #endif /* ARES__H */