4 #include "slirp_config.h"
11 # include <winsock2.h>
12 # include <ws2tcpip.h>
13 # include <sys/timeb.h>
14 # include <iphlpapi.h>
17 # define ioctlsocket ioctl
18 # define closesocket(s) close(s)
19 # if !defined(__HAIKU__)
24 #ifdef HAVE_SYS_BITYPES_H
25 # include <sys/bitypes.h>
37 #define memmove(x, y, z) bcopy(y, x, z)
40 #if TIME_WITH_SYS_TIME
42 # ifdef HAVE_SYS_TIME_H
56 #include <netinet/in.h>
57 #include <arpa/inet.h>
60 /* Systems lacking strdup() definition in <string.h>. */
62 char *strdup(const char *);
65 /* Systems lacking malloc() definition in <stdlib.h>. */
66 #if defined(ultrix) || defined(hcx)
67 void *malloc(size_t arg
);
71 #ifndef NO_UNIX_SOCKETS
74 #ifdef HAVE_SYS_SIGNAL_H
75 # include <sys/signal.h>
78 #include <sys/socket.h>
81 #if defined(HAVE_SYS_IOCTL_H)
82 # include <sys/ioctl.h>
85 #ifdef HAVE_SYS_SELECT_H
86 # include <sys/select.h>
89 #ifdef HAVE_SYS_WAIT_H
90 # include <sys/wait.h>
93 #ifdef HAVE_SYS_FILIO_H
94 # include <sys/filio.h>
98 #include <ppp/slirppp.h>
107 /* Avoid conflicting with the libc insque() and remque(), which
108 have different prototypes. */
109 #define insque slirp_insque
110 #define remque slirp_remque
112 #ifdef HAVE_SYS_STROPTS_H
113 #include <sys/stropts.h>
118 #include "qemu/queue.h"
119 #include "qemu/sockets.h"
122 #include "libslirp.h"
125 #include "tcp_timer.h"
137 #include "ppp/pppd.h"
144 #define ARPOP_REQUEST 1 /* ARP request */
145 #define ARPOP_REPLY 2 /* ARP reply */
148 unsigned char h_dest
[ETH_ALEN
]; /* destination eth addr */
149 unsigned char h_source
[ETH_ALEN
]; /* source ether addr */
150 unsigned short h_proto
; /* packet type ID field */
154 unsigned short ar_hrd
; /* format of hardware address */
155 unsigned short ar_pro
; /* format of protocol address */
156 unsigned char ar_hln
; /* length of hardware address */
157 unsigned char ar_pln
; /* length of protocol address */
158 unsigned short ar_op
; /* ARP opcode (command) */
161 * Ethernet looks like this : This bit is variable sized however...
163 unsigned char ar_sha
[ETH_ALEN
]; /* sender hardware address */
164 uint32_t ar_sip
; /* sender IP address */
165 unsigned char ar_tha
[ETH_ALEN
]; /* target hardware address */
166 uint32_t ar_tip
; /* target IP address */
169 #define ARP_TABLE_SIZE 16
171 typedef struct ArpTable
{
172 struct arphdr table
[ARP_TABLE_SIZE
];
176 void arp_table_add(Slirp
*slirp
, uint32_t ip_addr
, uint8_t ethaddr
[ETH_ALEN
]);
178 bool arp_table_search(Slirp
*slirp
, uint32_t ip_addr
,
179 uint8_t out_ethaddr
[ETH_ALEN
]);
182 QTAILQ_ENTRY(Slirp
) entry
;
187 /* virtual network configuration */
188 struct in_addr vnetwork_addr
;
189 struct in_addr vnetwork_mask
;
190 struct in_addr vhost_addr
;
191 struct in_addr vdhcp_startaddr
;
192 struct in_addr vnameserver_addr
;
194 struct in_addr client_ipaddr
;
195 char client_hostname
[33];
198 struct ex_list
*exec_list
;
201 struct mbuf m_freelist
, m_usedlist
;
205 struct mbuf if_fastq
; /* fast queue (for interactive data) */
206 struct mbuf if_batchq
; /* queue for non-interactive data */
207 struct mbuf
*next_m
; /* pointer to next mbuf to output */
208 bool if_start_busy
; /* avoid if_start recursion */
211 struct ipq ipq
; /* ip reass. queue */
212 uint16_t ip_id
; /* ip packet ctr, for ids */
214 /* bootp/dhcp states */
215 BOOTPClient bootp_clients
[NB_BOOTP_CLIENTS
];
216 char *bootp_filename
;
217 size_t vdnssearch_len
;
222 struct socket
*tcp_last_so
;
223 tcp_seq tcp_iss
; /* tcp initial send seq # */
224 uint32_t tcp_now
; /* for RFC 1323 timestamps */
228 struct socket
*udp_last_so
;
232 struct socket
*icmp_last_so
;
236 struct tftp_session tftp_sessions
[TFTP_SESSIONS_MAX
];
243 extern Slirp
*slirp_instance
;
246 #define NULL (void *)0
250 void if_start(Slirp
*);
252 void if_start(struct ttys
*);
255 #ifndef HAVE_STRERROR
256 char *strerror(int error
);
260 char *index(const char *, int);
263 #ifndef HAVE_GETHOSTID
264 long gethostid(void);
271 #define DEFAULT_BAUD 115200
273 #define SO_OPTIONS DO_KEEPALIVE
274 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
277 int translate_dnssearch(Slirp
*s
, const char ** names
);
280 int cksum(struct mbuf
*m
, int len
);
283 void if_init(Slirp
*);
284 void if_output(struct socket
*, struct mbuf
*);
287 void ip_init(Slirp
*);
288 void ip_cleanup(Slirp
*);
289 void ip_input(struct mbuf
*);
290 void ip_slowtimo(Slirp
*);
291 void ip_stripoptions(register struct mbuf
*, struct mbuf
*);
294 int ip_output(struct socket
*, struct mbuf
*);
297 void tcp_input(register struct mbuf
*, int, struct socket
*);
298 int tcp_mss(register struct tcpcb
*, u_int
);
301 int tcp_output(register struct tcpcb
*);
302 void tcp_setpersist(register struct tcpcb
*);
305 void tcp_init(Slirp
*);
306 void tcp_cleanup(Slirp
*);
307 void tcp_template(struct tcpcb
*);
308 void tcp_respond(struct tcpcb
*, register struct tcpiphdr
*, register struct mbuf
*, tcp_seq
, tcp_seq
, int);
309 struct tcpcb
* tcp_newtcpcb(struct socket
*);
310 struct tcpcb
* tcp_close(register struct tcpcb
*);
311 void tcp_sockclosed(struct tcpcb
*);
312 int tcp_fconnect(struct socket
*, unsigned short af
);
313 void tcp_connect(struct socket
*);
314 int tcp_attach(struct socket
*);
315 uint8_t tcp_tos(struct socket
*);
316 int tcp_emu(struct socket
*, struct mbuf
*);
317 int tcp_ctl(struct socket
*);
318 struct tcpcb
*tcp_drop(struct tcpcb
*tp
, int err
);
321 #define MIN_MRU MINMRU
322 #define MAX_MRU MAXMRU
325 #define MAX_MRU 16384
329 #define min(x,y) ((x) < (y) ? (x) : (y))
330 #define max(x,y) ((x) > (y) ? (x) : (y))
335 #define errno (WSAGetLastError())