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