windows fixes (Gregory Alexander)
[qemu] / slirp / slirp.h
1 #ifndef __COMMON_H__
2 #define __COMMON_H__
3
4 #define CONFIG_QEMU
5
6 #define DEBUG 1
7
8 #ifndef CONFIG_QEMU
9 #include "version.h"
10 #endif
11 #include "config.h"
12 #include "slirp_config.h"
13
14 #ifdef _WIN32
15 # include <inttypes.h>
16
17 typedef uint8_t u_int8_t;
18 typedef uint16_t u_int16_t;
19 typedef uint32_t u_int32_t;
20 typedef uint64_t u_int64_t;
21 typedef char *caddr_t;
22
23 # include <winsock2.h>
24 # include <sys/timeb.h>
25 # include <iphlpapi.h>
26
27 # define EWOULDBLOCK WSAEWOULDBLOCK
28 # define EINPROGRESS WSAEINPROGRESS
29 # define ENOTCONN WSAENOTCONN
30 # define EHOSTUNREACH WSAEHOSTUNREACH
31 # define ENETUNREACH WSAENETUNREACH
32 # define ECONNREFUSED WSAECONNREFUSED
33 #else
34 # define ioctlsocket ioctl
35 # define closesocket(s) close(s)
36 #endif
37
38 #include <sys/types.h>
39 #ifdef HAVE_SYS_BITYPES_H
40 # include <sys/bitypes.h>
41 #endif
42
43 #include <sys/time.h>
44
45 #ifdef NEED_TYPEDEFS
46 typedef char int8_t;
47 typedef unsigned char u_int8_t;
48
49 # if SIZEOF_SHORT == 2
50     typedef short int16_t;
51     typedef unsigned short u_int16_t;
52 # else
53 #  if SIZEOF_INT == 2
54     typedef int int16_t;
55     typedef unsigned int u_int16_t;
56 #  else
57     #error Cannot find a type with sizeof() == 2
58 #  endif
59 # endif
60
61 # if SIZEOF_SHORT == 4
62    typedef short int32_t;
63    typedef unsigned short u_int32_t;
64 # else
65 #  if SIZEOF_INT == 4
66     typedef int int32_t;
67     typedef unsigned int u_int32_t;
68 #  else
69     #error Cannot find a type with sizeof() == 4
70 #  endif
71 # endif
72 #endif /* NEED_TYPEDEFS */
73
74 #ifdef HAVE_UNISTD_H
75 # include <unistd.h>
76 #endif
77
78 #ifdef HAVE_STDLIB_H
79 # include <stdlib.h>
80 #endif
81
82 #include <stdio.h>
83 #include <errno.h>
84
85 #ifndef HAVE_MEMMOVE
86 #define memmove(x, y, z) bcopy(y, x, z)
87 #endif
88
89 #if TIME_WITH_SYS_TIME
90 # include <sys/time.h>
91 # include <time.h>
92 #else
93 # if HAVE_SYS_TIME_H
94 #  include <sys/time.h>
95 # else
96 #  include <time.h>
97 # endif
98 #endif
99
100 #ifdef HAVE_STRING_H
101 # include <string.h>
102 #else
103 # include <strings.h>
104 #endif
105
106 #ifndef _WIN32
107 #include <sys/uio.h>
108 #endif
109
110 #ifndef _P
111 #ifndef NO_PROTOTYPES
112 #  define   _P(x)   x
113 #else
114 #  define   _P(x)   ()
115 #endif
116 #endif
117
118 #ifndef _WIN32
119 #include <netinet/in.h>
120 #include <arpa/inet.h>
121 #endif
122
123 #ifdef GETTIMEOFDAY_ONE_ARG
124 #define gettimeofday(x, y) gettimeofday(x)
125 #endif
126
127 /* Systems lacking strdup() definition in <string.h>. */
128 #if defined(ultrix)
129 char *strdup _P((const char *));
130 #endif
131
132 /* Systems lacking malloc() definition in <stdlib.h>. */
133 #if defined(ultrix) || defined(hcx)
134 void *malloc _P((size_t arg));
135 void free _P((void *ptr));
136 #endif
137
138 #ifndef HAVE_INET_ATON
139 int inet_aton _P((const char *cp, struct in_addr *ia));
140 #endif
141
142 #include <fcntl.h>
143 #ifndef NO_UNIX_SOCKETS
144 #include <sys/un.h>
145 #endif
146 #include <signal.h>
147 #ifdef HAVE_SYS_SIGNAL_H
148 # include <sys/signal.h>
149 #endif
150 #ifndef _WIN32
151 #include <sys/socket.h>
152 #endif
153
154 #if defined(HAVE_SYS_IOCTL_H)
155 # include <sys/ioctl.h>
156 #endif
157
158 #ifdef HAVE_SYS_SELECT_H
159 # include <sys/select.h>
160 #endif
161
162 #ifdef HAVE_SYS_WAIT_H
163 # include <sys/wait.h>
164 #endif
165
166 #ifdef HAVE_SYS_FILIO_H
167 # include <sys/filio.h>
168 #endif
169
170 #ifdef USE_PPP
171 #include <ppp/slirppp.h>
172 #endif
173
174 #ifdef __STDC__
175 #include <stdarg.h>
176 #else
177 #include <varargs.h>
178 #endif
179
180 #include <sys/stat.h>
181
182 /* Avoid conflicting with the libc insque() and remque(), which
183    have different prototypes. */
184 #define insque slirp_insque
185 #define remque slirp_remque
186
187 #ifdef HAVE_SYS_STROPTS_H
188 #include <sys/stropts.h>
189 #endif
190
191 #include "debug.h"
192
193 #include "ip.h"
194 #include "tcp.h"
195 #include "tcp_timer.h"
196 #include "tcp_var.h"
197 #include "tcpip.h"
198 #include "udp.h"
199 #include "icmp_var.h"
200 #include "mbuf.h"
201 #include "sbuf.h"
202 #include "socket.h"
203 #include "if.h"
204 #include "main.h"
205 #include "misc.h"
206 #include "ctl.h"
207 #ifdef USE_PPP
208 #include "ppp/pppd.h"
209 #include "ppp/ppp.h"
210 #endif
211
212 #include "bootp.h"
213 #include "tftp.h"
214 #include "libslirp.h"
215
216 extern struct ttys *ttys_unit[MAX_INTERFACES];
217
218 #ifndef NULL
219 #define NULL (void *)0
220 #endif
221
222 #ifndef FULL_BOLT
223 void if_start _P((void));
224 #else
225 void if_start _P((struct ttys *));
226 #endif
227
228 #ifdef BAD_SPRINTF
229 # define vsprintf vsprintf_len
230 # define sprintf sprintf_len
231  extern int vsprintf_len _P((char *, const char *, va_list));
232  extern int sprintf_len _P((char *, const char *, ...));
233 #endif
234
235 #ifdef DECLARE_SPRINTF
236 # ifndef BAD_SPRINTF
237  extern int vsprintf _P((char *, const char *, va_list));
238 # endif
239  extern int vfprintf _P((FILE *, const char *, va_list));
240 #endif
241
242 #ifndef HAVE_STRERROR
243  extern char *strerror _P((int error));
244 #endif
245
246 #ifndef HAVE_INDEX
247  char *index _P((const char *, int));
248 #endif
249
250 #ifndef HAVE_GETHOSTID
251  long gethostid _P((void));
252 #endif
253
254 void lprint _P((const char *, ...));
255
256 extern int do_echo;
257
258 #if SIZEOF_CHAR_P == 4
259 # define insque_32 insque
260 # define remque_32 remque
261 #else
262  inline void insque_32 _P((void *, void *));
263  inline void remque_32 _P((void *));
264 #endif
265
266 #ifndef _WIN32
267 #include <netdb.h>
268 #endif
269
270 #define DEFAULT_BAUD 115200
271
272 /* cksum.c */
273 int cksum(struct mbuf *m, int len);
274
275 /* if.c */
276 void if_init _P((void));
277 void if_output _P((struct socket *, struct mbuf *));
278
279 /* ip_input.c */
280 void ip_init _P((void));
281 void ip_input _P((struct mbuf *));
282 struct ip * ip_reass _P((register struct ipasfrag *, register struct ipq *));
283 void ip_freef _P((struct ipq *));
284 void ip_enq _P((register struct ipasfrag *, register struct ipasfrag *));
285 void ip_deq _P((register struct ipasfrag *));
286 void ip_slowtimo _P((void));
287 void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
288
289 /* ip_output.c */
290 int ip_output _P((struct socket *, struct mbuf *));
291
292 /* tcp_input.c */
293 int tcp_reass _P((register struct tcpcb *, register struct tcpiphdr *, struct mbuf *));
294 void tcp_input _P((register struct mbuf *, int, struct socket *));
295 void tcp_dooptions _P((struct tcpcb *, u_char *, int, struct tcpiphdr *));
296 void tcp_xmit_timer _P((register struct tcpcb *, int));
297 int tcp_mss _P((register struct tcpcb *, u_int));
298
299 /* tcp_output.c */
300 int tcp_output _P((register struct tcpcb *));
301 void tcp_setpersist _P((register struct tcpcb *));
302
303 /* tcp_subr.c */
304 void tcp_init _P((void));
305 void tcp_template _P((struct tcpcb *));
306 void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
307 struct tcpcb * tcp_newtcpcb _P((struct socket *));
308 struct tcpcb * tcp_close _P((register struct tcpcb *));
309 void tcp_drain _P((void));
310 void tcp_sockclosed _P((struct tcpcb *));
311 int tcp_fconnect _P((struct socket *));
312 void tcp_connect _P((struct socket *));
313 int tcp_attach _P((struct socket *));
314 u_int8_t tcp_tos _P((struct socket *));
315 int tcp_emu _P((struct socket *, struct mbuf *));
316 int tcp_ctl _P((struct socket *));
317 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
318
319 #ifdef USE_PPP
320 #define MIN_MRU MINMRU
321 #define MAX_MRU MAXMRU
322 #else
323 #define MIN_MRU 128
324 #define MAX_MRU 16384
325 #endif
326
327 #ifndef _WIN32
328 #define min(x,y) ((x) < (y) ? (x) : (y))
329 #define max(x,y) ((x) > (y) ? (x) : (y))
330 #endif
331
332 #ifdef _WIN32
333 #define errno (WSAGetLastError())
334 #endif
335
336 #endif