4 #include "config-host.h"
5 #include "slirp_config.h"
10 typedef char *caddr_t
;
13 # include <winsock2.h>
14 # include <ws2tcpip.h>
15 # include <sys/timeb.h>
16 # include <iphlpapi.h>
18 # define EWOULDBLOCK WSAEWOULDBLOCK
19 # define EINPROGRESS WSAEINPROGRESS
20 # define ENOTCONN WSAENOTCONN
21 # define EHOSTUNREACH WSAEHOSTUNREACH
22 # define ENETUNREACH WSAENETUNREACH
23 # define ECONNREFUSED WSAECONNREFUSED
25 # define ioctlsocket ioctl
26 # define closesocket(s) close(s)
27 # if !defined(__HAIKU__)
32 #include <sys/types.h>
33 #ifdef HAVE_SYS_BITYPES_H
34 # include <sys/bitypes.h>
51 #define memmove(x, y, z) bcopy(y, x, z)
54 #if TIME_WITH_SYS_TIME
55 # include <sys/time.h>
58 # ifdef HAVE_SYS_TIME_H
59 # include <sys/time.h>
76 #include <netinet/in.h>
77 #include <arpa/inet.h>
80 /* Systems lacking strdup() definition in <string.h>. */
82 char *strdup(const char *);
85 /* Systems lacking malloc() definition in <stdlib.h>. */
86 #if defined(ultrix) || defined(hcx)
87 void *malloc(size_t arg
);
91 #ifndef HAVE_INET_ATON
92 int inet_aton(const char *cp
, struct in_addr
*ia
);
96 #ifndef NO_UNIX_SOCKETS
100 #ifdef HAVE_SYS_SIGNAL_H
101 # include <sys/signal.h>
104 #include <sys/socket.h>
107 #if defined(HAVE_SYS_IOCTL_H)
108 # include <sys/ioctl.h>
111 #ifdef HAVE_SYS_SELECT_H
112 # include <sys/select.h>
115 #ifdef HAVE_SYS_WAIT_H
116 # include <sys/wait.h>
119 #ifdef HAVE_SYS_FILIO_H
120 # include <sys/filio.h>
124 #include <ppp/slirppp.h>
133 #include <sys/stat.h>
135 /* Avoid conflicting with the libc insque() and remque(), which
136 have different prototypes. */
137 #define insque slirp_insque
138 #define remque slirp_remque
140 #ifdef HAVE_SYS_STROPTS_H
141 #include <sys/stropts.h>
146 #include "qemu-queue.h"
148 #include "libslirp.h"
151 #include "tcp_timer.h"
163 #include "ppp/pppd.h"
171 int qemu_socket(int domain
, int type
, int protocol
);
175 QTAILQ_ENTRY(Slirp
) entry
;
177 /* virtual network configuration */
178 struct in_addr vnetwork_addr
;
179 struct in_addr vnetwork_mask
;
180 struct in_addr vhost_addr
;
181 struct in_addr vdhcp_startaddr
;
182 struct in_addr vnameserver_addr
;
184 /* ARP cache for the guest IP addresses (XXX: allow many entries) */
185 uint8_t client_ethaddr
[6];
187 struct in_addr client_ipaddr
;
188 char client_hostname
[33];
192 struct ex_list
*exec_list
;
195 struct mbuf m_freelist
, m_usedlist
;
199 int if_queued
; /* number of packets queued so far */
200 struct mbuf if_fastq
; /* fast queue (for interactive data) */
201 struct mbuf if_batchq
; /* queue for non-interactive data */
202 struct mbuf
*next_m
; /* pointer to next mbuf to output */
205 struct ipq ipq
; /* ip reass. queue */
206 uint16_t ip_id
; /* ip packet ctr, for ids */
208 /* bootp/dhcp states */
209 BOOTPClient bootp_clients
[NB_BOOTP_CLIENTS
];
210 char *bootp_filename
;
214 struct socket
*tcp_last_so
;
215 tcp_seq tcp_iss
; /* tcp initial send seq # */
216 uint32_t tcp_now
; /* for RFC 1323 timestamps */
220 struct socket
*udp_last_so
;
224 struct socket
*icmp_last_so
;
228 struct tftp_session tftp_sessions
[TFTP_SESSIONS_MAX
];
233 extern Slirp
*slirp_instance
;
236 #define NULL (void *)0
240 void if_start(Slirp
*);
242 void if_start(struct ttys
*);
245 #ifndef HAVE_STRERROR
246 char *strerror(int error
);
250 char *index(const char *, int);
253 #ifndef HAVE_GETHOSTID
254 long gethostid(void);
257 void lprint(const char *, ...) GCC_FMT_ATTR(1, 2);
263 #define DEFAULT_BAUD 115200
265 #define SO_OPTIONS DO_KEEPALIVE
266 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
269 int cksum(struct mbuf
*m
, int len
);
272 void if_init(Slirp
*);
273 void if_output(struct socket
*, struct mbuf
*);
276 void ip_init(Slirp
*);
277 void ip_input(struct mbuf
*);
278 void ip_slowtimo(Slirp
*);
279 void ip_stripoptions(register struct mbuf
*, struct mbuf
*);
282 int ip_output(struct socket
*, struct mbuf
*);
285 void tcp_input(register struct mbuf
*, int, struct socket
*);
286 int tcp_mss(register struct tcpcb
*, u_int
);
289 int tcp_output(register struct tcpcb
*);
290 void tcp_setpersist(register struct tcpcb
*);
293 void tcp_init(Slirp
*);
294 void tcp_template(struct tcpcb
*);
295 void tcp_respond(struct tcpcb
*, register struct tcpiphdr
*, register struct mbuf
*, tcp_seq
, tcp_seq
, int);
296 struct tcpcb
* tcp_newtcpcb(struct socket
*);
297 struct tcpcb
* tcp_close(register struct tcpcb
*);
298 void tcp_sockclosed(struct tcpcb
*);
299 int tcp_fconnect(struct socket
*);
300 void tcp_connect(struct socket
*);
301 int tcp_attach(struct socket
*);
302 uint8_t tcp_tos(struct socket
*);
303 int tcp_emu(struct socket
*, struct mbuf
*);
304 int tcp_ctl(struct socket
*);
305 struct tcpcb
*tcp_drop(struct tcpcb
*tp
, int err
);
308 #define MIN_MRU MINMRU
309 #define MAX_MRU MAXMRU
312 #define MAX_MRU 16384
316 #define min(x,y) ((x) < (y) ? (x) : (y))
317 #define max(x,y) ((x) > (y) ? (x) : (y))
322 #define errno (WSAGetLastError())