Statistics
| Branch: | Revision:

root / slirp / slirp.h @ 4dbc422b

History | View | Annotate | Download (6.5 kB)

1 f0cbd3ec bellard
#ifndef __COMMON_H__
2 f0cbd3ec bellard
#define __COMMON_H__
3 f0cbd3ec bellard
4 f0cbd3ec bellard
#define CONFIG_QEMU
5 f0cbd3ec bellard
6 31a60e22 blueswir1
//#define DEBUG 1
7 31a60e22 blueswir1
8 31a60e22 blueswir1
// Uncomment the following line to enable SLIRP statistics printing in Qemu
9 31a60e22 blueswir1
//#define LOG_ENABLED
10 31a60e22 blueswir1
11 31a60e22 blueswir1
#ifdef LOG_ENABLED
12 31a60e22 blueswir1
#define STAT(expr) expr
13 31a60e22 blueswir1
#else
14 31a60e22 blueswir1
#define STAT(expr) do { } while(0)
15 31a60e22 blueswir1
#endif
16 f0cbd3ec bellard
17 f0cbd3ec bellard
#ifndef CONFIG_QEMU
18 f0cbd3ec bellard
#include "version.h"
19 f0cbd3ec bellard
#endif
20 5fa0ab8f bellard
#include "config-host.h"
21 f0cbd3ec bellard
#include "slirp_config.h"
22 f0cbd3ec bellard
23 379ff53d bellard
#ifdef _WIN32
24 379ff53d bellard
# include <inttypes.h>
25 379ff53d bellard
26 379ff53d bellard
typedef uint8_t u_int8_t;
27 379ff53d bellard
typedef uint16_t u_int16_t;
28 379ff53d bellard
typedef uint32_t u_int32_t;
29 379ff53d bellard
typedef uint64_t u_int64_t;
30 379ff53d bellard
typedef char *caddr_t;
31 379ff53d bellard
32 34444131 bellard
# include <windows.h>
33 379ff53d bellard
# include <winsock2.h>
34 379ff53d bellard
# include <sys/timeb.h>
35 379ff53d bellard
# include <iphlpapi.h>
36 379ff53d bellard
37 379ff53d bellard
# define EWOULDBLOCK WSAEWOULDBLOCK
38 379ff53d bellard
# define EINPROGRESS WSAEINPROGRESS
39 379ff53d bellard
# define ENOTCONN WSAENOTCONN
40 379ff53d bellard
# define EHOSTUNREACH WSAEHOSTUNREACH
41 379ff53d bellard
# define ENETUNREACH WSAENETUNREACH
42 379ff53d bellard
# define ECONNREFUSED WSAECONNREFUSED
43 379ff53d bellard
#else
44 379ff53d bellard
# define ioctlsocket ioctl
45 379ff53d bellard
# define closesocket(s) close(s)
46 6d46bf8a bellard
# define O_BINARY 0
47 379ff53d bellard
#endif
48 379ff53d bellard
49 f0cbd3ec bellard
#include <sys/types.h>
50 f0cbd3ec bellard
#ifdef HAVE_SYS_BITYPES_H
51 f0cbd3ec bellard
# include <sys/bitypes.h>
52 f0cbd3ec bellard
#endif
53 f0cbd3ec bellard
54 170c6f87 bellard
#include <sys/time.h>
55 170c6f87 bellard
56 f0cbd3ec bellard
#ifdef NEED_TYPEDEFS
57 f0cbd3ec bellard
typedef char int8_t;
58 f0cbd3ec bellard
typedef unsigned char u_int8_t;
59 f0cbd3ec bellard
60 f0cbd3ec bellard
# if SIZEOF_SHORT == 2
61 f0cbd3ec bellard
    typedef short int16_t;
62 f0cbd3ec bellard
    typedef unsigned short u_int16_t;
63 f0cbd3ec bellard
# else
64 f0cbd3ec bellard
#  if SIZEOF_INT == 2
65 f0cbd3ec bellard
    typedef int int16_t;
66 f0cbd3ec bellard
    typedef unsigned int u_int16_t;
