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