8 // Uncomment the following line to enable SLIRP statistics printing in Qemu
12 #define STAT(expr) expr
14 #define STAT(expr) do { } while(0)
20 #include "config-host.h"
21 #include "slirp_config.h"
24 # include <inttypes.h>
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;
32 #define WIN32_LEAN_AND_MEAN
34 # include <winsock2.h>
35 # include <sys/timeb.h>
36 # include <iphlpapi.h>
38 # define EWOULDBLOCK WSAEWOULDBLOCK
39 # define EINPROGRESS WSAEINPROGRESS
40 # define ENOTCONN WSAENOTCONN
41 # define EHOSTUNREACH WSAEHOSTUNREACH
42 # define ENETUNREACH WSAENETUNREACH
43 # define ECONNREFUSED WSAECONNREFUSED
45 # define ioctlsocket ioctl
46 # define closesocket(s) close(s)
50 #include <sys/types.h>
51 #ifdef HAVE_SYS_BITYPES_H
52 # include <sys/bitypes.h>
59 typedef unsigned char u_int8_t;
61 # if SIZEOF_SHORT == 2
62 typedef short int16_t;
63 typedef unsigned short u_int16_t;
67 typedef unsigned int u_int16_t;
69 #error Cannot find a type with sizeof() == 2
73 # if SIZEOF_SHORT == 4
74 typedef short int32_t;
75 typedef unsigned short u_int32_t;
79 typedef unsigned int u_int32_t;
81 #error Cannot find a type with sizeof() == 4
84 #endif /* NEED_TYPEDEFS */
98 #define memmove(x, y, z) bcopy(y, x, z)
101 #if TIME_WITH_SYS_TIME
102 # include <sys/time.h>
106 # include <sys/time.h>
115 # include <strings.h>
123 #ifndef NO_PROTOTYPES
131 #include <netinet/in.h>
132 #include <arpa/inet.h>
135 #ifdef GETTIMEOFDAY_ONE_ARG
136 #define gettimeofday(x, y) gettimeofday(x)
139 /* Systems lacking strdup() definition in <string.h>. */
141 char *strdup _P((const char *));
144 /* Systems lacking malloc() definition in <stdlib.h>. */
145 #if defined(ultrix) || defined(hcx)
146 void *malloc _P((size_t arg));
147 void free _P((void *ptr));
150 #ifndef HAVE_INET_ATON
151 int inet_aton _P((const char *cp, struct in_addr *ia));
155 #ifndef NO_UNIX_SOCKETS
159 #ifdef HAVE_SYS_SIGNAL_H
160 # include <sys/signal.h>
163 #include <sys/socket.h>
166 #if defined(HAVE_SYS_IOCTL_H)
167 # include <sys/ioctl.h>
170 #ifdef HAVE_SYS_SELECT_H
171 # include <sys/select.h>
174 #ifdef HAVE_SYS_WAIT_H
175 # include <sys/wait.h>
178 #ifdef HAVE_SYS_FILIO_H
179 # include <sys/filio.h>
183 #include <ppp/slirppp.h>
192 #include <sys/stat.h>
194 /* Avoid conflicting with the libc insque() and remque(), which
195 have different prototypes. */
196 #define insque slirp_insque
197 #define remque slirp_remque
199 #ifdef HAVE_SYS_STROPTS_H
200 #include <sys/stropts.h>
207 #include "tcp_timer.h"
211 #include "icmp_var.h"
220 #include "ppp/pppd.h"
226 #include "libslirp.h"
228 extern struct ttys *ttys_unit[MAX_INTERFACES];
231 #define NULL (void *)0
235 void if_start _P((void));
237 void if_start _P((struct ttys *));
241 # define vsprintf vsprintf_len
242 # define sprintf sprintf_len
243 extern int vsprintf_len _P((char *, const char *, va_list));
244 extern int sprintf_len _P((char *, const char *, ...));
247 #ifdef DECLARE_SPRINTF
249 extern int vsprintf _P((char *, const char *, va_list));
251 extern int vfprintf _P((FILE *, const char *, va_list));
254 #ifndef HAVE_STRERROR
255 extern char *strerror _P((int error));
259 char *index _P((const char *, int));
262 #ifndef HAVE_GETHOSTID
263 long gethostid _P((void));
266 void lprint _P((const char *, ...));
268 #if SIZEOF_CHAR_P == 4
269 # define insque_32 insque
270 # define remque_32 remque
272 inline void insque_32 _P((void *, void *));
273 inline void remque_32 _P((void *));
280 #define DEFAULT_BAUD 115200
282 #define SO_OPTIONS DO_KEEPALIVE
283 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
286 int cksum(struct mbuf *m, int len);
289 void if_init _P((void));
290 void if_output _P((struct socket *, struct mbuf *));
293 void ip_init _P((void));
294 void ip_input _P((struct mbuf *));
295 void ip_slowtimo _P((void));
296 void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
299 int ip_output _P((struct socket *, struct mbuf *));
302 void tcp_input _P((register struct mbuf *, int, struct socket *));
303 int tcp_mss _P((register struct tcpcb *, u_int));
306 int tcp_output _P((register struct tcpcb *));
307 void tcp_setpersist _P((register struct tcpcb *));
310 void tcp_init _P((void));
311 void tcp_template _P((struct tcpcb *));
312 void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
313 struct tcpcb * tcp_newtcpcb _P((struct socket *));
314 struct tcpcb * tcp_close _P((register struct tcpcb *));
315 void tcp_sockclosed _P((struct tcpcb *));
316 int tcp_fconnect _P((struct socket *));
317 void tcp_connect _P((struct socket *));
318 int tcp_attach _P((struct socket *));
319 u_int8_t tcp_tos _P((struct socket *));
320 int tcp_emu _P((struct socket *, struct mbuf *));
321 int tcp_ctl _P((struct socket *));
322 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
325 #define MIN_MRU MINMRU
326 #define MAX_MRU MAXMRU
329 #define MAX_MRU 16384
333 #define min(x,y) ((x) < (y) ? (x) : (y))
334 #define max(x,y) ((x) > (y) ? (x) : (y))
339 #define errno (WSAGetLastError())