67 f0cbd3ec bellard
#  else
68 f0cbd3ec bellard
    #error Cannot find a type with sizeof() == 2
69 f0cbd3ec bellard
#  endif
70 f0cbd3ec bellard
# endif
71 f0cbd3ec bellard
72 f0cbd3ec bellard
# if SIZEOF_SHORT == 4
73 f0cbd3ec bellard
   typedef short int32_t;
74 f0cbd3ec bellard
   typedef unsigned short u_int32_t;
75 f0cbd3ec bellard
# else
76 f0cbd3ec bellard
#  if SIZEOF_INT == 4
77 f0cbd3ec bellard
    typedef int int32_t;
78 f0cbd3ec bellard
    typedef unsigned int u_int32_t;
79 f0cbd3ec bellard
#  else
80 f0cbd3ec bellard
    #error Cannot find a type with sizeof() == 4
81 f0cbd3ec bellard
#  endif
82 f0cbd3ec bellard
# endif
83 f0cbd3ec bellard
#endif /* NEED_TYPEDEFS */
84 f0cbd3ec bellard
85 f0cbd3ec bellard
#ifdef HAVE_UNISTD_H
86 f0cbd3ec bellard
# include <unistd.h>
87 f0cbd3ec bellard
#endif
88 f0cbd3ec bellard
89 f0cbd3ec bellard
#ifdef HAVE_STDLIB_H
90 f0cbd3ec bellard
# include <stdlib.h>
91 f0cbd3ec bellard
#endif
92 f0cbd3ec bellard
93 f0cbd3ec bellard
#include <stdio.h>
94 f0cbd3ec bellard
#include <errno.h>
95 f0cbd3ec bellard
96 f0cbd3ec bellard
#ifndef HAVE_MEMMOVE
97 f0cbd3ec bellard
#define memmove(x, y, z) bcopy(y, x, z)
98 f0cbd3ec bellard
#endif
99 f0cbd3ec bellard
100 f0cbd3ec bellard
#if TIME_WITH_SYS_TIME
101 f0cbd3ec bellard
# include <sys/time.h>
102 f0cbd3ec bellard
# include <time.h>
103 f0cbd3ec bellard
#else
104 f0cbd3ec bellard
# if HAVE_SYS_TIME_H
105 f0cbd3ec bellard
#  include <sys/time.h>
106 f0cbd3ec bellard
# else
107 f0cbd3ec bellard
#  include <time.h>
108 f0cbd3ec bellard
# endif
109 f0cbd3ec bellard
#endif
110 f0cbd3ec bellard
111 f0cbd3ec bellard
#ifdef HAVE_STRING_H
112 f0cbd3ec bellard
# include <string.h>
113 f0cbd3ec bellard
#else
114 f0cbd3ec bellard
# include <strings.h>
115 f0cbd3ec bellard
#endif
116 f0cbd3ec bellard
117 379ff53d bellard
#ifndef _WIN32
118 f0cbd3ec bellard
#include <sys/uio.h>
119 379ff53d bellard
#endif
120 f0cbd3ec bellard
121 f0cbd3ec bellard
#ifndef _P
122 f0cbd3ec bellard
#ifndef NO_PROTOTYPES
123 f0cbd3ec bellard
#  define   _P(x)   x
124 f0cbd3ec bellard
#else
125 f0cbd3ec bellard
#  define   _P(x)   ()
126 f0cbd3ec bellard
#endif
127 f0cbd3ec bellard
#endif
128 f0cbd3ec bellard
129 379ff53d bellard
#ifndef _WIN32
130 f0cbd3ec bellard
#include <netinet/in.h>
131 f0cbd3ec bellard
#include <arpa/inet.h>
132 379ff53d bellard
#endif
133 f0cbd3ec bellard
134 f0cbd3ec bellard
#ifdef GETTIMEOFDAY_ONE_ARG
135 f0cbd3ec bellard
#define gettimeofday(x, y) gettimeofday(x)
136 f0cbd3ec bellard
#endif
137 f0cbd3ec bellard
138 f0cbd3ec bellard
/* Systems lacking strdup() definition in <string.h>. */
139 f0cbd3ec bellard
#if defined(ultrix)
140 f0cbd3ec bellard
char *strdup _P((const char *));
141 f0cbd3ec bellard
#endif
142 f0cbd3ec bellard
143 f0cbd3ec bellard
/* Systems lacking malloc() definition in <stdlib.h>. */
144 f0cbd3ec bellard
#if defined(ultrix) || defined(hcx)
145 f0cbd3ec bellard
void *malloc _P((size_t arg));
146 f0cbd3ec bellard
void free _P((void *ptr));
147 f0cbd3ec bellard
#endif
148 f0cbd3ec bellard
149 f0cbd3ec bellard
#ifndef HAVE_INET_ATON
150 f0cbd3ec bellard
int inet_aton _P((const char *cp, struct in_addr *ia));
151 f0cbd3ec bellard
#endif
152 f0cbd3ec bellard
153 f0cbd3ec bellard
#include <fcntl.h>
154 f0cbd3ec bellard
#ifndef NO_UNIX_SOCKETS
155 f0cbd3ec bellard
#include <sys/un.h>
156 f0cbd3ec bellard
#endif
157 f0cbd3ec bellard
#include <signal.h>
158 f0cbd3ec bellard
#ifdef HAVE_SYS_SIGNAL_H
159 f0cbd3ec bellard
# include <sys/signal.h>
160 f0cbd3ec bellard
#endif
161 379ff53d bellard
#ifndef _WIN32
162 f0cbd3ec bellard
#include <sys/socket.h>
163 379ff53d bellard
#endif
164 f0cbd3ec bellard
165 ee2654ac bellard
#if defined(HAVE_SYS_IOCTL_H)
166 f0cbd3ec bellard
# include <sys/ioctl.h>
167 f0cbd3ec bellard
#endif
168 f0cbd3ec bellard
169 f0cbd3ec bellard
#ifdef HAVE_SYS_SELECT_H
170 f0cbd3ec bellard
# include <sys/select.h>
171 f0cbd3ec bellard
#endif
172 f0cbd3ec bellard
173 f0cbd3ec bellard
#ifdef HAVE_SYS_WAIT_H
174 f0cbd3ec bellard
# include <sys/wait.h>
175 f0cbd3ec bellard
#endif
176 f0cbd3ec bellard
177 f0cbd3ec bellard
#ifdef HAVE_SYS_FILIO_H
178 f0cbd3ec bellard
# include <sys/filio.h>
179 f0cbd3ec bellard
#endif
180 f0cbd3ec bellard
181 f0cbd3ec bellard
#ifdef USE_PPP
182 f0cbd3ec bellard
#include <ppp/slirppp.h>
183 f0cbd3ec bellard
#endif
184 f0cbd3ec bellard
185 f0cbd3ec bellard
#ifdef __STDC__
186 f0cbd3ec bellard
#include <stdarg.h>
187 f0cbd3ec bellard
#else
188 f0cbd3ec bellard
#include <varargs.h>
189 f0cbd3ec bellard
#endif
190 f0cbd3ec bellard
191 f0cbd3ec bellard
#include <sys/stat.h>
192 f0cbd3ec bellard
193 f0cbd3ec bellard
/* Avoid conflicting with the libc insque() and remque(), which
194 f0cbd3ec bellard
   have different prototypes. */
