4 #include "slirp_config.h"
11 # include <winsock2.h>
12 # include <ws2tcpip.h>
13 # include <sys/timeb.h>
14 # include <iphlpapi.h>
17 # if !defined(__HAIKU__)
22 #ifdef HAVE_SYS_BITYPES_H
23 # include <sys/bitypes.h>
35 #define memmove(x, y, z) bcopy(y, x, z)
38 #if TIME_WITH_SYS_TIME
40 # ifdef HAVE_SYS_TIME_H
54 #include <netinet/in.h>
55 #include <arpa/inet.h>
58 /* Systems lacking strdup() definition in <string.h>. */
60 char *strdup(const char *);
63 /* Systems lacking malloc() definition in <stdlib.h>. */
64 #if defined(ultrix) || defined(hcx)
65 void *malloc(size_t arg
);
69 #ifndef NO_UNIX_SOCKETS
72 #ifdef HAVE_SYS_SIGNAL_H
73 # include <sys/signal.h>
76 #include <sys/socket.h>
79 #if defined(HAVE_SYS_IOCTL_H)
80 # include <sys/ioctl.h>
83 #ifdef HAVE_SYS_SELECT_H
84 # include <sys/select.h>
87 #ifdef HAVE_SYS_WAIT_H
88 # include <sys/wait.h>
91 #ifdef HAVE_SYS_FILIO_H
92 # include <sys/filio.h>
96 #include <ppp/slirppp.h>
105 /* Avoid conflicting with the libc insque() and remque(), which
106 have different prototypes. */
107 #define insque slirp_insque
108 #define remque slirp_remque
110 #ifdef HAVE_SYS_STROPTS_H
111 #include <sys/stropts.h>
118 #include "qemu/queue.h"
119 #include "qemu/sockets.h"
122 #include "libslirp.h"
126 #include "tcp_timer.h"
131 #include "ip6_icmp.h"
139 #include "ppp/pppd.h"
146 #define ARPOP_REQUEST 1 /* ARP request */
147 #define ARPOP_REPLY 2 /* ARP reply */
150 unsigned char h_dest
[ETH_ALEN
]; /* destination eth addr */
151 unsigned char h_source
[ETH_ALEN
]; /* source ether addr */
152 unsigned short h_proto
; /* packet type ID field */
156 unsigned short ar_hrd
; /* format of hardware address */
157 unsigned short ar_pro
; /* format of protocol address */
158 unsigned char ar_hln
; /* length of hardware address */
159 unsigned char ar_pln
; /* length of protocol address */
160 unsigned short ar_op
; /* ARP opcode (command) */
163 * Ethernet looks like this : This bit is variable sized however...
165 unsigned char ar_sha
[ETH_ALEN
]; /* sender hardware address */
166 uint32_t ar_sip
; /* sender IP address */
167 unsigned char ar_tha
[ETH_ALEN
]; /* target hardware address */
168 uint32_t ar_tip
; /* target IP address */
171 #define ARP_TABLE_SIZE 16
173 typedef struct ArpTable
{
174 struct arphdr table
[ARP_TABLE_SIZE
];
178 void arp_table_add(Slirp
*slirp
, uint32_t ip_addr
, uint8_t ethaddr
[ETH_ALEN
]);
180 bool arp_table_search(Slirp
*slirp
, uint32_t ip_addr
,
181 uint8_t out_ethaddr
[ETH_ALEN
]);
184 unsigned char eth_addr
[ETH_ALEN
]; /* sender hardware address */
185 struct in6_addr ip_addr
; /* sender IP address */
188 #define NDP_TABLE_SIZE 16
190 typedef struct NdpTable
{
191 struct ndpentry table
[NDP_TABLE_SIZE
];
195 void ndp_table_add(Slirp
*slirp
, struct in6_addr ip_addr
,
196 uint8_t ethaddr
[ETH_ALEN
]);
197 bool ndp_table_search(Slirp
*slirp
, struct in6_addr ip_addr
,
198 uint8_t out_ethaddr
[ETH_ALEN
]);
201 QTAILQ_ENTRY(Slirp
) entry
;
206 /* virtual network configuration */
207 struct in_addr vnetwork_addr
;
208 struct in_addr vnetwork_mask
;
209 struct in_addr vhost_addr
;
210 struct in6_addr vprefix_addr6
;
212 struct in6_addr vhost_addr6
;
213 struct in_addr vdhcp_startaddr
;
214 struct in_addr vnameserver_addr
;
216 struct in_addr client_ipaddr
;
217 char client_hostname
[33];
220 struct ex_list
*exec_list
;
223 struct mbuf m_freelist
, m_usedlist
;
227 struct mbuf if_fastq
; /* fast queue (for interactive data) */
228 struct mbuf if_batchq
; /* queue for non-interactive data */
229 struct mbuf
*next_m
; /* pointer to next mbuf to output */
230 bool if_start_busy
; /* avoid if_start recursion */
233 struct ipq ipq
; /* ip reass. queue */
234 uint16_t ip_id
; /* ip packet ctr, for ids */
236 /* bootp/dhcp states */
237 BOOTPClient bootp_clients
[NB_BOOTP_CLIENTS
];
238 char *bootp_filename
;
239 size_t vdnssearch_len
;
244 struct socket
*tcp_last_so
;
245 tcp_seq tcp_iss
; /* tcp initial send seq # */
246 uint32_t tcp_now
; /* for RFC 1323 timestamps */
250 struct socket
*udp_last_so
;
254 struct socket
*icmp_last_so
;
258 struct tftp_session tftp_sessions
[TFTP_SESSIONS_MAX
];
269 extern Slirp
*slirp_instance
;
272 #define NULL (void *)0
276 void if_start(Slirp
*);
278 void if_start(struct ttys
*);
281 #ifndef HAVE_STRERROR
282 char *strerror(int error
);
286 char *index(const char *, int);
289 #ifndef HAVE_GETHOSTID
290 long gethostid(void);
297 #define DEFAULT_BAUD 115200
299 #define SO_OPTIONS DO_KEEPALIVE
300 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
303 int translate_dnssearch(Slirp
*s
, const char ** names
);
306 int cksum(struct mbuf
*m
, int len
);
307 int ip6_cksum(struct mbuf
*m
);
310 void if_init(Slirp
*);
311 void if_output(struct socket
*, struct mbuf
*);
314 void ip_init(Slirp
*);
315 void ip_cleanup(Slirp
*);
316 void ip_input(struct mbuf
*);
317 void ip_slowtimo(Slirp
*);
318 void ip_stripoptions(register struct mbuf
*, struct mbuf
*);
321 int ip_output(struct socket
*, struct mbuf
*);
324 void ip6_init(Slirp
*);
325 void ip6_cleanup(Slirp
*);
326 void ip6_input(struct mbuf
*);
329 int ip6_output(struct socket
*, struct mbuf
*, int fast
);
332 void tcp_input(register struct mbuf
*, int, struct socket
*);
333 int tcp_mss(register struct tcpcb
*, u_int
);
336 int tcp_output(register struct tcpcb
*);
337 void tcp_setpersist(register struct tcpcb
*);
340 void tcp_init(Slirp
*);
341 void tcp_cleanup(Slirp
*);
342 void tcp_template(struct tcpcb
*);
343 void tcp_respond(struct tcpcb
*, register struct tcpiphdr
*, register struct mbuf
*, tcp_seq
, tcp_seq
, int);
344 struct tcpcb
* tcp_newtcpcb(struct socket
*);
345 struct tcpcb
* tcp_close(register struct tcpcb
*);
346 void tcp_sockclosed(struct tcpcb
*);
347 int tcp_fconnect(struct socket
*, unsigned short af
);
348 void tcp_connect(struct socket
*);
349 int tcp_attach(struct socket
*);
350 uint8_t tcp_tos(struct socket
*);
351 int tcp_emu(struct socket
*, struct mbuf
*);
352 int tcp_ctl(struct socket
*);
353 struct tcpcb
*tcp_drop(struct tcpcb
*tp
, int err
);
356 #define MIN_MRU MINMRU
357 #define MAX_MRU MAXMRU
360 #define MAX_MRU 16384
364 #define min(x,y) ((x) < (y) ? (x) : (y))
365 #define max(x,y) ((x) > (y) ? (x) : (y))
370 #define errno (WSAGetLastError())