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