VirtualBox

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

Last change on this file since 19846 was 19839, checked in by vboxsync, 16 years ago

NAT: Slirp don't use ether address of guest anymore
instead it calculates ethernet address of destination
with lookup operation. Currently it's very simple looks
over send addresses via dhcp or assume destination in outer
network and gets Slirp's ethernet address.

  • Property svn:eol-style set to native
File size: 8.2 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/assert.h>
36#include <iprt/string.h>
37#include <iprt/dir.h>
38#include <VBox/types.h>
39
40#undef malloc
41#define malloc dont_use_malloc
42#undef free
43#define free dont_use_free
44#undef realloc
45#define realloc dont_use_realloc
46#undef strdup
47#define strdup dont_use_strdup
48
49#include "slirp_config.h"
50
51#ifdef RT_OS_WINDOWS
52
53# ifndef _MSC_VER
54# include <inttypes.h>
55# endif
56
57typedef uint8_t u_int8_t;
58typedef uint16_t u_int16_t;
59typedef uint32_t u_int32_t;
60typedef uint64_t u_int64_t;
61typedef char *caddr_t;
62
63# include <sys/timeb.h>
64# include <iphlpapi.h>
65
66# define EWOULDBLOCK WSAEWOULDBLOCK
67# define EINPROGRESS WSAEINPROGRESS
68# define ENOTCONN WSAENOTCONN
69# define EHOSTUNREACH WSAEHOSTUNREACH
70# define ENETUNREACH WSAENETUNREACH
71# define ECONNREFUSED WSAECONNREFUSED
72
73#else /* !RT_OS_WINDOWS */
74
75# define ioctlsocket ioctl
76# define closesocket(s) close(s)
77# define O_BINARY 0
78
79#endif /* !RT_OS_WINDOWS */
80
81#include <sys/types.h>
82#ifdef HAVE_SYS_BITYPES_H
83# include <sys/bitypes.h>
84#endif
85
86#ifdef _MSC_VER
87# include <time.h>
88#else /* !_MSC_VER */
89# include <sys/time.h>
90#endif /* !_MSC_VER */
91
92#ifdef NEED_TYPEDEFS
93typedef char int8_t;
94typedef unsigned char u_int8_t;
95
96# if SIZEOF_SHORT == 2
97 typedef short int16_t;
98 typedef unsigned short u_int16_t;
99# else
100# if SIZEOF_INT == 2
101 typedef int int16_t;
102 typedef unsigned int u_int16_t;
103# else
104 #error Cannot find a type with sizeof() == 2
105# endif
106# endif
107
108# if SIZEOF_SHORT == 4
109 typedef short int32_t;
110 typedef unsigned short u_int32_t;
111# else
112# if SIZEOF_INT == 4
113 typedef int int32_t;
114 typedef unsigned int u_int32_t;
115# else
116 #error Cannot find a type with sizeof() == 4
117# endif
118# endif
119#endif /* NEED_TYPEDEFS */
120
121#ifdef HAVE_UNISTD_H
122# include <unistd.h>
123#endif
124
125#ifdef HAVE_STDLIB_H
126# include <stdlib.h>
127#endif
128
129#include <stdio.h>
130#include <errno.h>
131
132#ifndef HAVE_MEMMOVE
133# define memmove(x, y, z) bcopy(y, x, z)
134#endif
135
136#if TIME_WITH_SYS_TIME
137# include <sys/time.h>
138# include <time.h>
139#else
140# if HAVE_SYS_TIME_H
141# include <sys/time.h>
142# else
143# include <time.h>
144# endif
145#endif
146
147#ifdef HAVE_STRING_H
148# include <string.h>
149#else
150# include <strings.h>
151#endif
152
153#ifndef RT_OS_WINDOWS
154# include <sys/uio.h>
155#endif
156
157#ifndef _P
158#ifndef NO_PROTOTYPES
159# define _P(x) x
160#else
161# define _P(x) ()
162#endif
163#endif
164
165#ifndef RT_OS_WINDOWS
166# include <netinet/in.h>
167# include <arpa/inet.h>
168#endif
169
170#ifdef GETTIMEOFDAY_ONE_ARG
171# define gettimeofday(x, y) gettimeofday(x)
172#endif
173
174#ifndef HAVE_INET_ATON
175int inet_aton _P((const char *cp, struct in_addr *ia));
176#endif
177
178#include <fcntl.h>
179#ifndef NO_UNIX_SOCKETS
180# include <sys/un.h>
181#endif
182#include <signal.h>
183#ifdef HAVE_SYS_SIGNAL_H
184# include <sys/signal.h>
185#endif
186#ifndef RT_OS_WINDOWS
187# include <sys/socket.h>
188#endif
189
190#if defined(HAVE_SYS_IOCTL_H)
191# include <sys/ioctl.h>
192#endif
193
194#ifdef HAVE_SYS_SELECT_H
195# include <sys/select.h>
196#endif
197
198#ifdef HAVE_SYS_WAIT_H
199# include <sys/wait.h>
200#endif
201
202#ifdef HAVE_SYS_FILIO_H
203# include <sys/filio.h>
204#endif
205
206#if defined(__STDC__) || defined(_MSC_VER)
207# include <stdarg.h>
208#else
209# include <varargs.h>
210#endif
211
212#include <sys/stat.h>
213
214/* Avoid conflicting with the libc insque() and remque(), which
215 * have different prototypes. */
216#define insque slirp_insque
217#define remque slirp_remque
218
219#ifdef HAVE_SYS_STROPTS_H
220# include <sys/stropts.h>
221#endif
222
223#include "libslirp.h"
224
225#include "debug.h"
226
227#include "ip.h"
228#include "tcp.h"
229#include "tcp_timer.h"
230#include "tcp_var.h"
231#include "tcpip.h"
232#include "udp.h"
233#include "icmp_var.h"
234#include "mbuf.h"
235#include "sbuf.h"
236#include "socket.h"
237#include "if.h"
238#include "main.h"
239#include "misc.h"
240#include "ctl.h"
241#include "bootp.h"
242#include "tftp.h"
243
244#include "slirp_state.h"
245
246#undef PVM /* XXX Mac OS X hack */
247
248#ifndef NULL
249# define NULL (void *)0
250#endif
251
252void if_start _P((PNATState));
253
254#ifndef HAVE_INDEX
255 char *index _P((const char *, int));
256#endif
257
258#ifndef HAVE_GETHOSTID
259 long gethostid _P((void));
260#endif
261
262#if SIZEOF_CHAR_P == 4
263# define insque_32 insque
264# define remque_32 remque
265#else
266extern void insque_32 _P((PNATState, void *, void *));
267extern void remque_32 _P((PNATState, void *));
268#endif
269
270#ifndef RT_OS_WINDOWS
271#include <netdb.h>
272#endif
273
274#ifdef VBOX_WITH_SLIRP_DNS_PROXY
275# include "dnsproxy/dnsproxy.h"
276#endif
277
278#define DEFAULT_BAUD 115200
279
280int get_dns_addr(PNATState pData, struct in_addr *pdns_addr);
281
282/* cksum.c */
283int cksum(struct mbuf *m, int len);
284
285/* if.c */
286void if_init _P((PNATState));
287void if_output _P((PNATState, struct socket *, struct mbuf *));
288
289/* ip_input.c */
290void ip_init _P((PNATState));
291void ip_input _P((PNATState, struct mbuf *));
292struct mbuf * ip_reass _P((PNATState, register struct mbuf *));
293void ip_freef _P((PNATState, struct ipqhead *, struct ipq_t *));
294void ip_slowtimo _P((PNATState));
295void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
296
297/* ip_output.c */
298int ip_output _P((PNATState, struct socket *, struct mbuf *));
299
300/* tcp_input.c */
301int tcp_reass _P((PNATState, struct tcpcb *, struct tcphdr *, int *, struct mbuf *));
302void tcp_input _P((PNATState, register struct mbuf *, int, struct socket *));
303void tcp_dooptions _P((PNATState, struct tcpcb *, u_char *, int, struct tcpiphdr *));
304void tcp_xmit_timer _P((PNATState, register struct tcpcb *, int));
305int tcp_mss _P((PNATState, register struct tcpcb *, u_int));
306
307/* tcp_output.c */
308int tcp_output _P((PNATState, register struct tcpcb *));
309void tcp_setpersist _P((register struct tcpcb *));
310
311/* tcp_subr.c */
312void tcp_init _P((PNATState));
313void tcp_template _P((struct tcpcb *));
314void tcp_respond _P((PNATState, struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
315struct tcpcb * tcp_newtcpcb _P((PNATState, struct socket *));
316struct tcpcb * tcp_close _P((PNATState, register struct tcpcb *));
317void tcp_drain _P((void));
318void tcp_sockclosed _P((PNATState, struct tcpcb *));
319int tcp_fconnect _P((PNATState, struct socket *));
320void tcp_connect _P((PNATState, struct socket *));
321int tcp_attach _P((PNATState, struct socket *));
322u_int8_t tcp_tos _P((struct socket *));
323int tcp_emu _P((PNATState, struct socket *, struct mbuf *));
324int tcp_ctl _P((PNATState, struct socket *));
325struct tcpcb *tcp_drop(PNATState, struct tcpcb *tp, int err);
326
327uint16_t slirp_get_service(int proto, uint16_t dport, uint16_t sport);
328
329#define MIN_MRU 128
330#define MAX_MRU 16384
331
332#ifndef RT_OS_WINDOWS
333# define min(x, y) ((x) < (y) ? (x) : (y))
334# define max(x, y) ((x) > (y) ? (x) : (y))
335#endif
336
337#ifdef RT_OS_WINDOWS
338# undef errno
339# if 0 /* debugging */
340int errno_func(const char *file, int line);
341# define errno (errno_func(__FILE__, __LINE__))
342# else
343# define errno (WSAGetLastError())
344# endif
345#endif
346
347#ifndef VBOX_WITH_MULTI_DNS
348#define DO_ALIAS(paddr) \
349do { \
350 if ((paddr)->s_addr == dns_addr.s_addr) \
351 { \
352 (paddr)->s_addr = htonl(ntohl(special_addr.s_addr) | CTL_DNS); \
353 } \
354} while(0)
355#else
356#define DO_ALIAS(paddr) do {} while (0)
357#endif
358
359
360# ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
361# define ETH_ALEN 6
362# define ETH_HLEN 14
363
364# define ARPOP_REQUEST 1 /* ARP request */
365# define ARPOP_REPLY 2 /* ARP reply */
366
367struct ethhdr
368{
369 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
370 unsigned char h_source[ETH_ALEN]; /* source ether addr */
371 unsigned short h_proto; /* packet type ID field */
372};
373AssertCompileSize(struct ethhdr, 14);
374# endif
375#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