195 f0cbd3ec bellard
#define insque slirp_insque
196 f0cbd3ec bellard
#define remque slirp_remque
197 f0cbd3ec bellard
198 f0cbd3ec bellard
#ifdef HAVE_SYS_STROPTS_H
199 f0cbd3ec bellard
#include <sys/stropts.h>
200 f0cbd3ec bellard
#endif
201 f0cbd3ec bellard
202 f0cbd3ec bellard
#include "debug.h"
203 f0cbd3ec bellard
204 f0cbd3ec bellard
#include "ip.h"
205 f0cbd3ec bellard
#include "tcp.h"
206 f0cbd3ec bellard
#include "tcp_timer.h"
207 f0cbd3ec bellard
#include "tcp_var.h"
208 f0cbd3ec bellard
#include "tcpip.h"
209 f0cbd3ec bellard
#include "udp.h"
210 f0cbd3ec bellard
#include "icmp_var.h"
211 f0cbd3ec bellard
#include "mbuf.h"
212 f0cbd3ec bellard
#include "sbuf.h"
213 f0cbd3ec bellard
#include "socket.h"
214 f0cbd3ec bellard
#include "if.h"
215 f0cbd3ec bellard
#include "main.h"
216 f0cbd3ec bellard
#include "misc.h"
217 f0cbd3ec bellard
#include "ctl.h"
218 f0cbd3ec bellard
#ifdef USE_PPP
219 f0cbd3ec bellard
#include "ppp/pppd.h"
220 f0cbd3ec bellard
#include "ppp/ppp.h"
221 f0cbd3ec bellard
#endif
222 f0cbd3ec bellard
223 f0cbd3ec bellard
#include "bootp.h"
224 c7f74643 bellard
#include "tftp.h"
225 f0cbd3ec bellard
#include "libslirp.h"
226 f0cbd3ec bellard
227 f0cbd3ec bellard
extern struct ttys *ttys_unit[MAX_INTERFACES];
228 f0cbd3ec bellard
229 f0cbd3ec bellard
#ifndef NULL
230 f0cbd3ec bellard
#define NULL (void *)0
231 f0cbd3ec bellard
#endif
232 f0cbd3ec bellard
233 f0cbd3ec bellard
#ifndef FULL_BOLT
234 f0cbd3ec bellard
void if_start _P((void));
235 f0cbd3ec bellard
#else
236 f0cbd3ec bellard
void if_start _P((struct ttys *));
237 f0cbd3ec bellard
#endif
238 f0cbd3ec bellard
239 f0cbd3ec bellard
#ifdef BAD_SPRINTF
240 f0cbd3ec bellard
# define vsprintf vsprintf_len
241 f0cbd3ec bellard
# define sprintf sprintf_len
242 f0cbd3ec bellard
 extern int vsprintf_len _P((char *, const char *, va_list));
