VirtualBox

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

Last change on this file since 14925 was 14638, checked in by vboxsync, 16 years ago

NAT: some reformatting for better readability; merged VBOX_WITH_BSD_TCP_REASS with VBOX_WITH_BSD_REASS

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

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