4 #include "config-host.h"
5 #include "slirp_config.h"
10 typedef uint8_t u_int8_t
;
11 typedef uint16_t u_int16_t
;
12 typedef uint32_t u_int32_t
;
13 typedef uint64_t u_int64_t
;
14 typedef char *caddr_t
;
17 # include <winsock2.h>
18 # include <ws2tcpip.h>
19 # include <sys/timeb.h>
20 # include <iphlpapi.h>
22 # define EWOULDBLOCK WSAEWOULDBLOCK
23 # define EINPROGRESS WSAEINPROGRESS
24 # define ENOTCONN WSAENOTCONN
25 # define EHOSTUNREACH WSAEHOSTUNREACH
26 # define ENETUNREACH WSAENETUNREACH
27 # define ECONNREFUSED WSAECONNREFUSED
29 # define ioctlsocket ioctl
30 # define closesocket(s) close(s)
34 #include <sys/types.h>
35 #ifdef HAVE_SYS_BITYPES_H
36 # include <sys/bitypes.h>
43 typedef unsigned char u_int8_t
;
45 # if SIZEOF_SHORT == 2
46 typedef short int16_t;
47 typedef unsigned short u_int16_t
;
51 typedef unsigned int u_int16_t
;
53 #error Cannot find a type with sizeof() == 2
57 # if SIZEOF_SHORT == 4
58 typedef short int32_t;
59 typedef unsigned short u_int32_t
;
63 typedef unsigned int u_int32_t
;
65 #error Cannot find a type with sizeof() == 4
68 #endif /* NEED_TYPEDEFS */
82 #define memmove(x, y, z) bcopy(y, x, z)
85 #if TIME_WITH_SYS_TIME
86 # include <sys/time.h>
89 # ifdef HAVE_SYS_TIME_H
90 # include <sys/time.h>
107 #include <netinet/in.h>
108 #include <arpa/inet.h>
111 /* Systems lacking strdup() definition in <string.h>. */
113 char *strdup(const char *);
116 /* Systems lacking malloc() definition in <stdlib.h>. */
117 #if defined(ultrix) || defined(hcx)
118 void *malloc(size_t arg
);
119 void free(void *ptr
);
122 #ifndef HAVE_INET_ATON
123 int inet_aton(const char *cp
, struct in_addr
*ia
);
127 #ifndef NO_UNIX_SOCKETS
131 #ifdef HAVE_SYS_SIGNAL_H
132 # include <sys/signal.h>
135 #include <sys/socket.h>
138 #if defined(HAVE_SYS_IOCTL_H)
139 # include <sys/ioctl.h>
142 #ifdef HAVE_SYS_SELECT_H
143 # include <sys/select.h>
146 #ifdef HAVE_SYS_WAIT_H
147 # include <sys/wait.h>
150 #ifdef HAVE_SYS_FILIO_H
151 # include <sys/filio.h>
155 #include <ppp/slirppp.h>
164 #include <sys/stat.h>
166 /* Avoid conflicting with the libc insque() and remque(), which
167 have different prototypes. */
168 #define insque slirp_insque
169 #define remque slirp_remque
171 #ifdef HAVE_SYS_STROPTS_H
172 #include <sys/stropts.h>
177 #include "qemu-queue.h"
179 #include "libslirp.h"
182 #include "tcp_timer.h"
193 #include "ppp/pppd.h"
201 int qemu_socket(int domain
, int type
, int protocol
);
205 QTAILQ_ENTRY(Slirp
) entry
;
207 /* virtual network configuration */
208 struct in_addr vnetwork_addr
;
209 struct in_addr vnetwork_mask
;
210 struct in_addr vhost_addr
;
211 struct in_addr vdhcp_startaddr
;
212 struct in_addr vnameserver_addr
;
214 /* ARP cache for the guest IP addresses (XXX: allow many entries) */
215 uint8_t client_ethaddr
[6];
217 struct in_addr client_ipaddr
;
218 char client_hostname
[33];
222 struct ex_list
*exec_list
;
225 struct mbuf m_freelist
, m_usedlist
;
229 int if_queued
; /* number of packets queued so far */
230 struct mbuf if_fastq
; /* fast queue (for interactive data) */
231 struct mbuf if_batchq
; /* queue for non-interactive data */
232 struct mbuf
*next_m
; /* pointer to next mbuf to output */
235 struct ipq ipq
; /* ip reass. queue */
236 u_int16_t ip_id
; /* ip packet ctr, for ids */
238 /* bootp/dhcp states */
239 BOOTPClient bootp_clients
[NB_BOOTP_CLIENTS
];
240 char *bootp_filename
;
244 struct socket
*tcp_last_so
;
245 tcp_seq tcp_iss
; /* tcp initial send seq # */
246 u_int32_t tcp_now
; /* for RFC 1323 timestamps */
250 struct socket
*udp_last_so
;
254 struct tftp_session tftp_sessions
[TFTP_SESSIONS_MAX
];
259 extern Slirp
*slirp_instance
;
262 #define NULL (void *)0
266 void if_start(Slirp
*);
268 void if_start(struct ttys
*);
272 # define vsprintf vsprintf_len
273 # define sprintf sprintf_len
274 extern int vsprintf_len(char *, const char *, va_list);
275 extern int sprintf_len(char *, const char *, ...);
278 #ifdef DECLARE_SPRINTF
280 extern int vsprintf(char *, const char *, va_list);
282 extern int vfprintf(FILE *, const char *, va_list);
285 #ifndef HAVE_STRERROR
286 extern char *strerror(int error
);
290 char *index(const char *, int);
293 #ifndef HAVE_GETHOSTID
294 long gethostid(void);
297 void lprint(const char *, ...);
303 #define DEFAULT_BAUD 115200
305 #define SO_OPTIONS DO_KEEPALIVE
306 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
309 int cksum(struct mbuf
*m
, int len
);
312 void if_init(Slirp
*);
313 void if_output(struct socket
*, struct mbuf
*);
316 void ip_init(Slirp
*);
317 void ip_input(struct mbuf
*);
318 void ip_slowtimo(Slirp
*);
319 void ip_stripoptions(register struct mbuf
*, struct mbuf
*);
322 int ip_output(struct socket
*, struct mbuf
*);
325 void tcp_input(register struct mbuf
*, int, struct socket
*);
326 int tcp_mss(register struct tcpcb
*, u_int
);
329 int tcp_output(register struct tcpcb
*);
330 void tcp_setpersist(register struct tcpcb
*);
333 void tcp_init(Slirp
*);
334 void tcp_template(struct tcpcb
*);
335 void tcp_respond(struct tcpcb
*, register struct tcpiphdr
*, register struct mbuf
*, tcp_seq
, tcp_seq
, int);
336 struct tcpcb
* tcp_newtcpcb(struct socket
*);
337 struct tcpcb
* tcp_close(register struct tcpcb
*);
338 void tcp_sockclosed(struct tcpcb
*);
339 int tcp_fconnect(struct socket
*);
340 void tcp_connect(struct socket
*);
341 int tcp_attach(struct socket
*);
342 u_int8_t
tcp_tos(struct socket
*);
343 int tcp_emu(struct socket
*, struct mbuf
*);
344 int tcp_ctl(struct socket
*);
345 struct tcpcb
*tcp_drop(struct tcpcb
*tp
, int err
);
348 #define MIN_MRU MINMRU
349 #define MAX_MRU MAXMRU
352 #define MAX_MRU 16384
356 #define min(x,y) ((x) < (y) ? (x) : (y))
357 #define max(x,y) ((x) > (y) ? (x) : (y))
362 #define errno (WSAGetLastError())