VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/slirp.h@ 14329

Last change on this file since 14329 was 14275, checked in by vboxsync, 16 years ago

TCP reassembling (compilable, but not working version)

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette