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