Dominick Meglio added ares_parse_aaaa_reply.c and did various adjustments. The
[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 <tcp.h>
33 #elif defined(WIN32)
34   #include <winsock.h>
35   #include <windows.h>
36 #else
37   #include <netinet/in.h>
38 #endif
39
40 #ifdef  __cplusplus
41 extern "C" {
42 #endif
43
44 #define ARES_SUCCESS            0
45
46 /* Server error codes (ARES_ENODATA indicates no relevant answer) */
47 #define ARES_ENODATA            1
48 #define ARES_EFORMERR           2
49 #define ARES_ESERVFAIL          3
50 #define ARES_ENOTFOUND          4
51 #define ARES_ENOTIMP            5
52 #define ARES_EREFUSED           6
53
54 /* Locally generated error codes */
55 #define ARES_EBADQUERY          7
56 #define ARES_EBADNAME           8
57 #define ARES_EBADFAMILY         9
58 #define ARES_EBADRESP           10
59 #define ARES_ECONNREFUSED       11
60 #define ARES_ETIMEOUT           12
61 #define ARES_EOF                13
62 #define ARES_EFILE              14
63 #define ARES_ENOMEM             15
64 #define ARES_EDESTRUCTION       16
65 #define ARES_EBADSTR            17
66
67 /* Flag values */
68 #define ARES_FLAG_USEVC         (1 << 0)
69 #define ARES_FLAG_PRIMARY       (1 << 1)
70 #define ARES_FLAG_IGNTC         (1 << 2)
71 #define ARES_FLAG_NORECURSE     (1 << 3)
72 #define ARES_FLAG_STAYOPEN      (1 << 4)
73 #define ARES_FLAG_NOSEARCH      (1 << 5)
74 #define ARES_FLAG_NOALIASES     (1 << 6)
75 #define ARES_FLAG_NOCHECKRESP   (1 << 7)
76
77 /* Option mask values */
78 #define ARES_OPT_FLAGS          (1 << 0)
79 #define ARES_OPT_TIMEOUT        (1 << 1)
80 #define ARES_OPT_TRIES          (1 << 2)
81 #define ARES_OPT_NDOTS          (1 << 3)
82 #define ARES_OPT_UDP_PORT       (1 << 4)
83 #define ARES_OPT_TCP_PORT       (1 << 5)
84 #define ARES_OPT_SERVERS        (1 << 6)
85 #define ARES_OPT_DOMAINS        (1 << 7)
86 #define ARES_OPT_LOOKUPS        (1 << 8)
87
88 struct ares_options {
89   int flags;
90   int timeout;
91   int tries;
92   int ndots;
93   unsigned short udp_port;
94   unsigned short tcp_port;
95   struct in_addr *servers;
96   int nservers;
97   char **domains;
98   int ndomains;
99   char *lookups;
100 };
101
102 struct hostent;
103 struct timeval;
104 struct ares_channeldata;
105 typedef struct ares_channeldata *ares_channel;
106 typedef void (*ares_callback)(void *arg, int status, unsigned char *abuf,
107                               int alen);
108 typedef void (*ares_host_callback)(void *arg, int status,
109                                    struct hostent *hostent);
110
111 int ares_init(ares_channel *channelptr);
112 int ares_init_options(ares_channel *channelptr, struct ares_options *options,
113                       int optmask);
114 void ares_destroy(ares_channel channel);
115 void ares_cancel(ares_channel channel);
116 void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
117                ares_callback callback, void *arg);
118 void ares_query(ares_channel channel, const char *name, int dnsclass,
119                 int type, ares_callback callback, void *arg);
120 void ares_search(ares_channel channel, const char *name, int dnsclass,
121                  int type, ares_callback callback, void *arg);
122 void ares_gethostbyname(ares_channel channel, const char *name, int family,
123                         ares_host_callback callback, void *arg);
124 void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
125                         int family, ares_host_callback callback, void *arg);
126
127 int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
128 struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
129                              struct timeval *tv);
130 void ares_process(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
131
132 int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id,
133                  int rd, unsigned char **buf, int *buflen);
134 int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
135                      int alen, char **s, long *enclen);
136 int ares_expand_string(const unsigned char *encoded, const unsigned char *abuf,
137                      int alen, unsigned char **s, long *enclen);
138 int ares_parse_a_reply(const unsigned char *abuf, int alen,
139                        struct hostent **host);
140 int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
141                        struct hostent **host);
142 int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
143                          int addrlen, int family, struct hostent **host);
144 void ares_free_string(void *str);
145 void ares_free_hostent(struct hostent *host);
146 const char *ares_strerror(int code);
147
148 #ifdef  __cplusplus
149 }
150 #endif
151
152 #endif /* ARES__H */