Added debug option ('-d') for Watt-32 programs.
[platform/upstream/c-ares.git] / ares_private.h
1 #ifndef __ARES_PRIVATE_H
2 #define __ARES_PRIVATE_H
3
4 /* $Id$ */
5
6 /* Copyright 1998 by the Massachusetts Institute of Technology.
7  *
8  * Permission to use, copy, modify, and distribute this
9  * software and its documentation for any purpose and without
10  * fee is hereby granted, provided that the above copyright
11  * notice appear in all copies and that both that copyright
12  * notice and this permission notice appear in supporting
13  * documentation, and that the name of M.I.T. not be used in
14  * advertising or publicity pertaining to distribution of the
15  * software without specific, written prior permission.
16  * M.I.T. makes no representations about the suitability of
17  * this software for any purpose.  It is provided "as is"
18  * without express or implied warranty.
19  */
20
21 #include <stdio.h>
22 #include <sys/types.h>
23
24 #if !defined(WIN32) || defined(WATT32)
25 #include <netinet/in.h>
26 /* We define closesocket() here so that we can use this function all over
27    the source code for closing sockets. */
28 #define closesocket(x) close(x)
29 #endif
30
31 #ifdef WATT32
32 #include <tcp.h>
33 #include <sys/ioctl.h>
34 #undef  closesocket
35 #define closesocket(s)    close_s(s)
36 #define writev(s,v,c)     writev_s(s,v,c)
37 #endif
38
39 #ifdef NETWARE
40 #include <time.h>
41 #endif
42
43 #define DEFAULT_TIMEOUT         5
44 #define DEFAULT_TRIES           4
45 #ifndef INADDR_NONE
46 #define INADDR_NONE 0xffffffff
47 #endif
48
49 #if defined(WIN32) && !defined(WATT32)
50
51 #define IS_NT()        ((int)GetVersion() > 0)
52 #define WIN_NS_9X      "System\\CurrentControlSet\\Services\\VxD\\MSTCP"
53 #define WIN_NS_NT_KEY  "System\\CurrentControlSet\\Services\\Tcpip\\Parameters"
54 #define NAMESERVER     "NameServer"
55 #define DHCPNAMESERVER "DhcpNameServer"
56 #define DATABASEPATH   "DatabasePath"
57 #define WIN_PATH_HOSTS  "\\hosts"
58
59 #elif defined(WATT32)
60
61 #define PATH_RESOLV_CONF "/dev/ENV/etc/resolv.conf"
62
63 #elif defined(NETWARE)
64
65 #define PATH_RESOLV_CONF "sys:/etc/resolv.cfg"
66 #define PATH_HOSTS              "sys:/etc/hosts"
67
68 #elif defined(__riscos__)
69
70 #define PATH_HOSTS             "InetDBase:Hosts"
71
72 #else
73
74 #define PATH_RESOLV_CONF        "/etc/resolv.conf"
75 #ifdef ETC_INET
76 #define PATH_HOSTS              "/etc/inet/hosts"
77 #else
78 #define PATH_HOSTS              "/etc/hosts"
79 #endif
80
81 #endif
82
83 #include "ares_ipv6.h"
84
85 struct send_request {
86   /* Remaining data to send */
87   const unsigned char *data;
88   size_t len;
89
90   /* Next request in queue */
91   struct send_request *next;
92 };
93
94 struct server_state {
95   struct in_addr addr;
96   ares_socket_t udp_socket;
97   ares_socket_t tcp_socket;
98
99   /* Mini-buffer for reading the length word */
100   unsigned char tcp_lenbuf[2];
101   int tcp_lenbuf_pos;
102   int tcp_length;
103
104   /* Buffer for reading actual TCP data */
105   unsigned char *tcp_buffer;
106   int tcp_buffer_pos;
107
108   /* TCP output queue */
109   struct send_request *qhead;
110   struct send_request *qtail;
111 };
112
113 struct query {
114   /* Query ID from qbuf, for faster lookup, and current timeout */
115   unsigned short qid;
116   time_t timeout;
117
118   /* Query buf with length at beginning, for TCP transmission */
119   unsigned char *tcpbuf;
120   int tcplen;
121
122   /* Arguments passed to ares_send() (qbuf points into tcpbuf) */
123   const unsigned char *qbuf;
124   int qlen;
125   ares_callback callback;
126   void *arg;
127
128   /* Query status */
129   int try;
130   int server;
131   int *skip_server;
132   int using_tcp;
133   int error_status;
134
135   /* Next query in chain */
136   struct query *next;
137 };
138
139 /* An IP address pattern; matches an IP address X if X & mask == addr */
140 #define PATTERN_MASK 0x1
141 #define PATTERN_CIDR 0x2
142
143 union ares_addr {
144   struct in_addr addr4;
145   struct in6_addr addr6;
146 };
147
148 struct apattern {
149   union ares_addr addr;
150   union
151   {
152     union ares_addr addr;
153     unsigned short bits;
154   } mask;
155   int family;
156   unsigned short type;
157 };
158
159 struct ares_channeldata {
160   /* Configuration data */
161   int flags;
162   int timeout;
163   int tries;
164   int ndots;
165   int udp_port;
166   int tcp_port;
167   char **domains;
168   int ndomains;
169   struct apattern *sortlist;
170   int nsort;
171   char *lookups;
172
173   /* Server addresses and communications state */
174   struct server_state *servers;
175   int nservers;
176
177   /* ID to use for next query */
178   unsigned short next_id;
179
180   /* Active queries */
181   struct query *queries;
182
183   ares_sock_state_cb sock_state_cb;
184   void *sock_state_cb_data;
185 };
186
187 void ares__send_query(ares_channel channel, struct query *query, time_t now);
188 void ares__close_sockets(ares_channel channel, struct server_state *server);
189 int ares__get_hostent(FILE *fp, int family, struct hostent **host);
190 int ares__read_line(FILE *fp, char **buf, int *bufsize);
191
192 #define SOCK_STATE_CALLBACK(c, s, r, w)                                 \
193   do {                                                                  \
194     if ((c)->sock_state_cb)                                             \
195       (c)->sock_state_cb((c)->sock_state_cb_data, (s), (r), (w));       \
196   } while (0)
197
198 #ifdef CURLDEBUG
199 /* This is low-level hard-hacking memory leak tracking and similar. Using the
200    libcurl lowlevel code from within library is ugly and only works when
201    c-ares is built and linked with a similarly debug-build libcurl, but we do
202    this anyway for convenience. */
203 #include "../lib/memdebug.h"
204 #endif
205
206 #endif /* __ARES_PRIVATE_H */
207