root / slirp / slirp.h @ 0d62c4cf
History | View | Annotate | Download (6.2 kB)
1 |
#ifndef __COMMON_H__
|
---|---|
2 |
#define __COMMON_H__
|
3 |
|
4 |
//#define DEBUG 1
|
5 |
|
6 |
// Uncomment the following line to enable SLIRP statistics printing in Qemu
|
7 |
//#define LOG_ENABLED
|
8 |
|
9 |
#ifdef LOG_ENABLED
|
10 |
#define STAT(expr) expr
|
11 |
#else
|
12 |
#define STAT(expr) do { } while(0) |
13 |
#endif
|
14 |
|
15 |
#include "config-host.h" |
16 |
#include "slirp_config.h" |
17 |
|
18 |
#ifdef _WIN32
|
19 |
# include <inttypes.h> |
20 |
|
21 |
typedef uint8_t u_int8_t;
|
22 |
typedef uint16_t u_int16_t;
|
23 |
typedef uint32_t u_int32_t;
|
24 |
typedef uint64_t u_int64_t;
|
25 |
typedef char *caddr_t; |
26 |
|
27 |
# include <windows.h> |
28 |
# include <winsock2.h> |
29 |
# include <ws2tcpip.h> |
30 |
# include <sys/timeb.h> |
31 |
# include <iphlpapi.h> |
32 |
|
33 |
# define EWOULDBLOCK WSAEWOULDBLOCK
|
34 |
# define EINPROGRESS WSAEINPROGRESS
|
35 |
# define ENOTCONN WSAENOTCONN
|
36 |
# define EHOSTUNREACH WSAEHOSTUNREACH
|
37 |
# define ENETUNREACH WSAENETUNREACH
|
38 |
# define ECONNREFUSED WSAECONNREFUSED
|
39 |
#else
|
40 |
# define ioctlsocket ioctl
|
41 |
# define closesocket(s) close(s)
|
42 |
# define O_BINARY 0 |
43 |
#endif
|
44 |
|
45 |
#include <sys/types.h> |
46 |
#ifdef HAVE_SYS_BITYPES_H
|
47 |
# include <sys/bitypes.h> |
48 |
#endif
|
49 |
|
50 |
#include <sys/time.h> |
51 |
|
52 |
#ifdef NEED_TYPEDEFS
|
53 |
typedef char int8_t; |
54 |
typedef unsigned char u_int8_t; |
55 |
|
56 |
# if SIZEOF_SHORT == 2 |
57 |
typedef short int16_t; |
58 |
typedef unsigned short u_int16_t; |
59 |
# else
|
60 |
# if SIZEOF_INT == 2 |
61 |
typedef int int16_t; |
62 |
typedef unsigned int u_int16_t; |
63 |
# else
|
64 |
#error Cannot find a type with sizeof() == 2 |
65 |
# endif
|
66 |
# endif
|
67 |
|
68 |
# if SIZEOF_SHORT == 4 |
69 |
typedef short int32_t; |
70 |
typedef unsigned short u_int32_t; |
71 |
# else
|
72 |
# if SIZEOF_INT == 4 |
73 |
typedef int int32_t; |
74 |
typedef unsigned int u_int32_t; |
75 |
# else
|
76 |
#error Cannot find a type with sizeof() == 4 |
77 |
# endif
|
78 |
# endif
|
79 |
#endif /* NEED_TYPEDEFS */ |
80 |
|
81 |
#ifdef HAVE_UNISTD_H
|
82 |
# include <unistd.h> |
83 |
#endif
|
84 |
|
85 |
#ifdef HAVE_STDLIB_H
|
86 |
# include <stdlib.h> |
87 |
#endif
|
88 |
|
89 |
#include <stdio.h> |
90 |
#include <errno.h> |
91 |
|
92 |
#ifndef HAVE_MEMMOVE
|
93 |
#define memmove(x, y, z) bcopy(y, x, z)
|
94 |
#endif
|
95 |
|
96 |
#if TIME_WITH_SYS_TIME
|
97 |
# include <sys/time.h> |
98 |
# include <time.h> |
99 |
#else
|
100 |
# ifdef HAVE_SYS_TIME_H
|
101 |
# include <sys/time.h> |
102 |
# else
|
103 |
# include <time.h> |
104 |
# endif
|
105 |
#endif
|
106 |
|
107 |
#ifdef HAVE_STRING_H
|
108 |
# include <string.h> |
109 |
#else
|
110 |
# include <strings.h> |
111 |
#endif
|
112 |
|
113 |
#ifndef _WIN32
|
114 |
#include <sys/uio.h> |
115 |
#endif
|
116 |
|
117 |
#undef _P
|
118 |
#ifndef NO_PROTOTYPES
|
119 |
# define _P(x) x
|
120 |
#else
|
121 |
# define _P(x) ()
|
122 |
#endif
|
123 |
|
124 |
#ifndef _WIN32
|
125 |
#include <netinet/in.h> |
126 |
#include <arpa/inet.h> |
127 |
#endif
|
128 |
|
129 |
#ifdef GETTIMEOFDAY_ONE_ARG
|
130 |
#define gettimeofday(x, y) gettimeofday(x)
|
131 |
#endif
|
132 |
|
133 |
/* Systems lacking strdup() definition in <string.h>. */
|
134 |
#if defined(ultrix)
|
135 |
char *strdup _P((const char *)); |
136 |
#endif
|
137 |
|
138 |
/* Systems lacking malloc() definition in <stdlib.h>. */
|
139 |
#if defined(ultrix) || defined(hcx)
|
140 |
void *malloc _P((size_t arg));
|
141 |
void free _P((void *ptr)); |
142 |
#endif
|
143 |
|
144 |
#ifndef HAVE_INET_ATON
|
145 |
int inet_aton _P((const char *cp, struct in_addr *ia)); |
146 |
#endif
|
147 |
|
148 |
#include <fcntl.h> |
149 |
#ifndef NO_UNIX_SOCKETS
|
150 |
#include <sys/un.h> |
151 |
#endif
|
152 |
#include <signal.h> |
153 |
#ifdef HAVE_SYS_SIGNAL_H
|
154 |
# include <sys/signal.h> |
155 |
#endif
|
156 |
#ifndef _WIN32
|
157 |
#include <sys/socket.h> |
158 |
#endif
|
159 |
|
160 |
#if defined(HAVE_SYS_IOCTL_H)
|
161 |
# include <sys/ioctl.h> |
162 |
#endif
|
163 |
|
164 |
#ifdef HAVE_SYS_SELECT_H
|
165 |
# include <sys/select.h> |
166 |
#endif
|
167 |
|
168 |
#ifdef HAVE_SYS_WAIT_H
|
169 |
# include <sys/wait.h> |
170 |
#endif
|
171 |
|
172 |
#ifdef HAVE_SYS_FILIO_H
|
173 |
# include <sys/filio.h> |
174 |
#endif
|
175 |
|
176 |
#ifdef USE_PPP
|
177 |
#include <ppp/slirppp.h> |
178 |
#endif
|
179 |
|
180 |
#ifdef __STDC__
|
181 |
#include <stdarg.h> |
182 |
#else
|
183 |
#include <varargs.h> |
184 |
#endif
|
185 |
|
186 |
#include <sys/stat.h> |
187 |
|
188 |
/* Avoid conflicting with the libc insque() and remque(), which
|
189 |
have different prototypes. */
|
190 |
#define insque slirp_insque
|
191 |
#define remque slirp_remque
|
192 |
|
193 |
#ifdef HAVE_SYS_STROPTS_H
|
194 |
#include <sys/stropts.h> |
195 |
#endif
|
196 |
|
197 |
#include "debug.h" |
198 |
|
199 |
#include "ip.h" |
200 |
#include "tcp.h" |
201 |
#include "tcp_timer.h" |
202 |
#include "tcp_var.h" |
203 |
#include "tcpip.h" |
204 |
#include "udp.h" |
205 |
#include "icmp_var.h" |
206 |
#include "mbuf.h" |
207 |
#include "sbuf.h" |
208 |
#include "socket.h" |
209 |
#include "if.h" |
210 |
#include "main.h" |
211 |
#include "misc.h" |
212 |
#ifdef USE_PPP
|
213 |
#include "ppp/pppd.h" |
214 |
#include "ppp/ppp.h" |
215 |
#endif
|
216 |
|
217 |
#include "bootp.h" |
218 |
#include "tftp.h" |
219 |
#include "libslirp.h" |
220 |
|
221 |
#ifndef NULL |
222 |
#define NULL (void *)0 |
223 |
#endif
|
224 |
|
225 |
#ifndef FULL_BOLT
|
226 |
void if_start _P((void)); |
227 |
#else
|
228 |
void if_start _P((struct ttys *)); |
229 |
#endif
|
230 |
|
231 |
#ifdef BAD_SPRINTF
|
232 |
# define vsprintf vsprintf_len
|
233 |
# define sprintf sprintf_len
|
234 |
extern int vsprintf_len _P((char *, const char *, va_list)); |
235 |
extern int sprintf_len _P((char *, const char *, ...)); |
236 |
#endif
|
237 |
|
238 |
#ifdef DECLARE_SPRINTF
|
239 |
# ifndef BAD_SPRINTF
|
240 |
extern int vsprintf _P((char *, const char *, va_list)); |
241 |
# endif
|
242 |
extern int vfprintf _P((FILE *, const char *, va_list)); |
243 |
#endif
|
244 |
|
245 |
#ifndef HAVE_STRERROR
|
246 |
extern char *strerror _P((int error)); |
247 |
#endif
|
248 |
|
249 |
#ifndef HAVE_INDEX
|
250 |
char *index _P((const char *, int)); |
251 |
#endif
|
252 |
|
253 |
#ifndef HAVE_GETHOSTID
|
254 |
long gethostid _P((void)); |
255 |
#endif
|
256 |
|
257 |
void lprint _P((const char *, ...)); |
258 |
|
259 |
#ifndef _WIN32
|
260 |
#include <netdb.h> |
261 |
#endif
|
262 |
|
263 |
#define DEFAULT_BAUD 115200 |
264 |
|
265 |
#define SO_OPTIONS DO_KEEPALIVE
|
266 |
#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
|
267 |
|
268 |
/* cksum.c */
|
269 |
int cksum(struct mbuf *m, int len); |
270 |
|
271 |
/* if.c */
|
272 |
void if_init _P((void)); |
273 |
void if_output _P((struct socket *, struct mbuf *)); |
274 |
|
275 |
/* ip_input.c */
|
276 |
void ip_init _P((void)); |
277 |
void ip_input _P((struct mbuf *)); |
278 |
void ip_slowtimo _P((void)); |
279 |
void ip_stripoptions _P((register struct mbuf *, struct mbuf *)); |
280 |
|
281 |
/* ip_output.c */
|
282 |
int ip_output _P((struct socket *, struct mbuf *)); |
283 |
|
284 |
/* tcp_input.c */
|
285 |
void tcp_input _P((register struct mbuf *, int, struct socket *)); |
286 |
int tcp_mss _P((register struct tcpcb *, u_int)); |
287 |
|
288 |
/* tcp_output.c */
|
289 |
int tcp_output _P((register struct tcpcb *)); |
290 |
void tcp_setpersist _P((register struct tcpcb *)); |
291 |
|
292 |
/* tcp_subr.c */
|
293 |
void tcp_init _P((void)); |
294 |
void tcp_template _P((struct tcpcb *)); |
295 |
void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int)); |
296 |
struct tcpcb * tcp_newtcpcb _P((struct socket *)); |
297 |
struct tcpcb * tcp_close _P((register struct tcpcb *)); |
298 |
void tcp_sockclosed _P((struct tcpcb *)); |
299 |
int tcp_fconnect _P((struct socket *)); |
300 |
void tcp_connect _P((struct socket *)); |
301 |
int tcp_attach _P((struct socket *)); |
302 |
u_int8_t tcp_tos _P((struct socket *));
|
303 |
int tcp_emu _P((struct socket *, struct mbuf *)); |
304 |
int tcp_ctl _P((struct socket *)); |
305 |
struct tcpcb *tcp_drop(struct tcpcb *tp, int err); |
306 |
|
307 |
#ifdef USE_PPP
|
308 |
#define MIN_MRU MINMRU
|
309 |
#define MAX_MRU MAXMRU
|
310 |
#else
|
311 |
#define MIN_MRU 128 |
312 |
#define MAX_MRU 16384 |
313 |
#endif
|
314 |
|
315 |
#ifndef _WIN32
|
316 |
#define min(x,y) ((x) < (y) ? (x) : (y))
|
317 |
#define max(x,y) ((x) > (y) ? (x) : (y))
|
318 |
#endif
|
319 |
|
320 |
#ifdef _WIN32
|
321 |
#undef errno
|
322 |
#define errno (WSAGetLastError())
|
323 |
#endif
|
324 |
|
325 |
#endif
|