243 f0cbd3ec bellard
 extern int sprintf_len _P((char *, const char *, ...));
244 f0cbd3ec bellard
#endif
245 f0cbd3ec bellard
246 f0cbd3ec bellard
#ifdef DECLARE_SPRINTF
247 f0cbd3ec bellard
# ifndef BAD_SPRINTF
248 f0cbd3ec bellard
 extern int vsprintf _P((char *, const char *, va_list));
249 f0cbd3ec bellard
# endif
250 f0cbd3ec bellard
 extern int vfprintf _P((FILE *, const char *, va_list));
251 f0cbd3ec bellard
#endif
252 f0cbd3ec bellard
253 f0cbd3ec bellard
#ifndef HAVE_STRERROR
254 f0cbd3ec bellard
 extern char *strerror _P((int error));
255 f0cbd3ec bellard
#endif
256 f0cbd3ec bellard
257 f0cbd3ec bellard
#ifndef HAVE_INDEX
258 f0cbd3ec bellard
 char *index _P((const char *, int));
259 f0cbd3ec bellard
#endif
260 f0cbd3ec bellard
261 f0cbd3ec bellard
#ifndef HAVE_GETHOSTID
262 f0cbd3ec bellard
 long gethostid _P((void));
263 f0cbd3ec bellard
#endif
264 f0cbd3ec bellard
265 f0cbd3ec bellard
void lprint _P((const char *, ...));
266 f0cbd3ec bellard
267 f0cbd3ec bellard
#if SIZEOF_CHAR_P == 4
268 f0cbd3ec bellard
# define insque_32 insque
269 f0cbd3ec bellard
# define remque_32 remque
270 f0cbd3ec bellard
#else
271 f0cbd3ec bellard
 inline void insque_32 _P((void *, void *));
272 f0cbd3ec bellard
 inline void remque_32 _P((void *));
