]> git.proxmox.com Git - mirror_qemu.git/blame - slirp/slirp.h
all: Clean up includes
[mirror_qemu.git] / slirp / slirp.h
CommitLineData
f0cbd3ec
FB
1#ifndef __COMMON_H__
2#define __COMMON_H__
3
f0cbd3ec
FB
4#include "slirp_config.h"
5
379ff53d 6#ifdef _WIN32
379ff53d 7
379ff53d
FB
8typedef char *caddr_t;
9
34444131 10# include <windows.h>
379ff53d 11# include <winsock2.h>
116842ee 12# include <ws2tcpip.h>
379ff53d
FB
13# include <sys/timeb.h>
14# include <iphlpapi.h>
15
379ff53d
FB
16#else
17# define ioctlsocket ioctl
18# define closesocket(s) close(s)
4a2b39d3
AF
19# if !defined(__HAIKU__)
20# define O_BINARY 0
21# endif
379ff53d
FB
22#endif
23
f0cbd3ec
FB
24#ifdef HAVE_SYS_BITYPES_H
25# include <sys/bitypes.h>
26#endif
27
170c6f87 28
f0cbd3ec 29#ifdef HAVE_UNISTD_H
f0cbd3ec
FB
30#endif
31
32#ifdef HAVE_STDLIB_H
f0cbd3ec
FB
33#endif
34
f0cbd3ec
FB
35
36#ifndef HAVE_MEMMOVE
37#define memmove(x, y, z) bcopy(y, x, z)
38#endif
39
40#if TIME_WITH_SYS_TIME
f0cbd3ec 41#else
eb38c52c 42# ifdef HAVE_SYS_TIME_H
f0cbd3ec 43# else
f0cbd3ec
FB
44# endif
45#endif
46
47#ifdef HAVE_STRING_H
f0cbd3ec 48#else
f0cbd3ec
FB
49#endif
50
379ff53d 51#ifndef _WIN32
f0cbd3ec 52#include <sys/uio.h>
379ff53d 53#endif
f0cbd3ec 54
379ff53d 55#ifndef _WIN32
f0cbd3ec
FB
56#include <netinet/in.h>
57#include <arpa/inet.h>
379ff53d 58#endif
f0cbd3ec 59
f0cbd3ec
FB
60/* Systems lacking strdup() definition in <string.h>. */
61#if defined(ultrix)
6cb9c6d3 62char *strdup(const char *);
f0cbd3ec
FB
63#endif
64
65/* Systems lacking malloc() definition in <stdlib.h>. */
66#if defined(ultrix) || defined(hcx)
6cb9c6d3
BS
67void *malloc(size_t arg);
68void free(void *ptr);
f0cbd3ec
FB
69#endif
70
f0cbd3ec
FB
71#ifndef NO_UNIX_SOCKETS
72#include <sys/un.h>
73#endif
f0cbd3ec
FB
74#ifdef HAVE_SYS_SIGNAL_H
75# include <sys/signal.h>
76#endif
379ff53d 77#ifndef _WIN32
f0cbd3ec 78#include <sys/socket.h>
379ff53d 79#endif
f0cbd3ec 80
ee2654ac 81#if defined(HAVE_SYS_IOCTL_H)
f0cbd3ec 82# include <sys/ioctl.h>
f0cbd3ec
FB
83#endif
84
f0cbd3ec
FB
85#ifdef HAVE_SYS_SELECT_H
86# include <sys/select.h>
87#endif
88
89#ifdef HAVE_SYS_WAIT_H
90# include <sys/wait.h>
91#endif
92
93#ifdef HAVE_SYS_FILIO_H
94# include <sys/filio.h>
95#endif
96
97#ifdef USE_PPP
98#include <ppp/slirppp.h>
99#endif
100
101#ifdef __STDC__
f0cbd3ec
FB
102#else
103#include <varargs.h>
104#endif
105
f0cbd3ec
FB
106
107/* Avoid conflicting with the libc insque() and remque(), which
108 have different prototypes. */
109#define insque slirp_insque
110#define remque slirp_remque
111
112#ifdef HAVE_SYS_STROPTS_H
113#include <sys/stropts.h>
114#endif
115
116#include "debug.h"
117
1de7afc9
PB
118#include "qemu/queue.h"
119#include "qemu/sockets.h"
9c7ffe26 120#include "net/eth.h"
b1c99fcd 121
460fec67 122#include "libslirp.h"
f0cbd3ec
FB
123#include "ip.h"
124#include "tcp.h"
125#include "tcp_timer.h"
126#include "tcp_var.h"
127#include "tcpip.h"
128#include "udp.h"
e6d43cfb 129#include "ip_icmp.h"
f0cbd3ec
FB
130#include "mbuf.h"
131#include "sbuf.h"
132#include "socket.h"
133#include "if.h"
134#include "main.h"
135#include "misc.h"
f0cbd3ec
FB
136#ifdef USE_PPP
137#include "ppp/pppd.h"
138#include "ppp/ppp.h"
139#endif
140
141#include "bootp.h"
c7f74643 142#include "tftp.h"
460fec67 143
1a0ca1e1
FC
144#define ARPOP_REQUEST 1 /* ARP request */
145#define ARPOP_REPLY 2 /* ARP reply */
146
147struct ethhdr {
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 */
151};
152
153struct arphdr {
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) */
159
160 /*
161 * Ethernet looks like this : This bit is variable sized however...
162 */
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 */
541dc0d4 167} QEMU_PACKED;
1a0ca1e1
FC
168
169#define ARP_TABLE_SIZE 16
170
171typedef struct ArpTable {
172 struct arphdr table[ARP_TABLE_SIZE];
173 int next_victim;
174} ArpTable;
175
5a371a2e 176void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
1a0ca1e1 177
5a371a2e 178bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
1a0ca1e1 179 uint8_t out_ethaddr[ETH_ALEN]);
40ff6d7e 180
460fec67 181struct Slirp {
72cf2d4f 182 QTAILQ_ENTRY(Slirp) entry;
fe0ff43c
LPF
183 u_int time_fasttimo;
184 u_int last_slowtimo;
185 bool do_slowtimo;
b1c99fcd 186
460fec67
JK
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;
193
460fec67
JK
194 struct in_addr client_ipaddr;
195 char client_hostname[33];
196
197 int restricted;
460fec67
JK
198 struct ex_list *exec_list;
199
200 /* mbuf states */
201 struct mbuf m_freelist, m_usedlist;
202 int mbuf_alloced;
203
204 /* if states */
460fec67
JK
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 */
953e7f54 208 bool if_start_busy; /* avoid if_start recursion */
460fec67
JK
209
210 /* ip states */
211 struct ipq ipq; /* ip reass. queue */
b6dce92e 212 uint16_t ip_id; /* ip packet ctr, for ids */
460fec67
JK
213
214 /* bootp/dhcp states */
215 BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
216 char *bootp_filename;
63d2960b
KS
217 size_t vdnssearch_len;
218 uint8_t *vdnssearch;
460fec67
JK
219
220 /* tcp states */
221 struct socket tcb;
222 struct socket *tcp_last_so;
223 tcp_seq tcp_iss; /* tcp initial send seq # */
b6dce92e 224 uint32_t tcp_now; /* for RFC 1323 timestamps */
460fec67
JK
225
226 /* udp states */
227 struct socket udb;
228 struct socket *udp_last_so;
229
e6d43cfb
JK
230 /* icmp states */
231 struct socket icmp;
232 struct socket *icmp_last_so;
233
460fec67
JK
234 /* tftp states */
235 char *tftp_prefix;
236 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
237
1a0ca1e1
FC
238 ArpTable arp_table;
239
9f8bd042 240 void *opaque;
460fec67
JK
241};
242
ad0d8c4c 243extern Slirp *slirp_instance;
f0cbd3ec 244
f0cbd3ec
FB
245#ifndef NULL
246#define NULL (void *)0
247#endif
248
249#ifndef FULL_BOLT
6cb9c6d3 250void if_start(Slirp *);
f0cbd3ec 251#else
6cb9c6d3 252void if_start(struct ttys *);
f0cbd3ec
FB
253#endif
254
f0cbd3ec 255#ifndef HAVE_STRERROR
64b85a8f 256 char *strerror(int error);
f0cbd3ec
FB
257#endif
258
259#ifndef HAVE_INDEX
6cb9c6d3 260 char *index(const char *, int);
f0cbd3ec
FB
261#endif
262
263#ifndef HAVE_GETHOSTID
6cb9c6d3 264 long gethostid(void);
f0cbd3ec
FB
265#endif
266
379ff53d 267#ifndef _WIN32
f0cbd3ec 268#include <netdb.h>
379ff53d 269#endif
f0cbd3ec
FB
270
271#define DEFAULT_BAUD 115200
272
9634d903
BS
273#define SO_OPTIONS DO_KEEPALIVE
274#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
275
63d2960b
KS
276/* dnssearch.c */
277int translate_dnssearch(Slirp *s, const char ** names);
278
f0cbd3ec
FB
279/* cksum.c */
280int cksum(struct mbuf *m, int len);
281
282/* if.c */
6cb9c6d3
BS
283void if_init(Slirp *);
284void if_output(struct socket *, struct mbuf *);
f0cbd3ec
FB
285
286/* ip_input.c */
6cb9c6d3 287void ip_init(Slirp *);
a68adc22 288void ip_cleanup(Slirp *);
6cb9c6d3
BS
289void ip_input(struct mbuf *);
290void ip_slowtimo(Slirp *);
291void ip_stripoptions(register struct mbuf *, struct mbuf *);
f0cbd3ec
FB
292
293/* ip_output.c */
6cb9c6d3 294int ip_output(struct socket *, struct mbuf *);
f0cbd3ec
FB
295
296/* tcp_input.c */
6cb9c6d3
BS
297void tcp_input(register struct mbuf *, int, struct socket *);
298int tcp_mss(register struct tcpcb *, u_int);
f0cbd3ec
FB
299
300/* tcp_output.c */
6cb9c6d3
BS
301int tcp_output(register struct tcpcb *);
302void tcp_setpersist(register struct tcpcb *);
f0cbd3ec
FB
303
304/* tcp_subr.c */
6cb9c6d3 305void tcp_init(Slirp *);
a68adc22 306void tcp_cleanup(Slirp *);
6cb9c6d3
BS
307void tcp_template(struct tcpcb *);
308void tcp_respond(struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int);
309struct tcpcb * tcp_newtcpcb(struct socket *);
310struct tcpcb * tcp_close(register struct tcpcb *);
311void tcp_sockclosed(struct tcpcb *);
cc573a69 312int tcp_fconnect(struct socket *, unsigned short af);
6cb9c6d3
BS
313void tcp_connect(struct socket *);
314int tcp_attach(struct socket *);
b6dce92e 315uint8_t tcp_tos(struct socket *);
6cb9c6d3
BS
316int tcp_emu(struct socket *, struct mbuf *);
317int tcp_ctl(struct socket *);
9fafc9ea 318struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
f0cbd3ec
FB
319
320#ifdef USE_PPP
321#define MIN_MRU MINMRU
322#define MAX_MRU MAXMRU
323#else
324#define MIN_MRU 128
325#define MAX_MRU 16384
326#endif
327
379ff53d
FB
328#ifndef _WIN32
329#define min(x,y) ((x) < (y) ? (x) : (y))
330#define max(x,y) ((x) > (y) ? (x) : (y))
331#endif
332
02d2c54c 333#ifdef _WIN32
ef6ff6b7 334#undef errno
02d2c54c
FB
335#define errno (WSAGetLastError())
336#endif
337
f0cbd3ec 338#endif