VirtualBox

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

最後變更 在這個檔案從15035是 14964,由 vboxsync 提交於 16 年 前

slirp: code cosmetics for better readability (no semantics change)

  • 屬性 svn:eol-style 設為 native
檔案大小: 7.9 KB
 
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 RT_OS_WINDOWS
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
70#else /* !RT_OS_WINDOWS */
71
72# define ioctlsocket ioctl
73# define closesocket(s) close(s)
74# define O_BINARY 0
75
76#endif /* !RT_OS_WINDOWS */
77
78#include <sys/types.h>
79#ifdef HAVE_SYS_BITYPES_H
80# include <sys/bitypes.h>
81#endif
82
83#ifdef _MSC_VER
84# include <time.h>
85#else /* !_MSC_VER */
86# include <sys/time.h>
87#endif /* !_MSC_VER */
88
89#ifdef NEED_TYPEDEFS
90typedef char int8_t;
91typedef unsigned char u_int8_t;
92
93# if SIZEOF_SHORT == 2
94 typedef short int16_t;
95 typedef unsigned short u_int16_t;
96# else
97# if SIZEOF_INT == 2
98 typedef int int16_t;
99 typedef unsigned int u_int16_t;
100# else
101 #error Cannot find a type with sizeof() == 2
102# endif
103# endif
104
105# if SIZEOF_SHORT == 4
106 typedef short int32_t;
107 typedef unsigned short u_int32_t;
108# else
109# if SIZEOF_INT == 4
110 typedef int int32_t;
111 typedef unsigned int u_int32_t;
112# else
113 #error Cannot find a type with sizeof() == 4
114# endif
115# endif
116#endif /* NEED_TYPEDEFS */
117
118#ifdef HAVE_UNISTD_H
119# include <unistd.h>
120#endif
121
122#ifdef HAVE_STDLIB_H
123# include <stdlib.h>
124#endif
125
126#include <stdio.h>
127#include <errno.h>
128
129#ifndef HAVE_MEMMOVE
130# define memmove(x, y, z) bcopy(y, x, z)
131#endif
132
133#if TIME_WITH_SYS_TIME
134# include <sys/time.h>
135# include <time.h>
136#else
137# if HAVE_SYS_TIME_H
138# include <sys/time.h>
139# else
140# include <time.h>
141# endif
142#endif
143
144#ifdef HAVE_STRING_H
145# include <string.h>
146#else
147# include <strings.h>
148#endif
149
150#ifndef RT_OS_WINDOWS
151# include <sys/uio.h>
152#endif
153
154#ifndef _P
155#ifndef NO_PROTOTYPES
156# define _P(x) x
157#else
158# define _P(x) ()
159#endif
160#endif
161
162#ifndef RT_OS_WINDOWS
163# include <netinet/in.h>
164# include <arpa/inet.h>
165#endif
166
167#ifdef GETTIMEOFDAY_ONE_ARG
168# define gettimeofday(x, y) gettimeofday(x)
169#endif
170
171/* Systems lacking strdup() definition in <string.h>. */
172#if defined(ultrix)
173char *strdup _P((const char *));
174#endif
175
176/* Systems lacking malloc() definition in <stdlib.h>. */
177#if defined(ultrix) || defined(hcx)
178void *malloc _P((size_t arg));
179void free _P((void *ptr));
180#endif
181
182#ifndef HAVE_INET_ATON
183int inet_aton _P((const char *cp, struct in_addr *ia));
184#endif
185
186#include <fcntl.h>
187#ifndef NO_UNIX_SOCKETS
188# include <sys/un.h>
189#endif
190#include <signal.h>
191#ifdef HAVE_SYS_SIGNAL_H
192# include <sys/signal.h>
193#endif
194#ifndef RT_OS_WINDOWS
195# include <sys/socket.h>
196#endif
197
198#if defined(HAVE_SYS_IOCTL_H)
199# include <sys/ioctl.h>
200#endif
201
202#ifdef HAVE_SYS_SELECT_H
203# include <sys/select.h>
204#endif
205
206#ifdef HAVE_SYS_WAIT_H
207# include <sys/wait.h>
208#endif
209
210#ifdef HAVE_SYS_FILIO_H
211# include <sys/filio.h>
212#endif
213
214#if defined(__STDC__) || defined(_MSC_VER)
215# include <stdarg.h>
216#else
217# include <varargs.h>
218#endif
219
220#include <sys/stat.h>
221
222/* Avoid conflicting with the libc insque() and remque(), which
223 * have different prototypes. */
224#define insque slirp_insque
225#define remque slirp_remque
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#include "bootp.h"
250#include "tftp.h"
251
252#include "slirp_state.h"
253
254#undef PVM /* XXX Mac OS X hack */
255
256#ifndef NULL
257# define NULL (void *)0
258#endif
259
260void if_start _P((PNATState));
261
262#ifndef HAVE_INDEX
263 char *index _P((const char *, int));
264#endif
265
266#ifndef HAVE_GETHOSTID
267 long gethostid _P((void));
268#endif
269
270DECLINLINE(void) lprint (const char *pszFormat, ...)
271{
272#ifdef LOG_ENABLED
273 va_list args;
274 va_start(args, pszFormat);
275#if 1 /* nearly only for stats which we always want. */
276 RTLogPrintfV(pszFormat, args);
277#else
278 Log(("%N", pszFormat, &args));
279#endif
280 va_end(args);
281#endif
282}
283
284extern int do_echo;
285
286#if SIZEOF_CHAR_P == 4
287# define insque_32 insque
288# define remque_32 remque
289#else
290extern void insque_32 _P((PNATState, void *, void *));
291extern void remque_32 _P((PNATState, void *));
292#endif
293
294#ifndef RT_OS_WINDOWS
295#include <netdb.h>
296#endif
297
298#define DEFAULT_BAUD 115200
299
300int get_dns_addr(PNATState pData, struct in_addr *pdns_addr);
301
302/* cksum.c */
303int cksum(struct mbuf *m, int len);
304
305/* if.c */
306void if_init _P((PNATState));
307void if_output _P((PNATState, struct socket *, struct mbuf *));
308
309/* ip_input.c */
310void ip_init _P((PNATState));
311void ip_input _P((PNATState, struct mbuf *));
312#ifndef VBOX_WITH_BSD_REASS
313struct ip * ip_reass _P((PNATState, register struct ipasfrag *, register struct ipq_t *));
314void ip_freef _P((PNATState, struct ipq_t *));
315#else /* !VBOX_WITH_BSD_REASS */
316struct mbuf * ip_reass _P((PNATState, register struct mbuf *));
317void ip_freef _P((PNATState, struct ipqhead *, struct ipq_t *));
318#endif /* VBOX_WITH_BSD_REASS */
319void ip_enq _P((PNATState, register struct ipasfrag *, register struct ipasfrag *));
320void ip_deq _P((PNATState, register struct ipasfrag *));
321void ip_slowtimo _P((PNATState));
322void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
323
324/* ip_output.c */
325int ip_output _P((PNATState, struct socket *, struct mbuf *));
326
327/* tcp_input.c */
328#ifndef VBOX_WITH_BSD_REASS
329int tcp_reass _P((PNATState, register struct tcpcb *, register struct tcpiphdr *, struct mbuf *));
330#else /* !VBOX_WITH_BSD_REASS */
331int tcp_reass _P((PNATState, struct tcpcb *, struct tcphdr *, int *, struct mbuf *));
332#endif /* VBOX_WITH_BSD_REASS */
333void tcp_input _P((PNATState, register struct mbuf *, int, struct socket *));
334void tcp_dooptions _P((PNATState, struct tcpcb *, u_char *, int, struct tcpiphdr *));
335void tcp_xmit_timer _P((PNATState, register struct tcpcb *, int));
336int tcp_mss _P((PNATState, register struct tcpcb *, u_int));
337
338/* tcp_output.c */
339int tcp_output _P((PNATState, register struct tcpcb *));
340void tcp_setpersist _P((register struct tcpcb *));
341
342/* tcp_subr.c */
343void tcp_init _P((PNATState));
344void tcp_template _P((struct tcpcb *));
345void tcp_respond _P((PNATState, struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
346struct tcpcb * tcp_newtcpcb _P((PNATState, struct socket *));
347struct tcpcb * tcp_close _P((PNATState, register struct tcpcb *));
348void tcp_drain _P((void));
349void tcp_sockclosed _P((PNATState, struct tcpcb *));
350int tcp_fconnect _P((PNATState, struct socket *));
351void tcp_connect _P((PNATState, struct socket *));
352int tcp_attach _P((PNATState, struct socket *));
353u_int8_t tcp_tos _P((struct socket *));
354int tcp_emu _P((PNATState, struct socket *, struct mbuf *));
355int tcp_ctl _P((PNATState, struct socket *));
356struct tcpcb *tcp_drop(PNATState, struct tcpcb *tp, int err);
357
358#define MIN_MRU 128
359#define MAX_MRU 16384
360
361#ifndef RT_OS_WINDOWS
362# define min(x,y) ((x) < (y) ? (x) : (y))
363# define max(x,y) ((x) > (y) ? (x) : (y))
364#endif
365
366#ifdef RT_OS_WINDOWS
367# undef errno
368# define errno (WSAGetLastError())
369#endif
370
371#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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