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)
30 #include <sys/types.h>
31 #ifdef HAVE_SYS_BITYPES_H
32 # include <sys/bitypes.h>
49 #define memmove(x, y, z) bcopy(y, x, z)
52 #if TIME_WITH_SYS_TIME
53 # include <sys/time.h>
56 # ifdef HAVE_SYS_TIME_H
57 # include <sys/time.h>
74 #include <netinet/in.h>
75 #include <arpa/inet.h>
78 /* Systems lacking strdup() definition in <string.h>. */
80 char *strdup(const char *);
83 /* Systems lacking malloc() definition in <stdlib.h>. */
84 #if defined(ultrix) || defined(hcx)
85 void *malloc(size_t arg
);
89 #ifndef HAVE_INET_ATON
90 int inet_aton(const char *cp
, struct in_addr
*ia
);
94 #ifndef NO_UNIX_SOCKETS
98 #ifdef HAVE_SYS_SIGNAL_H
99 # include <sys/signal.h>
102 #include <sys/socket.h>
105 #if defined(HAVE_SYS_IOCTL_H)
106 # include <sys/ioctl.h>
109 #ifdef HAVE_SYS_SELECT_H
110 # include <sys/select.h>
113 #ifdef HAVE_SYS_WAIT_H
114 # include <sys/wait.h>
117 #ifdef HAVE_SYS_FILIO_H
118 # include <sys/filio.h>
122 #include <ppp/slirppp.h>
131 #include <sys/stat.h>
133 /* Avoid conflicting with the libc insque() and remque(), which
134 have different prototypes. */
135 #define insque slirp_insque
136 #define remque slirp_remque
138 #ifdef HAVE_SYS_STROPTS_H
139 #include <sys/stropts.h>
144 #include "qemu-queue.h"
146 #include "libslirp.h"
149 #include "tcp_timer.h"
160 #include "ppp/pppd.h"
168 int qemu_socket(int domain
, int type
, int protocol
);
172 QTAILQ_ENTRY(Slirp
) entry
;
174 /* virtual network configuration */
175 struct in_addr vnetwork_addr
;
176 struct in_addr vnetwork_mask
;
177 struct in_addr vhost_addr
;
178 struct in_addr vdhcp_startaddr
;
179 struct in_addr vnameserver_addr
;
181 /* ARP cache for the guest IP addresses (XXX: allow many entries) */
182 uint8_t client_ethaddr
[6];
184 struct in_addr client_ipaddr
;
185 char client_hostname
[33];
189 struct ex_list
*exec_list
;
192 struct mbuf m_freelist
, m_usedlist
;
196 int if_queued
; /* number of packets queued so far */
197 struct mbuf if_fastq
; /* fast queue (for interactive data) */
198 struct mbuf if_batchq
; /* queue for non-interactive data */
199 struct mbuf
*next_m
; /* pointer to next mbuf to output */
202 struct ipq ipq
; /* ip reass. queue */
203 uint16_t ip_id
; /* ip packet ctr, for ids */
205 /* bootp/dhcp states */
206 BOOTPClient bootp_clients
[NB_BOOTP_CLIENTS
];
207 char *bootp_filename
;
211 struct socket
*tcp_last_so
;
212 tcp_seq tcp_iss
; /* tcp initial send seq # */
213 uint32_t tcp_now
; /* for RFC 1323 timestamps */
217 struct socket
*udp_last_so
;
221 struct tftp_session tftp_sessions
[TFTP_SESSIONS_MAX
];
226 extern Slirp
*slirp_instance
;
229 #define NULL (void *)0
233 void if_start(Slirp
*);
235 void if_start(struct ttys
*);
239 # define vsprintf vsprintf_len
240 # define sprintf sprintf_len
241 extern int vsprintf_len(char *, const char *, va_list);
242 extern int sprintf_len(char *, const char *, ...);
245 #ifdef DECLARE_SPRINTF
247 extern int vsprintf(char *, const char *, va_list);
249 extern int vfprintf(FILE *, const char *, va_list);
252 #ifndef HAVE_STRERROR
253 extern char *strerror(int error
);
257 char *index(const char *, int);
260 #ifndef HAVE_GETHOSTID
261 long gethostid(void);
264 void lprint(const char *, ...);
270 #define DEFAULT_BAUD 115200
272 #define SO_OPTIONS DO_KEEPALIVE
273 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
276 int cksum(struct mbuf
*m
, int len
);
279 void if_init(Slirp
*);
280 void if_output(struct socket
*, struct mbuf
*);
283 void ip_init(Slirp
*);
284 void ip_input(struct mbuf
*);
285 void ip_slowtimo(Slirp
*);
286 void ip_stripoptions(register struct mbuf
*, struct mbuf
*);
289 int ip_output(struct socket
*, struct mbuf
*);
292 void tcp_input(register struct mbuf
*, int, struct socket
*);
293 int tcp_mss(register struct tcpcb
*, u_int
);
296 int tcp_output(register struct tcpcb
*);
297 void tcp_setpersist(register struct tcpcb
*);
300 void tcp_init(Slirp
*);
301 void tcp_template(struct tcpcb
*);
302 void tcp_respond(struct tcpcb
*, register struct tcpiphdr
*, register struct mbuf
*, tcp_seq
, tcp_seq
, int);
303 struct tcpcb
* tcp_newtcpcb(struct socket
*);
304 struct tcpcb
* tcp_close(register struct tcpcb
*);
305 void tcp_sockclosed(struct tcpcb
*);
306 int tcp_fconnect(struct socket
*);
307 void tcp_connect(struct socket
*);
308 int tcp_attach(struct socket
*);
309 uint8_t tcp_tos(struct socket
*);
310 int tcp_emu(struct socket
*, struct mbuf
*);
311 int tcp_ctl(struct socket
*);
312 struct tcpcb
*tcp_drop(struct tcpcb
*tp
, int err
);
315 #define MIN_MRU MINMRU
316 #define MAX_MRU MAXMRU
319 #define MAX_MRU 16384
323 #define min(x,y) ((x) < (y) ? (x) : (y))
324 #define max(x,y) ((x) > (y) ? (x) : (y))
329 #define errno (WSAGetLastError())