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