Statistics
| Branch: | Revision:

root / slirp / slirp.h @ 8b7968f7

History | View | Annotate | Download (6.6 kB)

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