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 <ws2tcpip.h>
36 # include <sys/timeb.h>
37 # include <iphlpapi.h>
39 # define EWOULDBLOCK WSAEWOULDBLOCK
40 # define EINPROGRESS WSAEINPROGRESS
41 # define ENOTCONN WSAENOTCONN
42 # define EHOSTUNREACH WSAEHOSTUNREACH
43 # define ENETUNREACH WSAENETUNREACH
44 # define ECONNREFUSED WSAECONNREFUSED
46 # define ioctlsocket ioctl
47 # define closesocket(s) close(s)
51 #include <sys/types.h>
52 #ifdef HAVE_SYS_BITYPES_H
53 # include <sys/bitypes.h>
60 typedef unsigned char u_int8_t
;
62 # if SIZEOF_SHORT == 2
63 typedef short int16_t;
64 typedef unsigned short u_int16_t
;
68 typedef unsigned int u_int16_t
;
70 #error Cannot find a type with sizeof() == 2
74 # if SIZEOF_SHORT == 4
75 typedef short int32_t;
76 typedef unsigned short u_int32_t
;
80 typedef unsigned int u_int32_t
;
82 #error Cannot find a type with sizeof() == 4
85 #endif /* NEED_TYPEDEFS */
99 #define memmove(x, y, z) bcopy(y, x, z)
102 #if TIME_WITH_SYS_TIME
103 # include <sys/time.h>
106 # ifdef HAVE_SYS_TIME_H
107 # include <sys/time.h>
116 # include <strings.h>
124 #ifndef NO_PROTOTYPES
132 #include <netinet/in.h>
133 #include <arpa/inet.h>
136 #ifdef GETTIMEOFDAY_ONE_ARG
137 #define gettimeofday(x, y) gettimeofday(x)
140 /* Systems lacking strdup() definition in <string.h>. */
142 char *strdup
_P((const char *));
145 /* Systems lacking malloc() definition in <stdlib.h>. */
146 #if defined(ultrix) || defined(hcx)
147 void *malloc
_P((size_t arg
));
148 void free
_P((void *ptr
));
151 #ifndef HAVE_INET_ATON
152 int inet_aton
_P((const char *cp
, struct in_addr
*ia
));
156 #ifndef NO_UNIX_SOCKETS
160 #ifdef HAVE_SYS_SIGNAL_H
161 # include <sys/signal.h>
164 #include <sys/socket.h>
167 #if defined(HAVE_SYS_IOCTL_H)
168 # include <sys/ioctl.h>
171 #ifdef HAVE_SYS_SELECT_H
172 # include <sys/select.h>
175 #ifdef HAVE_SYS_WAIT_H
176 # include <sys/wait.h>
179 #ifdef HAVE_SYS_FILIO_H
180 # include <sys/filio.h>
184 #include <ppp/slirppp.h>
193 #include <sys/stat.h>
195 /* Avoid conflicting with the libc insque() and remque(), which
196 have different prototypes. */
197 #define insque slirp_insque
198 #define remque slirp_remque
200 #ifdef HAVE_SYS_STROPTS_H
201 #include <sys/stropts.h>
208 #include "tcp_timer.h"
212 #include "icmp_var.h"
221 #include "ppp/pppd.h"
227 #include "libslirp.h"
229 extern struct ttys
*ttys_unit
[MAX_INTERFACES
];
232 #define NULL (void *)0
236 void if_start
_P((void));
238 void if_start
_P((struct ttys
*));
242 # define vsprintf vsprintf_len
243 # define sprintf sprintf_len
244 extern int vsprintf_len
_P((char *, const char *, va_list));
245 extern int sprintf_len
_P((char *, const char *, ...));
248 #ifdef DECLARE_SPRINTF
250 extern int vsprintf
_P((char *, const char *, va_list));
252 extern int vfprintf
_P((FILE *, const char *, va_list));
255 #ifndef HAVE_STRERROR
256 extern char *strerror
_P((int error
));
260 char *index
_P((const char *, int));
263 #ifndef HAVE_GETHOSTID
264 long gethostid
_P((void));
267 void lprint
_P((const char *, ...));
269 #if SIZEOF_CHAR_P == 4
270 # define insque_32 insque
271 # define remque_32 remque
273 void insque_32
_P((void *, void *));
274 void remque_32
_P((void *));
281 #define DEFAULT_BAUD 115200
283 #define SO_OPTIONS DO_KEEPALIVE
284 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
287 int cksum(struct mbuf
*m
, int len
);
290 void if_init
_P((void));
291 void if_output
_P((struct socket
*, struct mbuf
*));
294 void ip_init
_P((void));
295 void ip_input
_P((struct mbuf
*));
296 void ip_slowtimo
_P((void));
297 void ip_stripoptions
_P((register struct mbuf
*, struct mbuf
*));
300 int ip_output
_P((struct socket
*, struct mbuf
*));
303 void tcp_input
_P((register struct mbuf
*, int, struct socket
*));
304 int tcp_mss
_P((register struct tcpcb
*, u_int
));
307 int tcp_output
_P((register struct tcpcb
*));
308 void tcp_setpersist
_P((register struct tcpcb
*));
311 void tcp_init
_P((void));
312 void tcp_template
_P((struct tcpcb
*));
313 void tcp_respond
_P((struct tcpcb
*, register struct tcpiphdr
*, register struct mbuf
*, tcp_seq
, tcp_seq
, int));
314 struct tcpcb
* tcp_newtcpcb
_P((struct socket
*));
315 struct tcpcb
* tcp_close
_P((register struct tcpcb
*));
316 void tcp_sockclosed
_P((struct tcpcb
*));
317 int tcp_fconnect
_P((struct socket
*));
318 void tcp_connect
_P((struct socket
*));
319 int tcp_attach
_P((struct socket
*));
320 u_int8_t tcp_tos
_P((struct socket
*));
321 int tcp_emu
_P((struct socket
*, struct mbuf
*));
322 int tcp_ctl
_P((struct socket
*));
323 struct tcpcb
*tcp_drop(struct tcpcb
*tp
, int err
);
326 #define MIN_MRU MINMRU
327 #define MAX_MRU MAXMRU
330 #define MAX_MRU 16384
334 #define min(x,y) ((x) < (y) ? (x) : (y))
335 #define max(x,y) ((x) > (y) ? (x) : (y))
340 #define errno (WSAGetLastError())