063e5f6c18ab8b75e09d8dee54e1030288f21ecc
[qemu.git] / slirp / slirp.h
blob063e5f6c18ab8b75e09d8dee54e1030288f21ecc
1 #ifndef __COMMON_H__
2 #define __COMMON_H__
4 #include "config-host.h"
5 #include "slirp_config.h"
7 #ifdef _WIN32
8 # include <inttypes.h>
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;
16 # include <windows.h>
17 # include <winsock2.h>
18 # include <ws2tcpip.h>
19 # include <sys/timeb.h>
20 # include <iphlpapi.h>
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)
31 # define O_BINARY 0
32 #endif
34 #include <sys/types.h>
35 #ifdef HAVE_SYS_BITYPES_H
36 # include <sys/bitypes.h>
37 #endif
39 #include <sys/time.h>
41 #ifdef NEED_TYPEDEFS
42 typedef char int8_t;
43 typedef unsigned char u_int8_t;
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
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 */
70 #ifdef HAVE_UNISTD_H
71 # include <unistd.h>
72 #endif
74 #ifdef HAVE_STDLIB_H
75 # include <stdlib.h>
76 #endif
78 #include <stdio.h>
79 #include <errno.h>
81 #ifndef HAVE_MEMMOVE
82 #define memmove(x, y, z) bcopy(y, x, z)
83 #endif
85 #if TIME_WITH_SYS_TIME
86 # include <sys/time.h>
87 # include <time.h>
88 #else
89 # ifdef HAVE_SYS_TIME_H
90 # include <sys/time.h>
91 # else
92 # include <time.h>
93 # endif
94 #endif
96 #ifdef HAVE_STRING_H
97 # include <string.h>
98 #else
99 # include <strings.h>
100 #endif
102 #ifndef _WIN32
103 #include <sys/uio.h>
104 #endif
106 #undef _P
107 #ifndef NO_PROTOTYPES
108 # define _P(x) x
109 #else
110 # define _P(x) ()
111 #endif
113 #ifndef _WIN32
114 #include <netinet/in.h>
115 #include <arpa/inet.h>
116 #endif
118 #ifdef GETTIMEOFDAY_ONE_ARG
119 #define gettimeofday(x, y) gettimeofday(x)
120 #endif
122 /* Systems lacking strdup() definition in <string.h>. */
123 #if defined(ultrix)
124 char *strdup _P((const char *));
125 #endif
127 /* Systems lacking malloc() definition in <stdlib.h>. */
128 #if defined(ultrix) || defined(hcx)
129 void *malloc _P((size_t arg));
130 void free _P((void *ptr));
131 #endif
133 #ifndef HAVE_INET_ATON
134 int inet_aton _P((const char *cp, struct in_addr *ia));
135 #endif
137 #include <fcntl.h>
138 #ifndef NO_UNIX_SOCKETS
139 #include <sys/un.h>
140 #endif
141 #include <signal.h>
142 #ifdef HAVE_SYS_SIGNAL_H
143 # include <sys/signal.h>
144 #endif
145 #ifndef _WIN32
146 #include <sys/socket.h>
147 #endif
149 #if defined(HAVE_SYS_IOCTL_H)
150 # include <sys/ioctl.h>
151 #endif
153 #ifdef HAVE_SYS_SELECT_H
154 # include <sys/select.h>
155 #endif
157 #ifdef HAVE_SYS_WAIT_H
158 # include <sys/wait.h>
159 #endif
161 #ifdef HAVE_SYS_FILIO_H
162 # include <sys/filio.h>
163 #endif
165 #ifdef USE_PPP
166 #include <ppp/slirppp.h>
167 #endif
169 #ifdef __STDC__
170 #include <stdarg.h>
171 #else
172 #include <varargs.h>
173 #endif
175 #include <sys/stat.h>
177 /* Avoid conflicting with the libc insque() and remque(), which
178 have different prototypes. */
179 #define insque slirp_insque
180 #define remque slirp_remque
182 #ifdef HAVE_SYS_STROPTS_H
183 #include <sys/stropts.h>
184 #endif
186 #include "debug.h"
188 #include "ip.h"
189 #include "tcp.h"
190 #include "tcp_timer.h"
191 #include "tcp_var.h"
192 #include "tcpip.h"
193 #include "udp.h"
194 #include "mbuf.h"
195 #include "sbuf.h"
196 #include "socket.h"
197 #include "if.h"
198 #include "main.h"
199 #include "misc.h"
200 #ifdef USE_PPP
201 #include "ppp/pppd.h"
202 #include "ppp/ppp.h"
203 #endif
205 #include "bootp.h"
206 #include "tftp.h"
207 #include "libslirp.h"
209 #ifndef NULL
210 #define NULL (void *)0
211 #endif
213 #ifndef FULL_BOLT
214 void if_start _P((void));
215 #else
216 void if_start _P((struct ttys *));
217 #endif
219 #ifdef BAD_SPRINTF
220 # define vsprintf vsprintf_len
221 # define sprintf sprintf_len
222 extern int vsprintf_len _P((char *, const char *, va_list));
223 extern int sprintf_len _P((char *, const char *, ...));
224 #endif
226 #ifdef DECLARE_SPRINTF
227 # ifndef BAD_SPRINTF
228 extern int vsprintf _P((char *, const char *, va_list));
229 # endif
230 extern int vfprintf _P((FILE *, const char *, va_list));
231 #endif
233 #ifndef HAVE_STRERROR
234 extern char *strerror _P((int error));
235 #endif
237 #ifndef HAVE_INDEX
238 char *index _P((const char *, int));
239 #endif
241 #ifndef HAVE_GETHOSTID
242 long gethostid _P((void));
243 #endif
245 void lprint _P((const char *, ...));
247 #ifndef _WIN32
248 #include <netdb.h>
249 #endif
251 #define DEFAULT_BAUD 115200
253 #define SO_OPTIONS DO_KEEPALIVE
254 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
256 /* cksum.c */
257 int cksum(struct mbuf *m, int len);
259 /* if.c */
260 void if_init _P((void));
261 void if_output _P((struct socket *, struct mbuf *));
263 /* ip_input.c */
264 void ip_init _P((void));
265 void ip_input _P((struct mbuf *));
266 void ip_slowtimo _P((void));
267 void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
269 /* ip_output.c */
270 int ip_output _P((struct socket *, struct mbuf *));
272 /* tcp_input.c */
273 void tcp_input _P((register struct mbuf *, int, struct socket *));
274 int tcp_mss _P((register struct tcpcb *, u_int));
276 /* tcp_output.c */
277 int tcp_output _P((register struct tcpcb *));
278 void tcp_setpersist _P((register struct tcpcb *));
280 /* tcp_subr.c */
281 void tcp_init _P((void));
282 void tcp_template _P((struct tcpcb *));
283 void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
284 struct tcpcb * tcp_newtcpcb _P((struct socket *));
285 struct tcpcb * tcp_close _P((register struct tcpcb *));
286 void tcp_sockclosed _P((struct tcpcb *));
287 int tcp_fconnect _P((struct socket *));
288 void tcp_connect _P((struct socket *));
289 int tcp_attach _P((struct socket *));
290 u_int8_t tcp_tos _P((struct socket *));
291 int tcp_emu _P((struct socket *, struct mbuf *));
292 int tcp_ctl _P((struct socket *));
293 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
295 #ifdef USE_PPP
296 #define MIN_MRU MINMRU
297 #define MAX_MRU MAXMRU
298 #else
299 #define MIN_MRU 128
300 #define MAX_MRU 16384
301 #endif
303 #ifndef _WIN32
304 #define min(x,y) ((x) < (y) ? (x) : (y))
305 #define max(x,y) ((x) > (y) ? (x) : (y))
306 #endif
308 #ifdef _WIN32
309 #undef errno
310 #define errno (WSAGetLastError())
311 #endif
313 #endif