273 f0cbd3ec bellard
#endif
274 f0cbd3ec bellard
275 379ff53d bellard
#ifndef _WIN32
276 f0cbd3ec bellard
#include <netdb.h>
277 379ff53d bellard
#endif
278 f0cbd3ec bellard
279 f0cbd3ec bellard
#define DEFAULT_BAUD 115200
280 f0cbd3ec bellard
281 9634d903 blueswir1
#define SO_OPTIONS DO_KEEPALIVE
282 9634d903 blueswir1
#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
283 9634d903 blueswir1
284 f0cbd3ec bellard
/* cksum.c */
285 f0cbd3ec bellard
int cksum(struct mbuf *m, int len);
286 f0cbd3ec bellard
287 f0cbd3ec bellard
/* if.c */
288 f0cbd3ec bellard
void if_init _P((void));
289 f0cbd3ec bellard
void if_output _P((struct socket *, struct mbuf *));
290 f0cbd3ec bellard
291 f0cbd3ec bellard
/* ip_input.c */
292 f0cbd3ec bellard
void ip_init _P((void));
293 f0cbd3ec bellard
void ip_input _P((struct mbuf *));
294 f0cbd3ec bellard
void ip_slowtimo _P((void));
295 f0cbd3ec bellard
void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
296 f0cbd3ec bellard
297 f0cbd3ec bellard
/* ip_output.c */
298 f0cbd3ec bellard
int ip_output _P((struct socket *, struct mbuf *));
299 f0cbd3ec bellard
300 f0cbd3ec bellard
/* tcp_input.c */
301 f0cbd3ec bellard
void tcp_input _P((register struct mbuf *, int, struct socket *));
302 f0cbd3ec bellard
int tcp_mss _P((register struct tcpcb *, u_int));
303 f0cbd3ec bellard
304 f0cbd3ec bellard
/* tcp_output.c */
305 f0cbd3ec bellard
int tcp_output _P((register struct tcpcb *));
306 f0cbd3ec bellard
void tcp_setpersist _P((register struct tcpcb *));
307 f0cbd3ec bellard
308 f0cbd3ec bellard
/* tcp_subr.c */
309 f0cbd3ec bellard
void tcp_init _P((void));
310 f0cbd3ec bellard
void tcp_template _P((struct tcpcb *));
311 f0cbd3ec bellard
void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
312 f0cbd3ec bellard
struct tcpcb * tcp_newtcpcb _P((struct socket *));
313 f0cbd3ec bellard
struct tcpcb * tcp_close _P((register struct tcpcb *));
314 f0cbd3ec bellard
void tcp_sockclosed _P((struct tcpcb *));
315 f0cbd3ec bellard
int tcp_fconnect _P((struct socket *));
316 f0cbd3ec bellard
void tcp_connect _P((struct socket *));
317 f0cbd3ec bellard
int tcp_attach _P((struct socket *));
318 f0cbd3ec bellard
u_int8_t tcp_tos _P((struct socket *));
319 f0cbd3ec bellard
int tcp_emu _P((struct socket *, struct mbuf *));
320 f0cbd3ec bellard
int tcp_ctl _P((struct socket *));
321 9fafc9ea bellard
struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
322 f0cbd3ec bellard
323 f0cbd3ec bellard
#ifdef USE_PPP
324 f0cbd3ec bellard
#define MIN_MRU MINMRU
325 f0cbd3ec bellard
#define MAX_MRU MAXMRU
326 f0cbd3ec bellard
#else
327 f0cbd3ec bellard
#define MIN_MRU 128
328 f0cbd3ec bellard
#define MAX_MRU 16384
329 f0cbd3ec bellard
#endif
330 f0cbd3ec bellard
331 379ff53d bellard
#ifndef _WIN32
332 379ff53d bellard
#define min(x,y) ((x) < (y) ? (x) : (y))
333 379ff53d bellard
#define max(x,y) ((x) > (y) ? (x) : (y))
334 379ff53d bellard
#endif
335 379ff53d bellard
336 02d2c54c bellard
#ifdef _WIN32
337 ef6ff6b7 bellard
#undef errno
338 02d2c54c bellard
#define errno (WSAGetLastError())
339 02d2c54c bellard
#endif
340 02d2c54c bellard
341 f0cbd3ec bellard
#endif