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