VirtualBox

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

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

NAT/libalias: logging enchancements

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