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
;
33 # include <winsock2.h>
34 # include <sys/timeb.h>
35 # include <iphlpapi.h>
37 # define EWOULDBLOCK WSAEWOULDBLOCK
38 # define EINPROGRESS WSAEINPROGRESS
39 # define ENOTCONN WSAENOTCONN
40 # define EHOSTUNREACH WSAEHOSTUNREACH
41 # define ENETUNREACH WSAENETUNREACH
42 # define ECONNREFUSED WSAECONNREFUSED
44 # define ioctlsocket ioctl
45 # define closesocket(s) close(s)
49 #include <sys/types.h>
50 #ifdef HAVE_SYS_BITYPES_H
51 # include <sys/bitypes.h>
58 typedef unsigned char u_int8_t
;
60 # if SIZEOF_SHORT == 2
61 typedef short int16_t;
62 typedef unsigned short u_int16_t
;
66 typedef unsigned int u_int16_t
;
68 #error Cannot find a type with sizeof() == 2
72 # if SIZEOF_SHORT == 4
73 typedef short int32_t;
74 typedef unsigned short u_int32_t
;
78 typedef unsigned int u_int32_t
;
80 #error Cannot find a type with sizeof() == 4
83 #endif /* NEED_TYPEDEFS */
97 #define memmove(x, y, z) bcopy(y, x, z)
100 #if TIME_WITH_SYS_TIME
101 # include <sys/time.h>
105 # include <sys/time.h>
114 # include <strings.h>
122 #ifndef NO_PROTOTYPES
130 #include <netinet/in.h>
131 #include <arpa/inet.h>
134 #ifdef GETTIMEOFDAY_ONE_ARG
135 #define gettimeofday(x, y) gettimeofday(x)
138 /* Systems lacking strdup() definition in <string.h>. */
140 char *strdup
_P((const char *));
143 /* Systems lacking malloc() definition in <stdlib.h>. */
144 #if defined(ultrix) || defined(hcx)
145 void *malloc
_P((size_t arg
));
146 void free
_P((void *ptr
));
149 #ifndef HAVE_INET_ATON
150 int inet_aton
_P((const char *cp
, struct in_addr
*ia
));
154 #ifndef NO_UNIX_SOCKETS
158 #ifdef HAVE_SYS_SIGNAL_H
159 # include <sys/signal.h>
162 #include <sys/socket.h>
165 #if defined(HAVE_SYS_IOCTL_H)
166 # include <sys/ioctl.h>
169 #ifdef HAVE_SYS_SELECT_H
170 # include <sys/select.h>
173 #ifdef HAVE_SYS_WAIT_H
174 # include <sys/wait.h>
177 #ifdef HAVE_SYS_FILIO_H
178 # include <sys/filio.h>
182 #include <ppp/slirppp.h>
191 #include <sys/stat.h>
193 /* Avoid conflicting with the libc insque() and remque(), which
194 have different prototypes. */
195 #define insque slirp_insque
196 #define remque slirp_remque
198 #ifdef HAVE_SYS_STROPTS_H
199 #include <sys/stropts.h>
206 #include "tcp_timer.h"
210 #include "icmp_var.h"
219 #include "ppp/pppd.h"
225 #include "libslirp.h"
227 extern struct ttys
*ttys_unit
[MAX_INTERFACES
];
230 #define NULL (void *)0
234 void if_start
_P((void));
236 void if_start
_P((struct ttys
*));
240 # define vsprintf vsprintf_len
241 # define sprintf sprintf_len
242 extern int vsprintf_len
_P((char *, const char *, va_list));
243 extern int sprintf_len
_P((char *, const char *, ...));
246 #ifdef DECLARE_SPRINTF
248 extern int vsprintf
_P((char *, const char *, va_list));
250 extern int vfprintf
_P((FILE *, const char *, va_list));
253 #ifndef HAVE_STRERROR
254 extern char *strerror
_P((int error
));
258 char *index
_P((const char *, int));
261 #ifndef HAVE_GETHOSTID
262 long gethostid
_P((void));
265 void lprint
_P((const char *, ...));
267 #if SIZEOF_CHAR_P == 4
268 # define insque_32 insque
269 # define remque_32 remque
271 inline void insque_32
_P((void *, void *));
272 inline void remque_32
_P((void *));
279 #define DEFAULT_BAUD 115200
281 #define SO_OPTIONS DO_KEEPALIVE
282 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
285 int cksum(struct mbuf
*m
, int len
);
288 void if_init
_P((void));
289 void if_output
_P((struct socket
*, struct mbuf
*));
292 void ip_init
_P((void));
293 void ip_input
_P((struct mbuf
*));
294 void ip_slowtimo
_P((void));
295 void ip_stripoptions
_P((register struct mbuf
*, struct mbuf
*));
298 int ip_output
_P((struct socket
*, struct mbuf
*));
301 void tcp_input
_P((register struct mbuf
*, int, struct socket
*));
302 int tcp_mss
_P((register struct tcpcb
*, u_int
));
305 int tcp_output
_P((register struct tcpcb
*));
306 void tcp_setpersist
_P((register struct tcpcb
*));
309 void tcp_init
_P((void));
310 void tcp_template
_P((struct tcpcb
*));
311 void tcp_respond
_P((struct tcpcb
*, register struct tcpiphdr
*, register struct mbuf
*, tcp_seq
, tcp_seq
, int));
312 struct tcpcb
* tcp_newtcpcb
_P((struct socket
*));
313 struct tcpcb
* tcp_close
_P((register struct tcpcb
*));
314 void tcp_sockclosed
_P((struct tcpcb
*));
315 int tcp_fconnect
_P((struct socket
*));
316 void tcp_connect
_P((struct socket
*));
317 int tcp_attach
_P((struct socket
*));
318 u_int8_t tcp_tos
_P((struct socket
*));
319 int tcp_emu
_P((struct socket
*, struct mbuf
*));
320 int tcp_ctl
_P((struct socket
*));
321 struct tcpcb
*tcp_drop(struct tcpcb
*tp
, int err
);
324 #define MIN_MRU MINMRU
325 #define MAX_MRU MAXMRU
328 #define MAX_MRU 16384
332 #define min(x,y) ((x) < (y) ? (x) : (y))
333 #define max(x,y) ((x) > (y) ? (x) : (y))
338 #define errno (WSAGetLastError())