]> git.proxmox.com Git - qemu.git/blob - slirp/slirp.h
vnc: rename vnc-encoding-* vnc-enc-*
[qemu.git] / slirp / slirp.h
1 #ifndef __COMMON_H__
2 #define __COMMON_H__
3
4 #include "config-host.h"
5 #include "slirp_config.h"
6
7 #ifdef _WIN32
8 # include <inttypes.h>
9
10 typedef char *caddr_t;
11
12 # include <windows.h>
13 # include <winsock2.h>
14 # include <ws2tcpip.h>
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)
27 # define O_BINARY 0
28 #endif
29
30 #include <sys/types.h>
31 #ifdef HAVE_SYS_BITYPES_H
32 # include <sys/bitypes.h>
33 #endif
34
35 #include <sys/time.h>
36
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
56 # ifdef HAVE_SYS_TIME_H
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
69 #ifndef _WIN32
70 #include <sys/uio.h>
71 #endif
72
73 #ifndef _WIN32
74 #include <netinet/in.h>
75 #include <arpa/inet.h>
76 #endif
77
78 /* Systems lacking strdup() definition in <string.h>. */
79 #if defined(ultrix)
80 char *strdup(const char *);
81 #endif
82
83 /* Systems lacking malloc() definition in <stdlib.h>. */
84 #if defined(ultrix) || defined(hcx)
85 void *malloc(size_t arg);
86 void free(void *ptr);
87 #endif
88
89 #ifndef HAVE_INET_ATON
90 int inet_aton(const char *cp, struct in_addr *ia);
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
101 #ifndef _WIN32
102 #include <sys/socket.h>
103 #endif
104
105 #if defined(HAVE_SYS_IOCTL_H)
106 # include <sys/ioctl.h>
107 #endif
108
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
144 #include "qemu-queue.h"
145
146 #include "libslirp.h"
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"
153 #include "mbuf.h"
154 #include "sbuf.h"
155 #include "socket.h"
156 #include "if.h"
157 #include "main.h"
158 #include "misc.h"
159 #ifdef USE_PPP
160 #include "ppp/pppd.h"
161 #include "ppp/ppp.h"
162 #endif
163
164 #include "bootp.h"
165 #include "tftp.h"
166
167 /* osdep.c */
168 int qemu_socket(int domain, int type, int protocol);
169
170
171 struct Slirp {
172 QTAILQ_ENTRY(Slirp) entry;
173
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 */
203 uint16_t ip_id; /* ip packet ctr, for ids */
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 # */
213 uint32_t tcp_now; /* for RFC 1323 timestamps */
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
223 void *opaque;
224 };
225
226 extern Slirp *slirp_instance;
227
228 #ifndef NULL
229 #define NULL (void *)0
230 #endif
231
232 #ifndef FULL_BOLT
233 void if_start(Slirp *);
234 #else
235 void if_start(struct ttys *);
236 #endif
237
238 #ifdef BAD_SPRINTF
239 # define vsprintf vsprintf_len
240 # define sprintf sprintf_len
241 extern int vsprintf_len(char *, const char *, va_list);
242 extern int sprintf_len(char *, const char *, ...);
243 #endif
244
245 #ifdef DECLARE_SPRINTF
246 # ifndef BAD_SPRINTF
247 extern int vsprintf(char *, const char *, va_list);
248 # endif
249 extern int vfprintf(FILE *, const char *, va_list);
250 #endif
251
252 #ifndef HAVE_STRERROR
253 extern char *strerror(int error);
254 #endif
255
256 #ifndef HAVE_INDEX
257 char *index(const char *, int);
258 #endif
259
260 #ifndef HAVE_GETHOSTID
261 long gethostid(void);
262 #endif
263
264 void lprint(const char *, ...);
265
266 #ifndef _WIN32
267 #include <netdb.h>
268 #endif
269
270 #define DEFAULT_BAUD 115200
271
272 #define SO_OPTIONS DO_KEEPALIVE
273 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
274
275 /* cksum.c */
276 int cksum(struct mbuf *m, int len);
277
278 /* if.c */
279 void if_init(Slirp *);
280 void if_output(struct socket *, struct mbuf *);
281
282 /* ip_input.c */
283 void ip_init(Slirp *);
284 void ip_input(struct mbuf *);
285 void ip_slowtimo(Slirp *);
286 void ip_stripoptions(register struct mbuf *, struct mbuf *);
287
288 /* ip_output.c */
289 int ip_output(struct socket *, struct mbuf *);
290
291 /* tcp_input.c */
292 void tcp_input(register struct mbuf *, int, struct socket *);
293 int tcp_mss(register struct tcpcb *, u_int);
294
295 /* tcp_output.c */
296 int tcp_output(register struct tcpcb *);
297 void tcp_setpersist(register struct tcpcb *);
298
299 /* tcp_subr.c */
300 void tcp_init(Slirp *);
301 void tcp_template(struct tcpcb *);
302 void tcp_respond(struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int);
303 struct tcpcb * tcp_newtcpcb(struct socket *);
304 struct tcpcb * tcp_close(register struct tcpcb *);
305 void tcp_sockclosed(struct tcpcb *);
306 int tcp_fconnect(struct socket *);
307 void tcp_connect(struct socket *);
308 int tcp_attach(struct socket *);
309 uint8_t tcp_tos(struct socket *);
310 int tcp_emu(struct socket *, struct mbuf *);
311 int tcp_ctl(struct socket *);
312 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
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
322 #ifndef _WIN32
323 #define min(x,y) ((x) < (y) ? (x) : (y))
324 #define max(x,y) ((x) > (y) ? (x) : (y))
325 #endif
326
327 #ifdef _WIN32
328 #undef errno
329 #define errno (WSAGetLastError())
330 #endif
331
332 #endif