VirtualBox

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

Last change on this file since 28172 was 28172, checked in by vboxsync, 15 years ago

NAT: win build fix.

  • Property svn:eol-style set to native
File size: 9.9 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>
8# include <ws2tcpip.h>
9typedef int socklen_t;
10#endif
11#ifdef RT_OS_OS2 /* temporary workaround, see ticket #127 */
12# define mbstat mbstat_os2
13# include <sys/socket.h>
14# undef mbstat
15typedef int socklen_t;
16#endif
17
18#define CONFIG_QEMU
19
20#ifdef DEBUG
21# undef DEBUG
22# define DEBUG 1
23#endif
24
25#ifndef CONFIG_QEMU
26# include "version.h"
27#endif
28#define LOG_GROUP LOG_GROUP_DRV_NAT
29#include <VBox/log.h>
30#include <iprt/mem.h>
31#ifdef RT_OS_WINDOWS
32# include <windows.h>
33# include <io.h>
34#endif
35#include <iprt/asm.h>
36#include <iprt/assert.h>
37#include <iprt/string.h>
38#include <iprt/dir.h>
39#include <iprt/rand.h>
40#include <VBox/types.h>
41
42#undef malloc
43#define malloc dont_use_malloc
44#undef free
45#define free dont_use_free
46#undef realloc
47#define realloc dont_use_realloc
48#undef strdup
49#define strdup dont_use_strdup
50
51#include "slirp_config.h"
52
53#ifdef RT_OS_WINDOWS
54
55# ifndef _MSC_VER
56# include <inttypes.h>
57# endif
58
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
70typedef uint8_t u_int8_t;
71typedef uint16_t u_int16_t;
72typedef uint32_t u_int32_t;
73
74#else /* !RT_OS_WINDOWS */
75
76# define ioctlsocket ioctl
77# define closesocket(s) close(s)
78# define O_BINARY 0
79
80#endif /* !RT_OS_WINDOWS */
81
82#if defined(RT_OS_WINDOWS) || defined (RT_OS_SOLARIS)
83typedef uint64_t u_int64_t;
84typedef char *caddr_t;
85#endif
86
87#include <sys/types.h>
88#ifdef HAVE_SYS_BITYPES_H
89# include <sys/bitypes.h>
90#endif
91
92#ifdef _MSC_VER
93# include <time.h>
94#else /* !_MSC_VER */
95# include <sys/time.h>
96#endif /* !_MSC_VER */
97
98#ifdef NEED_TYPEDEFS
99typedef char int8_t;
100typedef unsigned char u_int8_t;
101
102# if SIZEOF_SHORT == 2
103 typedef short int16_t;
104 typedef unsigned short u_int16_t;
105# else
106# if SIZEOF_INT == 2
107 typedef int int16_t;
108 typedef unsigned int u_int16_t;
109# else
110 #error Cannot find a type with sizeof() == 2
111# endif
112# endif
113
114# if SIZEOF_SHORT == 4
115 typedef short int32_t;
116 typedef unsigned short u_int32_t;
117# else
118# if SIZEOF_INT == 4
119 typedef int int32_t;
120 typedef unsigned int u_int32_t;
121# else
122 #error Cannot find a type with sizeof() == 4
123# endif
124# endif
125#endif /* NEED_TYPEDEFS */
126
127#ifdef HAVE_UNISTD_H
128# include <unistd.h>
129#endif
130
131#ifdef HAVE_STDLIB_H
132# include <stdlib.h>
133#endif
134
135#include <errno.h>
136
137
138#ifndef HAVE_MEMMOVE
139# define memmove(x, y, z) bcopy(y, x, z)
140#endif
141
142#if TIME_WITH_SYS_TIME
143# include <sys/time.h>
144# include <time.h>
145#else
146# if HAVE_SYS_TIME_H
147# include <sys/time.h>
148# else
149# include <time.h>
150# endif
151#endif
152
153#ifdef HAVE_STRING_H
154# include <string.h>
155#else
156# include <strings.h>
157#endif
158
159#ifndef RT_OS_WINDOWS
160# include <sys/uio.h>
161#endif
162
163#ifndef RT_OS_WINDOWS
164# include <netinet/in.h>
165# include <arpa/inet.h>
166#endif
167
168#ifdef GETTIMEOFDAY_ONE_ARG
169# define gettimeofday(x, y) gettimeofday(x)
170#endif
171
172#ifndef HAVE_INET_ATON
173int inet_aton (const char *cp, struct in_addr *ia);
174#endif
175
176#include <fcntl.h>
177#ifndef NO_UNIX_SOCKETS
178# include <sys/un.h>
179#endif
180#include <signal.h>
181#ifdef HAVE_SYS_SIGNAL_H
182# include <sys/signal.h>
183#endif
184#ifndef RT_OS_WINDOWS
185# include <sys/socket.h>
186#endif
187
188#if defined(HAVE_SYS_IOCTL_H)
189# include <sys/ioctl.h>
190#endif
191
192#ifdef HAVE_SYS_SELECT_H
193# include <sys/select.h>
194#endif
195
196#ifdef HAVE_SYS_WAIT_H
197# include <sys/wait.h>
198#endif
199
200#ifdef HAVE_SYS_FILIO_H
201# include <sys/filio.h>
202#endif
203
204#if defined(__STDC__) || defined(_MSC_VER)
205# include <stdarg.h>
206#else
207# include <varargs.h>
208#endif
209
210#include <sys/stat.h>
211
212/* Avoid conflicting with the libc insque() and remque(), which
213 * have different prototypes. */
214#define insque slirp_insque
215#define remque slirp_remque
216
217#ifdef HAVE_SYS_STROPTS_H
218# include <sys/stropts.h>
219#endif
220
221#include "libslirp.h"
222
223#include "debug.h"
224
225#include "ip.h"
226#include "tcp.h"
227#include "tcp_timer.h"
228#include "tcp_var.h"
229#include "tcpip.h"
230#include "udp.h"
231#include "icmp_var.h"
232#include "mbuf.h"
233#include "sbuf.h"
234#include "socket.h"
235#include "if.h"
236#include "main.h"
237#include "misc.h"
238#include "ctl.h"
239#include "bootp.h"
240#include "tftp.h"
241
242#include "slirp_state.h"
243
244#undef PVM /* XXX Mac OS X hack */
245
246#ifndef NULL
247# define NULL (void *)0
248#endif
249
250void if_start (PNATState);
251
252#ifndef HAVE_INDEX
253 char *index (const char *, int);
254#endif
255
256#ifndef HAVE_GETHOSTID
257 long gethostid (void);
258#endif
259
260#ifndef RT_OS_WINDOWS
261#include <netdb.h>
262#endif
263
264#include "dnsproxy/dnsproxy.h"
265
266#define DEFAULT_BAUD 115200
267
268int get_dns_addr(PNATState pData, struct in_addr *pdns_addr);
269
270/* cksum.c */
271#ifndef VBOX_WITH_SLIRP_BSD_MBUF
272int cksum(struct mbuf *m, int len);
273#else
274typedef uint16_t u_short;
275typedef unsigned int u_int;
276#include "in_cksum.h"
277#endif
278
279/* if.c */
280void if_init (PNATState);
281void if_output (PNATState, struct socket *, struct mbuf *);
282
283/* ip_input.c */
284void ip_init (PNATState);
285void ip_input (PNATState, struct mbuf *);
286struct mbuf * ip_reass (PNATState, register struct mbuf *);
287void ip_freef (PNATState, struct ipqhead *, struct ipq_t *);
288void ip_slowtimo (PNATState);
289void ip_stripoptions (register struct mbuf *, struct mbuf *);
290
291/* ip_output.c */
292int ip_output (PNATState, struct socket *, struct mbuf *);
293int ip_output0 (PNATState, struct socket *, struct mbuf *, int urg);
294
295/* tcp_input.c */
296int tcp_reass (PNATState, struct tcpcb *, struct tcphdr *, int *, struct mbuf *);
297void tcp_input (PNATState, register struct mbuf *, int, struct socket *);
298void tcp_dooptions (PNATState, struct tcpcb *, u_char *, int, struct tcpiphdr *);
299void tcp_xmit_timer (PNATState, register struct tcpcb *, int);
300int tcp_mss (PNATState, register struct tcpcb *, u_int);
301
302/* tcp_output.c */
303int tcp_output (PNATState, register struct tcpcb *);
304void tcp_setpersist (register struct tcpcb *);
305
306/* tcp_subr.c */
307void tcp_init (PNATState);
308void tcp_template (struct tcpcb *);
309void tcp_respond (PNATState, struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int);
310struct tcpcb * tcp_newtcpcb (PNATState, struct socket *);
311struct tcpcb * tcp_close (PNATState, register struct tcpcb *);
312void tcp_drain (void);
313void tcp_sockclosed (PNATState, struct tcpcb *);
314int tcp_fconnect (PNATState, struct socket *);
315void tcp_connect (PNATState, struct socket *);
316int tcp_attach (PNATState, struct socket *);
317u_int8_t tcp_tos (struct socket *);
318int tcp_emu (PNATState, struct socket *, struct mbuf *);
319int tcp_ctl (PNATState, struct socket *);
320struct tcpcb *tcp_drop(PNATState, struct tcpcb *tp, int err);
321
322/*slirp.c*/
323void slirp_arp_who_has(PNATState pData, uint32_t dst);
324int slirp_arp_cache_update(PNATState pData, uint32_t dst, const uint8_t *mac);
325void slirp_arp_cache_add(PNATState pData, uint32_t ip, const uint8_t *ether);
326int slirp_arp_cache_update_or_add(PNATState pData, uint32_t dst, const uint8_t *mac);
327#define MIN_MRU 128
328#define MAX_MRU 16384
329
330#ifndef RT_OS_WINDOWS
331# define min(x, y) ((x) < (y) ? (x) : (y))
332# define max(x, y) ((x) > (y) ? (x) : (y))
333#endif
334
335#ifdef RT_OS_WINDOWS
336# undef errno
337# if 0 /* debugging */
338int errno_func(const char *file, int line);
339# define errno (errno_func(__FILE__, __LINE__))
340# else
341# define errno (WSAGetLastError())
342# endif
343#endif
344
345# define ETH_ALEN 6
346# define ETH_HLEN 14
347
348# define ARPOP_REQUEST 1 /* ARP request */
349# define ARPOP_REPLY 2 /* ARP reply */
350
351struct ethhdr
352{
353 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
354 unsigned char h_source[ETH_ALEN]; /* source ether addr */
355 unsigned short h_proto; /* packet type ID field */
356};
357AssertCompileSize(struct ethhdr, 14);
358
359/*
360 * (vvl) externing of sscanf.
361 */
362int sscanf(const char *s, const char *format, ...);
363
364#if defined(VBOX_SLIRP_ALIAS) || defined(VBOX_SLIRP_BSD)
365
366# define ip_next(ip) (void *)((uint8_t *)(ip) + ((ip)->ip_hl << 2))
367# define udp_next(udp) (void *)((uint8_t *)&((struct udphdr *)(udp))[1] )
368# define bcopy(src, dst, len) memcpy((dst), (src), (len))
369# define bcmp(a1, a2, len) memcmp((a1), (a2), (len))
370# define NO_FW_PUNCH
371
372# ifdef alias_addr
373# ifndef VBOX_SLIRP_BSD
374# error alias_addr has already defined!!!
375# else
376# undef alias_addr
377# endif
378# endif
379
380# define arc4random() RTRandU32()
381# undef malloc
382# undef calloc
383# undef free
384# define malloc(x) RTMemAlloc((x))
385# define calloc(x, n) RTMemAllocZ((x)*(n))
386# define free(x) RTMemFree((x))
387# ifndef __unused
388# define __unused
389# endif
390
391# define strncasecmp RTStrNICmp
392# define stderr NULL
393# define stdout NULL
394
395# ifdef DEBUG
396# define LIBALIAS_DEBUG
397# endif
398
399# define fflush(x) do{} while(0)
400# include "ext.h"
401#endif /*VBOX_SLIRP_ALIAS*/
402
403#ifdef VBOX_WITH_SLIRP_BSD_MBUF
404/**
405 * @todo might be useful to make it configurable, especially in terms of Intnet behind NAT
406 */
407# define maxusers 32
408# define max_protohdr 0
409/**
410 * @todo (vvl) for now ignore these values, later perhaps initialize tuning parameters
411 */
412# define TUNABLE_INT_FETCH(name, pval) do { } while (0)
413# define SYSCTL_PROC(a0, a1, a2, a3, a4, a5, a6, a7, a8) const int dummy_ ## a6 = 0
414# define SYSCTL_STRUCT(a0, a1, a2, a3, a4, a5, a6) const int dummy_ ## a5 = 0
415# define SYSINIT(a0, a1, a2, a3, a4) const int dummy_ ## a3 = 0
416# define sysctl_handle_int(a0, a1, a2, a3) 0
417# define EVENTHANDLER_INVOKE(a) do{}while(0)
418# define EVENTHANDLER_REGISTER(a0, a1, a2, a3) do{}while(0)
419# define KASSERT AssertMsg
420
421struct dummy_req
422{
423 void *newptr;
424};
425
426#define SYSCTL_HANDLER_ARGS PNATState pData, void *oidp, struct dummy_req *req
427
428void mbuf_init(void *);
429# define cksum(m, len) in_cksum_skip((m), (len), 0)
430#endif
431
432int ftp_alias_load(PNATState);
433int ftp_alias_unload(PNATState);
434int nbt_alias_load(PNATState);
435int nbt_alias_unload(PNATState);
436int dns_alias_load(PNATState);
437int dns_alias_unload(PNATState);
438int slirp_arp_lookup_ip_by_ether(PNATState, const uint8_t *, uint32_t *);
439int slirp_arp_lookup_ether_by_ip(PNATState, uint32_t, uint8_t *);
440#endif
441
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