1 /* SPDX-License-Identifier: BSD-3-Clause */
7 /* as defined in sdkddkver.h */
9 #define _WIN32_WINNT 0x0600 /* Vista */
11 /* reduces the number of implicitly included headers */
12 #ifndef WIN32_LEAN_AND_MEAN
13 #define WIN32_LEAN_AND_MEAN
16 # include <winsock2.h>
18 # include <ws2tcpip.h>
19 # include <sys/timeb.h>
20 # include <iphlpapi.h>
23 # if !defined(__HAIKU__)
30 #include <netinet/in.h>
31 #include <arpa/inet.h>
32 #include <sys/socket.h>
33 #include <sys/ioctl.h>
37 # include <sys/filio.h>
40 /* Avoid conflicting with the libc insque() and remque(), which
41 have different prototypes. */
42 #define insque slirp_insque
43 #define remque slirp_remque
44 #define quehead slirp_quehead
54 #include "tcp_timer.h"
70 #define ARPOP_REQUEST 1 /* ARP request */
71 #define ARPOP_REPLY 2 /* ARP reply */
74 unsigned char h_dest
[ETH_ALEN
]; /* destination eth addr */
75 unsigned char h_source
[ETH_ALEN
]; /* source ether addr */
76 unsigned short h_proto
; /* packet type ID field */
80 unsigned short ar_hrd
; /* format of hardware address */
81 unsigned short ar_pro
; /* format of protocol address */
82 unsigned char ar_hln
; /* length of hardware address */
83 unsigned char ar_pln
; /* length of protocol address */
84 unsigned short ar_op
; /* ARP opcode (command) */
87 * Ethernet looks like this : This bit is variable sized however...
89 unsigned char ar_sha
[ETH_ALEN
]; /* sender hardware address */
90 uint32_t ar_sip
; /* sender IP address */
91 unsigned char ar_tha
[ETH_ALEN
]; /* target hardware address */
92 uint32_t ar_tip
; /* target IP address */
95 #define ARP_TABLE_SIZE 16
97 typedef struct ArpTable
{
98 struct slirp_arphdr table
[ARP_TABLE_SIZE
];
102 void arp_table_add(Slirp
*slirp
, uint32_t ip_addr
, uint8_t ethaddr
[ETH_ALEN
]);
104 bool arp_table_search(Slirp
*slirp
, uint32_t ip_addr
,
105 uint8_t out_ethaddr
[ETH_ALEN
]);
108 unsigned char eth_addr
[ETH_ALEN
]; /* sender hardware address */
109 struct in6_addr ip_addr
; /* sender IP address */
112 #define NDP_TABLE_SIZE 16
114 typedef struct NdpTable
{
115 struct ndpentry table
[NDP_TABLE_SIZE
];
119 void ndp_table_add(Slirp
*slirp
, struct in6_addr ip_addr
,
120 uint8_t ethaddr
[ETH_ALEN
]);
121 bool ndp_table_search(Slirp
*slirp
, struct in6_addr ip_addr
,
122 uint8_t out_ethaddr
[ETH_ALEN
]);
125 QTAILQ_ENTRY(Slirp
) entry
;
126 unsigned time_fasttimo
;
127 unsigned last_slowtimo
;
130 bool in_enabled
, in6_enabled
;
132 /* virtual network configuration */
133 struct in_addr vnetwork_addr
;
134 struct in_addr vnetwork_mask
;
135 struct in_addr vhost_addr
;
136 struct in6_addr vprefix_addr6
;
138 struct in6_addr vhost_addr6
;
139 struct in_addr vdhcp_startaddr
;
140 struct in_addr vnameserver_addr
;
141 struct in6_addr vnameserver_addr6
;
143 struct in_addr client_ipaddr
;
144 char client_hostname
[33];
147 struct gfwd_list
*guestfwd_list
;
150 struct quehead m_freelist
;
151 struct quehead m_usedlist
;
155 struct quehead if_fastq
; /* fast queue (for interactive data) */
156 struct quehead if_batchq
; /* queue for non-interactive data */
157 bool if_start_busy
; /* avoid if_start recursion */
160 struct ipq ipq
; /* ip reass. queue */
161 uint16_t ip_id
; /* ip packet ctr, for ids */
163 /* bootp/dhcp states */
164 BOOTPClient bootp_clients
[NB_BOOTP_CLIENTS
];
165 char *bootp_filename
;
166 size_t vdnssearch_len
;
172 struct socket
*tcp_last_so
;
173 tcp_seq tcp_iss
; /* tcp initial send seq # */
174 uint32_t tcp_now
; /* for RFC 1323 timestamps */
178 struct socket
*udp_last_so
;
182 struct socket
*icmp_last_so
;
186 struct tftp_session tftp_sessions
[TFTP_SESSIONS_MAX
];
187 char *tftp_server_name
;
199 void if_start(Slirp
*);
201 int get_dns_addr(struct in_addr
*pdns_addr
);
202 int get_dns6_addr(struct in6_addr
*pdns6_addr
, uint32_t *scope_id
);
205 void ncsi_input(Slirp
*slirp
, const uint8_t *pkt
, int pkt_len
);
212 extern bool slirp_do_keepalive
;
214 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
217 int translate_dnssearch(Slirp
*s
, const char ** names
);
220 int cksum(struct mbuf
*m
, int len
);
221 int ip6_cksum(struct mbuf
*m
);
224 void if_init(Slirp
*);
225 void if_output(struct socket
*, struct mbuf
*);
228 void ip_init(Slirp
*);
229 void ip_cleanup(Slirp
*);
230 void ip_input(struct mbuf
*);
231 void ip_slowtimo(Slirp
*);
232 void ip_stripoptions(register struct mbuf
*, struct mbuf
*);
235 int ip_output(struct socket
*, struct mbuf
*);
238 void ip6_init(Slirp
*);
239 void ip6_cleanup(Slirp
*);
240 void ip6_input(struct mbuf
*);
243 int ip6_output(struct socket
*, struct mbuf
*, int fast
);
246 void tcp_input(register struct mbuf
*, int, struct socket
*, unsigned short af
);
247 int tcp_mss(register struct tcpcb
*, unsigned);
250 int tcp_output(register struct tcpcb
*);
251 void tcp_setpersist(register struct tcpcb
*);
254 void tcp_init(Slirp
*);
255 void tcp_cleanup(Slirp
*);
256 void tcp_template(struct tcpcb
*);
257 void tcp_respond(struct tcpcb
*, register struct tcpiphdr
*,
258 register struct mbuf
*, tcp_seq
, tcp_seq
, int, unsigned short);
259 struct tcpcb
* tcp_newtcpcb(struct socket
*);
260 struct tcpcb
* tcp_close(register struct tcpcb
*);
261 void tcp_sockclosed(struct tcpcb
*);
262 int tcp_fconnect(struct socket
*, unsigned short af
);
263 void tcp_connect(struct socket
*);
264 int tcp_attach(struct socket
*);
265 uint8_t tcp_tos(struct socket
*);
266 int tcp_emu(struct socket
*, struct mbuf
*);
267 int tcp_ctl(struct socket
*);
268 struct tcpcb
*tcp_drop(struct tcpcb
*tp
, int err
);
271 slirp_find_ctl_socket(Slirp
*slirp
, struct in_addr guest_addr
, int guest_port
);
273 void slirp_send_packet_all(Slirp
*slirp
, const void *buf
, size_t len
);