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;
24
# include <winsock2.h>
25
# include <sys/timeb.h>
26
# include <iphlpapi.h>
28
# define EWOULDBLOCK WSAEWOULDBLOCK
29
# define EINPROGRESS WSAEINPROGRESS
30
# define ENOTCONN WSAENOTCONN
31
# define EHOSTUNREACH WSAEHOSTUNREACH
32
# define ENETUNREACH WSAENETUNREACH
33
# define ECONNREFUSED WSAECONNREFUSED
35
# define ioctlsocket ioctl
36
# define closesocket(s) close(s)
44
#include <sys/types.h>
45
#ifdef HAVE_SYS_BITYPES_H
46
# include <sys/bitypes.h>
53
typedef unsigned char u_int8_t;
55
# if SIZEOF_SHORT == 2
56
typedef short int16_t;
57
typedef unsigned short u_int16_t;
61
typedef unsigned int u_int16_t;
63
#error Cannot find a type with sizeof() == 2
67
# if SIZEOF_SHORT == 4
68
typedef short int32_t;
69
typedef unsigned short u_int32_t;
73
typedef unsigned int u_int32_t;
75
#error Cannot find a type with sizeof() == 4
78
#endif /* NEED_TYPEDEFS */
92
#define memmove(x, y, z) bcopy(y, x, z)
95
#if TIME_WITH_SYS_TIME
96
# include <sys/time.h>
100
# include <sys/time.h>
109
# include <strings.h>
117
#ifndef NO_PROTOTYPES
125
#include <netinet/in.h>
126
#include <arpa/inet.h>
129
#ifdef GETTIMEOFDAY_ONE_ARG
130
#define gettimeofday(x, y) gettimeofday(x)
133
/* Systems lacking strdup() definition in <string.h>. */
135
char *strdup _P((const char *));
138
/* Systems lacking malloc() definition in <stdlib.h>. */
139
#if defined(ultrix) || defined(hcx)
140
void *malloc _P((size_t arg));
141
void free _P((void *ptr));
144
#ifndef HAVE_INET_ATON
145
int inet_aton _P((const char *cp, struct in_addr *ia));
149
#ifndef NO_UNIX_SOCKETS
153
#ifdef HAVE_SYS_SIGNAL_H
154
# include <sys/signal.h>
157
#include <sys/socket.h>
160
#if defined(HAVE_SYS_IOCTL_H)
161
# include <sys/ioctl.h>
164
#ifdef HAVE_SYS_SELECT_H
165
# include <sys/select.h>
168
#ifdef HAVE_SYS_WAIT_H
169
# include <sys/wait.h>
172
#ifdef HAVE_SYS_FILIO_H
173
# include <sys/filio.h>
177
#include <ppp/slirppp.h>
186
#include <sys/stat.h>
188
/* Avoid conflicting with the libc insque() and remque(), which
189
have different prototypes. */
190
#define insque slirp_insque
191
#define remque slirp_remque
193
#ifdef HAVE_SYS_STROPTS_H
194
#include <sys/stropts.h>
201
#include "tcp_timer.h"
205
#include "icmp_var.h"
214
#include "ppp/pppd.h"
220
#include "libslirp.h"
222
extern struct ttys *ttys_unit[MAX_INTERFACES];
225
#define NULL (void *)0
229
void if_start _P((void));
231
void if_start _P((struct ttys *));
235
# define vsprintf vsprintf_len
236
# define sprintf sprintf_len
237
extern int vsprintf_len _P((char *, const char *, va_list));
238
extern int sprintf_len _P((char *, const char *, ...));
241
#ifdef DECLARE_SPRINTF
243
extern int vsprintf _P((char *, const char *, va_list));
245
extern int vfprintf _P((FILE *, const char *, va_list));
248
#ifndef HAVE_STRERROR
249
extern char *strerror _P((int error));
253
char *index _P((const char *, int));
256
#ifndef HAVE_GETHOSTID
257
long gethostid _P((void));
260
void lprint _P((const char *, ...));
264
#if SIZEOF_CHAR_P == 4
265
# define insque_32 insque
266
# define remque_32 remque
268
inline void insque_32 _P((void *, void *));
269
inline void remque_32 _P((void *));
276
#define DEFAULT_BAUD 115200
279
int cksum(struct mbuf *m, int len);
282
void if_init _P((void));
283
void if_output _P((struct socket *, struct mbuf *));
286
void ip_init _P((void));
287
void ip_input _P((struct mbuf *));
288
struct ip * ip_reass _P((register struct ipasfrag *, register struct ipq *));
289
void ip_freef _P((struct ipq *));
290
void ip_enq _P((register struct ipasfrag *, register struct ipasfrag *));
291
void ip_deq _P((register struct ipasfrag *));
292
void ip_slowtimo _P((void));
293
void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
296
int ip_output _P((struct socket *, struct mbuf *));
299
int tcp_reass _P((register struct tcpcb *, register struct tcpiphdr *, struct mbuf *));
300
void tcp_input _P((register struct mbuf *, int, struct socket *));
301
void tcp_dooptions _P((struct tcpcb *, u_char *, int, struct tcpiphdr *));
302
void tcp_xmit_timer _P((register struct tcpcb *, int));
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_drain _P((void));
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())