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>
19 # define ioctlsocket ioctl
20 # define closesocket(s) close(s)
21 # if !defined(__HAIKU__)
26 #include <sys/types.h>
27 #ifdef HAVE_SYS_BITYPES_H
28 # include <sys/bitypes.h>
45 #define memmove(x, y, z) bcopy(y, x, z)
48 #if TIME_WITH_SYS_TIME
49 # include <sys/time.h>
52 # ifdef HAVE_SYS_TIME_H
53 # include <sys/time.h>
70 #include <netinet/in.h>
71 #include <arpa/inet.h>
74 /* Systems lacking strdup() definition in <string.h>. */
76 char *strdup(const char *);
79 /* Systems lacking malloc() definition in <stdlib.h>. */
80 #if defined(ultrix) || defined(hcx)
81 void *malloc(size_t arg
);
86 #ifndef NO_UNIX_SOCKETS
90 #ifdef HAVE_SYS_SIGNAL_H
91 # include <sys/signal.h>
94 #include <sys/socket.h>
97 #if defined(HAVE_SYS_IOCTL_H)
98 # include <sys/ioctl.h>
101 #ifdef HAVE_SYS_SELECT_H
102 # include <sys/select.h>
105 #ifdef HAVE_SYS_WAIT_H
106 # include <sys/wait.h>
109 #ifdef HAVE_SYS_FILIO_H
110 # include <sys/filio.h>
114 #include <ppp/slirppp.h>
123 #include <sys/stat.h>
125 /* Avoid conflicting with the libc insque() and remque(), which
126 have different prototypes. */
127 #define insque slirp_insque
128 #define remque slirp_remque
130 #ifdef HAVE_SYS_STROPTS_H
131 #include <sys/stropts.h>
136 #include "qemu/queue.h"
137 #include "qemu/sockets.h"
140 #include "libslirp.h"
143 #include "tcp_timer.h"
155 #include "ppp/pppd.h"
162 #define ARPOP_REQUEST 1 /* ARP request */
163 #define ARPOP_REPLY 2 /* ARP reply */
166 unsigned char h_dest
[ETH_ALEN
]; /* destination eth addr */
167 unsigned char h_source
[ETH_ALEN
]; /* source ether addr */
168 unsigned short h_proto
; /* packet type ID field */
172 unsigned short ar_hrd
; /* format of hardware address */
173 unsigned short ar_pro
; /* format of protocol address */
174 unsigned char ar_hln
; /* length of hardware address */
175 unsigned char ar_pln
; /* length of protocol address */
176 unsigned short ar_op
; /* ARP opcode (command) */
179 * Ethernet looks like this : This bit is variable sized however...
181 unsigned char ar_sha
[ETH_ALEN
]; /* sender hardware address */
182 uint32_t ar_sip
; /* sender IP address */
183 unsigned char ar_tha
[ETH_ALEN
]; /* target hardware address */
184 uint32_t ar_tip
; /* target IP address */
187 #define ARP_TABLE_SIZE 16
189 typedef struct ArpTable
{
190 struct arphdr table
[ARP_TABLE_SIZE
];
194 void arp_table_add(Slirp
*slirp
, uint32_t ip_addr
, uint8_t ethaddr
[ETH_ALEN
]);
196 bool arp_table_search(Slirp
*slirp
, uint32_t ip_addr
,
197 uint8_t out_ethaddr
[ETH_ALEN
]);
200 QTAILQ_ENTRY(Slirp
) entry
;
205 /* virtual network configuration */
206 struct in_addr vnetwork_addr
;
207 struct in_addr vnetwork_mask
;
208 struct in_addr vhost_addr
;
209 struct in_addr vdhcp_startaddr
;
210 struct in_addr vnameserver_addr
;
212 struct in_addr client_ipaddr
;
213 char client_hostname
[33];
216 struct ex_list
*exec_list
;
219 struct mbuf m_freelist
, m_usedlist
;
223 struct mbuf if_fastq
; /* fast queue (for interactive data) */
224 struct mbuf if_batchq
; /* queue for non-interactive data */
225 struct mbuf
*next_m
; /* pointer to next mbuf to output */
226 bool if_start_busy
; /* avoid if_start recursion */
229 struct ipq ipq
; /* ip reass. queue */
230 uint16_t ip_id
; /* ip packet ctr, for ids */
232 /* bootp/dhcp states */
233 BOOTPClient bootp_clients
[NB_BOOTP_CLIENTS
];
234 char *bootp_filename
;
235 size_t vdnssearch_len
;
240 struct socket
*tcp_last_so
;
241 tcp_seq tcp_iss
; /* tcp initial send seq # */
242 uint32_t tcp_now
; /* for RFC 1323 timestamps */
246 struct socket
*udp_last_so
;
250 struct socket
*icmp_last_so
;
254 struct tftp_session tftp_sessions
[TFTP_SESSIONS_MAX
];
261 extern Slirp
*slirp_instance
;
264 #define NULL (void *)0
268 void if_start(Slirp
*);
270 void if_start(struct ttys
*);
273 #ifndef HAVE_STRERROR
274 char *strerror(int error
);
278 char *index(const char *, int);
281 #ifndef HAVE_GETHOSTID
282 long gethostid(void);
289 #define DEFAULT_BAUD 115200
291 #define SO_OPTIONS DO_KEEPALIVE
292 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
295 int translate_dnssearch(Slirp
*s
, const char ** names
);
298 int cksum(struct mbuf
*m
, int len
);
301 void if_init(Slirp
*);
302 void if_output(struct socket
*, struct mbuf
*);
305 void ip_init(Slirp
*);
306 void ip_cleanup(Slirp
*);
307 void ip_input(struct mbuf
*);
308 void ip_slowtimo(Slirp
*);
309 void ip_stripoptions(register struct mbuf
*, struct mbuf
*);
312 int ip_output(struct socket
*, struct mbuf
*);
315 void tcp_input(register struct mbuf
*, int, struct socket
*);
316 int tcp_mss(register struct tcpcb
*, u_int
);
319 int tcp_output(register struct tcpcb
*);
320 void tcp_setpersist(register struct tcpcb
*);
323 void tcp_init(Slirp
*);
324 void tcp_cleanup(Slirp
*);
325 void tcp_template(struct tcpcb
*);
326 void tcp_respond(struct tcpcb
*, register struct tcpiphdr
*, register struct mbuf
*, tcp_seq
, tcp_seq
, int);
327 struct tcpcb
* tcp_newtcpcb(struct socket
*);
328 struct tcpcb
* tcp_close(register struct tcpcb
*);
329 void tcp_sockclosed(struct tcpcb
*);
330 int tcp_fconnect(struct socket
*);
331 void tcp_connect(struct socket
*);
332 int tcp_attach(struct socket
*);
333 uint8_t tcp_tos(struct socket
*);
334 int tcp_emu(struct socket
*, struct mbuf
*);
335 int tcp_ctl(struct socket
*);
336 struct tcpcb
*tcp_drop(struct tcpcb
*tp
, int err
);
339 #define MIN_MRU MINMRU
340 #define MAX_MRU MAXMRU
343 #define MAX_MRU 16384
347 #define min(x,y) ((x) < (y) ? (x) : (y))
348 #define max(x,y) ((x) > (y) ? (x) : (y))
353 #define errno (WSAGetLastError())