]> git.proxmox.com Git - qemu.git/blame - slirp/slirp.h
vhost build fix for i386
[qemu.git] / slirp / slirp.h
CommitLineData
f0cbd3ec
FB
1#ifndef __COMMON_H__
2#define __COMMON_H__
3
5fa0ab8f 4#include "config-host.h"
f0cbd3ec
FB
5#include "slirp_config.h"
6
379ff53d
FB
7#ifdef _WIN32
8# include <inttypes.h>
9
379ff53d
FB
10typedef char *caddr_t;
11
34444131 12# include <windows.h>
379ff53d 13# include <winsock2.h>
116842ee 14# include <ws2tcpip.h>
379ff53d
FB
15# include <sys/timeb.h>
16# include <iphlpapi.h>
17
18# define EWOULDBLOCK WSAEWOULDBLOCK
19# define EINPROGRESS WSAEINPROGRESS
20# define ENOTCONN WSAENOTCONN
21# define EHOSTUNREACH WSAEHOSTUNREACH
22# define ENETUNREACH WSAENETUNREACH
23# define ECONNREFUSED WSAECONNREFUSED
24#else
25# define ioctlsocket ioctl
26# define closesocket(s) close(s)
4a2b39d3
AF
27# if !defined(__HAIKU__)
28# define O_BINARY 0
29# endif
379ff53d
FB
30#endif
31
f0cbd3ec
FB
32#include <sys/types.h>
33#ifdef HAVE_SYS_BITYPES_H
34# include <sys/bitypes.h>
35#endif
36
170c6f87
FB
37#include <sys/time.h>
38
f0cbd3ec
FB
39#ifdef HAVE_UNISTD_H
40# include <unistd.h>
41#endif
42
43#ifdef HAVE_STDLIB_H
44# include <stdlib.h>
45#endif
46
47#include <stdio.h>
48#include <errno.h>
49
50#ifndef HAVE_MEMMOVE
51#define memmove(x, y, z) bcopy(y, x, z)
52#endif
53
54#if TIME_WITH_SYS_TIME
55# include <sys/time.h>
56# include <time.h>
57#else
eb38c52c 58# ifdef HAVE_SYS_TIME_H
f0cbd3ec
FB
59# include <sys/time.h>
60# else
61# include <time.h>
62# endif
63#endif
64
65#ifdef HAVE_STRING_H
66# include <string.h>
67#else
68# include <strings.h>
69#endif
70
379ff53d 71#ifndef _WIN32
f0cbd3ec 72#include <sys/uio.h>
379ff53d 73#endif
f0cbd3ec 74
379ff53d 75#ifndef _WIN32
f0cbd3ec
FB
76#include <netinet/in.h>
77#include <arpa/inet.h>
379ff53d 78#endif
f0cbd3ec 79
f0cbd3ec
FB
80/* Systems lacking strdup() definition in <string.h>. */
81#if defined(ultrix)
6cb9c6d3 82char *strdup(const char *);
f0cbd3ec
FB
83#endif
84
85/* Systems lacking malloc() definition in <stdlib.h>. */
86#if defined(ultrix) || defined(hcx)
6cb9c6d3
BS
87void *malloc(size_t arg);
88void free(void *ptr);
f0cbd3ec
FB
89#endif
90
91#ifndef HAVE_INET_ATON
6cb9c6d3 92int inet_aton(const char *cp, struct in_addr *ia);
f0cbd3ec
FB
93#endif
94
95#include <fcntl.h>
96#ifndef NO_UNIX_SOCKETS
97#include <sys/un.h>
98#endif
99#include <signal.h>
100#ifdef HAVE_SYS_SIGNAL_H
101# include <sys/signal.h>
102#endif
379ff53d 103#ifndef _WIN32
f0cbd3ec 104#include <sys/socket.h>
379ff53d 105#endif
f0cbd3ec 106
ee2654ac 107#if defined(HAVE_SYS_IOCTL_H)
f0cbd3ec 108# include <sys/ioctl.h>
f0cbd3ec
FB
109#endif
110
f0cbd3ec
FB
111#ifdef HAVE_SYS_SELECT_H
112# include <sys/select.h>
113#endif
114
115#ifdef HAVE_SYS_WAIT_H
116# include <sys/wait.h>
117#endif
118
119#ifdef HAVE_SYS_FILIO_H
120# include <sys/filio.h>
121#endif
122
123#ifdef USE_PPP
124#include <ppp/slirppp.h>
125#endif
126
127#ifdef __STDC__
128#include <stdarg.h>
129#else
130#include <varargs.h>
131#endif
132
133#include <sys/stat.h>
134
135/* Avoid conflicting with the libc insque() and remque(), which
136 have different prototypes. */
137#define insque slirp_insque
138#define remque slirp_remque
139
140#ifdef HAVE_SYS_STROPTS_H
141#include <sys/stropts.h>
142#endif
143
144#include "debug.h"
145
72cf2d4f 146#include "qemu-queue.h"
b1c99fcd 147
460fec67 148#include "libslirp.h"
f0cbd3ec
FB
149#include "ip.h"
150#include "tcp.h"
151#include "tcp_timer.h"
152#include "tcp_var.h"
153#include "tcpip.h"
154#include "udp.h"
e6d43cfb 155#include "ip_icmp.h"
f0cbd3ec
FB
156#include "mbuf.h"
157#include "sbuf.h"
158#include "socket.h"
159#include "if.h"
160#include "main.h"
161#include "misc.h"
f0cbd3ec
FB
162#ifdef USE_PPP
163#include "ppp/pppd.h"
164#include "ppp/ppp.h"
165#endif
166
167#include "bootp.h"
c7f74643 168#include "tftp.h"
460fec67 169
40ff6d7e
KW
170/* osdep.c */
171int qemu_socket(int domain, int type, int protocol);
172
173
460fec67 174struct Slirp {
72cf2d4f 175 QTAILQ_ENTRY(Slirp) entry;
b1c99fcd 176
460fec67
JK
177 /* virtual network configuration */
178 struct in_addr vnetwork_addr;
179 struct in_addr vnetwork_mask;
180 struct in_addr vhost_addr;
181 struct in_addr vdhcp_startaddr;
182 struct in_addr vnameserver_addr;
183
184 /* ARP cache for the guest IP addresses (XXX: allow many entries) */
185 uint8_t client_ethaddr[6];
186
187 struct in_addr client_ipaddr;
188 char client_hostname[33];
189
190 int restricted;
191 struct timeval tt;
192 struct ex_list *exec_list;
193
194 /* mbuf states */
195 struct mbuf m_freelist, m_usedlist;
196 int mbuf_alloced;
197
198 /* if states */
199 int if_queued; /* number of packets queued so far */
200 struct mbuf if_fastq; /* fast queue (for interactive data) */
201 struct mbuf if_batchq; /* queue for non-interactive data */
202 struct mbuf *next_m; /* pointer to next mbuf to output */
203
204 /* ip states */
205 struct ipq ipq; /* ip reass. queue */
b6dce92e 206 uint16_t ip_id; /* ip packet ctr, for ids */
460fec67
JK
207
208 /* bootp/dhcp states */
209 BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
210 char *bootp_filename;
211
212 /* tcp states */
213 struct socket tcb;
214 struct socket *tcp_last_so;
215 tcp_seq tcp_iss; /* tcp initial send seq # */
b6dce92e 216 uint32_t tcp_now; /* for RFC 1323 timestamps */
460fec67
JK
217
218 /* udp states */
219 struct socket udb;
220 struct socket *udp_last_so;
221
e6d43cfb
JK
222 /* icmp states */
223 struct socket icmp;
224 struct socket *icmp_last_so;
225
460fec67
JK
226 /* tftp states */
227 char *tftp_prefix;
228 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
229
9f8bd042 230 void *opaque;
460fec67
JK
231};
232
ad0d8c4c 233extern Slirp *slirp_instance;
f0cbd3ec 234
f0cbd3ec
FB
235#ifndef NULL
236#define NULL (void *)0
237#endif
238
239#ifndef FULL_BOLT
6cb9c6d3 240void if_start(Slirp *);
f0cbd3ec 241#else
6cb9c6d3 242void if_start(struct ttys *);
f0cbd3ec
FB
243#endif
244
f0cbd3ec 245#ifndef HAVE_STRERROR
64b85a8f 246 char *strerror(int error);
f0cbd3ec
FB
247#endif
248
249#ifndef HAVE_INDEX
6cb9c6d3 250 char *index(const char *, int);
f0cbd3ec
FB
251#endif
252
253#ifndef HAVE_GETHOSTID
6cb9c6d3 254 long gethostid(void);
f0cbd3ec
FB
255#endif
256
8b7968f7 257void lprint(const char *, ...) GCC_FMT_ATTR(1, 2);
f0cbd3ec 258
379ff53d 259#ifndef _WIN32
f0cbd3ec 260#include <netdb.h>
379ff53d 261#endif
f0cbd3ec
FB
262
263#define DEFAULT_BAUD 115200
264
9634d903
BS
265#define SO_OPTIONS DO_KEEPALIVE
266#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
267
f0cbd3ec
FB
268/* cksum.c */
269int cksum(struct mbuf *m, int len);
270
271/* if.c */
6cb9c6d3
BS
272void if_init(Slirp *);
273void if_output(struct socket *, struct mbuf *);
f0cbd3ec
FB
274
275/* ip_input.c */
6cb9c6d3
BS
276void ip_init(Slirp *);
277void ip_input(struct mbuf *);
278void ip_slowtimo(Slirp *);
279void ip_stripoptions(register struct mbuf *, struct mbuf *);
f0cbd3ec
FB
280
281/* ip_output.c */
6cb9c6d3 282int ip_output(struct socket *, struct mbuf *);
f0cbd3ec
FB
283
284/* tcp_input.c */
6cb9c6d3
BS
285void tcp_input(register struct mbuf *, int, struct socket *);
286int tcp_mss(register struct tcpcb *, u_int);
f0cbd3ec
FB
287
288/* tcp_output.c */
6cb9c6d3
BS
289int tcp_output(register struct tcpcb *);
290void tcp_setpersist(register struct tcpcb *);
f0cbd3ec
FB
291
292/* tcp_subr.c */
6cb9c6d3
BS
293void tcp_init(Slirp *);
294void tcp_template(struct tcpcb *);
295void tcp_respond(struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int);
296struct tcpcb * tcp_newtcpcb(struct socket *);
297struct tcpcb * tcp_close(register struct tcpcb *);
298void tcp_sockclosed(struct tcpcb *);
299int tcp_fconnect(struct socket *);
300void tcp_connect(struct socket *);
301int tcp_attach(struct socket *);
b6dce92e 302uint8_t tcp_tos(struct socket *);
6cb9c6d3
BS
303int tcp_emu(struct socket *, struct mbuf *);
304int tcp_ctl(struct socket *);
9fafc9ea 305struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
f0cbd3ec
FB
306
307#ifdef USE_PPP
308#define MIN_MRU MINMRU
309#define MAX_MRU MAXMRU
310#else
311#define MIN_MRU 128
312#define MAX_MRU 16384
313#endif
314
379ff53d
FB
315#ifndef _WIN32
316#define min(x,y) ((x) < (y) ? (x) : (y))
317#define max(x,y) ((x) > (y) ? (x) : (y))
318#endif
319
02d2c54c 320#ifdef _WIN32
ef6ff6b7 321#undef errno
02d2c54c
FB
322#define errno (WSAGetLastError())
323#endif
324
f0cbd3ec 325#endif