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