12 #include "slirp_config.h"
15 # include <inttypes.h>
17 typedef uint8_t u_int8_t;
18 typedef uint16_t u_int16_t;
19 typedef uint32_t u_int32_t;
20 typedef uint64_t u_int64_t;
21 typedef char *caddr_t;
23 # include <winsock2.h>
24 # include <sys/timeb.h>
25 # include <iphlpapi.h>
27 # define EWOULDBLOCK WSAEWOULDBLOCK
28 # define EINPROGRESS WSAEINPROGRESS
29 # define ENOTCONN WSAENOTCONN
30 # define EHOSTUNREACH WSAEHOSTUNREACH
31 # define ENETUNREACH WSAENETUNREACH
32 # define ECONNREFUSED WSAECONNREFUSED
34 # define ioctlsocket ioctl
35 # define closesocket(s) close(s)
38 #include <sys/types.h>
39 #ifdef HAVE_SYS_BITYPES_H
40 # include <sys/bitypes.h>
47 typedef unsigned char u_int8_t;
49 # if SIZEOF_SHORT == 2
50 typedef short int16_t;
51 typedef unsigned short u_int16_t;
55 typedef unsigned int u_int16_t;
57 #error Cannot find a type with sizeof() == 2
61 # if SIZEOF_SHORT == 4
62 typedef short int32_t;
63 typedef unsigned short u_int32_t;
67 typedef unsigned int u_int32_t;
69 #error Cannot find a type with sizeof() == 4
72 #endif /* NEED_TYPEDEFS */
86 #define memmove(x, y, z) bcopy(y, x, z)
89 #if TIME_WITH_SYS_TIME
90 # include <sys/time.h>
94 # include <sys/time.h>
103 # include <strings.h>
111 #ifndef NO_PROTOTYPES
119 #include <netinet/in.h>
120 #include <arpa/inet.h>
123 #ifdef GETTIMEOFDAY_ONE_ARG
124 #define gettimeofday(x, y) gettimeofday(x)
127 /* Systems lacking strdup() definition in <string.h>. */
129 char *strdup _P((const char *));
132 /* Systems lacking malloc() definition in <stdlib.h>. */
133 #if defined(ultrix) || defined(hcx)
134 void *malloc _P((size_t arg));
135 void free _P((void *ptr));
138 #ifndef HAVE_INET_ATON
139 int inet_aton _P((const char *cp, struct in_addr *ia));
143 #ifndef NO_UNIX_SOCKETS
147 #ifdef HAVE_SYS_SIGNAL_H
148 # include <sys/signal.h>
151 #include <sys/socket.h>
154 #if defined(HAVE_SYS_IOCTL_H)
155 # include <sys/ioctl.h>
158 #ifdef HAVE_SYS_SELECT_H
159 # include <sys/select.h>
162 #ifdef HAVE_SYS_WAIT_H
163 # include <sys/wait.h>
166 #ifdef HAVE_SYS_FILIO_H
167 # include <sys/filio.h>
171 #include <ppp/slirppp.h>
180 #include <sys/stat.h>
182 /* Avoid conflicting with the libc insque() and remque(), which
183 have different prototypes. */
184 #define insque slirp_insque
185 #define remque slirp_remque
187 #ifdef HAVE_SYS_STROPTS_H
188 #include <sys/stropts.h>
195 #include "tcp_timer.h"
199 #include "icmp_var.h"
208 #include "ppp/pppd.h"
214 #include "libslirp.h"
216 extern struct ttys *ttys_unit[MAX_INTERFACES];
219 #define NULL (void *)0
223 void if_start _P((void));
225 void if_start _P((struct ttys *));
229 # define vsprintf vsprintf_len
230 # define sprintf sprintf_len
231 extern int vsprintf_len _P((char *, const char *, va_list));
232 extern int sprintf_len _P((char *, const char *, ...));
235 #ifdef DECLARE_SPRINTF
237 extern int vsprintf _P((char *, const char *, va_list));
239 extern int vfprintf _P((FILE *, const char *, va_list));
242 #ifndef HAVE_STRERROR
243 extern char *strerror _P((int error));
247 char *index _P((const char *, int));
250 #ifndef HAVE_GETHOSTID
251 long gethostid _P((void));
254 void lprint _P((const char *, ...));
258 #if SIZEOF_CHAR_P == 4
259 # define insque_32 insque
260 # define remque_32 remque
262 inline void insque_32 _P((void *, void *));
263 inline void remque_32 _P((void *));
270 #define DEFAULT_BAUD 115200
273 int cksum(struct mbuf *m, int len);
276 void if_init _P((void));
277 void if_output _P((struct socket *, struct mbuf *));
280 void ip_init _P((void));
281 void ip_input _P((struct mbuf *));
282 struct ip * ip_reass _P((register struct ipasfrag *, register struct ipq *));
283 void ip_freef _P((struct ipq *));
284 void ip_enq _P((register struct ipasfrag *, register struct ipasfrag *));
285 void ip_deq _P((register struct ipasfrag *));
286 void ip_slowtimo _P((void));
287 void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
290 int ip_output _P((struct socket *, struct mbuf *));
293 int tcp_reass _P((register struct tcpcb *, register struct tcpiphdr *, struct mbuf *));
294 void tcp_input _P((register struct mbuf *, int, struct socket *));
295 void tcp_dooptions _P((struct tcpcb *, u_char *, int, struct tcpiphdr *));
296 void tcp_xmit_timer _P((register struct tcpcb *, int));
297 int tcp_mss _P((register struct tcpcb *, u_int));
300 int tcp_output _P((register struct tcpcb *));
301 void tcp_setpersist _P((register struct tcpcb *));
304 void tcp_init _P((void));
305 void tcp_template _P((struct tcpcb *));
306 void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
307 struct tcpcb * tcp_newtcpcb _P((struct socket *));
308 struct tcpcb * tcp_close _P((register struct tcpcb *));
309 void tcp_drain _P((void));
310 void tcp_sockclosed _P((struct tcpcb *));
311 int tcp_fconnect _P((struct socket *));
312 void tcp_connect _P((struct socket *));
313 int tcp_attach _P((struct socket *));
314 u_int8_t tcp_tos _P((struct socket *));
315 int tcp_emu _P((struct socket *, struct mbuf *));
316 int tcp_ctl _P((struct socket *));
317 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
320 #define MIN_MRU MINMRU
321 #define MAX_MRU MAXMRU
324 #define MAX_MRU 16384
328 #define min(x,y) ((x) < (y) ? (x) : (y))
329 #define max(x,y) ((x) > (y) ? (x) : (y))
333 #define errno (WSAGetLastError())