blob: 4068a4fdc99161e538741baa692d2cf0e005fe35 [file] [log] [blame]
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001#ifndef __COMMON_H__
2#define __COMMON_H__
3
4#define CONFIG_QEMU
5
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07006//#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
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080016
17#ifndef CONFIG_QEMU
18#include "version.h"
19#endif
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070020#include "config-host.h"
thomas knych9d3a3292014-04-08 20:28:07 -070021#include <stdint.h>
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080022#include "slirp_config.h"
23
24#include <stddef.h>
David 'Digit' Turnercc330d42013-12-14 23:26:42 +010025#include "android/sockets.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080026
27#ifdef _WIN32
28# include <inttypes.h>
29
30typedef uint8_t u_int8_t;
31typedef uint16_t u_int16_t;
32typedef uint32_t u_int32_t;
33typedef uint64_t u_int64_t;
34typedef char *caddr_t;
35
36# include <windows.h>
37# include <sys/timeb.h>
38# include <iphlpapi.h>
39#else
40# define O_BINARY 0
41#endif
42
43#include <sys/types.h>
44#ifdef HAVE_SYS_BITYPES_H
45# include <sys/bitypes.h>
46#endif
47
48#include <sys/time.h>
49
50#ifdef NEED_TYPEDEFS
51typedef char int8_t;
52typedef unsigned char u_int8_t;
53
54# if SIZEOF_SHORT == 2
55 typedef short int16_t;
56 typedef unsigned short u_int16_t;
57# else
58# if SIZEOF_INT == 2
59 typedef int int16_t;
60 typedef unsigned int u_int16_t;
61# else
62 #error Cannot find a type with sizeof() == 2
63# endif
64# endif
65
66# if SIZEOF_SHORT == 4
67 typedef short int32_t;
68 typedef unsigned short u_int32_t;
69# else
70# if SIZEOF_INT == 4
71 typedef int int32_t;
72 typedef unsigned int u_int32_t;
73# else
74 #error Cannot find a type with sizeof() == 4
75# endif
76# endif
77#endif /* NEED_TYPEDEFS */
78
79#ifdef HAVE_UNISTD_H
80# include <unistd.h>
81#endif
82
83#ifdef HAVE_STDLIB_H
84# include <stdlib.h>
85#endif
86
87#include <stdio.h>
88#include <errno.h>
89
90#ifndef HAVE_MEMMOVE
91#define memmove(x, y, z) bcopy(y, x, z)
92#endif
93
94#if TIME_WITH_SYS_TIME
95# include <sys/time.h>
96# include <time.h>
97#else
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070098# ifdef HAVE_SYS_TIME_H
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080099# include <sys/time.h>
100# else
101# include <time.h>
102# endif
103#endif
104
105#ifdef HAVE_STRING_H
106# include <string.h>
107#else
108# include <strings.h>
109#endif
110
111#ifndef _WIN32
112#include <sys/uio.h>
113#endif
114
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700115#undef _P
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800116#ifndef NO_PROTOTYPES
117# define _P(x) x
118#else
119# define _P(x) ()
120#endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800121
122#ifndef _WIN32
123#include <arpa/inet.h>
124#endif
125
126#ifdef GETTIMEOFDAY_ONE_ARG
127#define gettimeofday(x, y) gettimeofday(x)
128#endif
129
130/* Systems lacking strdup() definition in <string.h>. */
131#if defined(ultrix)
132char *strdup _P((const char *));
133#endif
134
135/* Systems lacking malloc() definition in <stdlib.h>. */
136#if defined(ultrix) || defined(hcx)
137void *malloc _P((size_t arg));
138void free _P((void *ptr));
139#endif
140
141#ifdef __STDC__
142#include <stdarg.h>
143#else
144#include <varargs.h>
145#endif
146
147/* Avoid conflicting with the libc insque() and remque(), which
148 have different prototypes. */
149#define insque slirp_insque
150#define remque slirp_remque
151
152#ifdef HAVE_SYS_STROPTS_H
153#include <sys/stropts.h>
154#endif
155
156#include "debug.h"
157
158#include "ip.h"
159#include "tcp.h"
160#include "tcp_timer.h"
161#include "tcp_var.h"
162#include "tcpip.h"
163#include "udp.h"
164#include "icmp_var.h"
165#include "mbuf.h"
166#include "sbuf.h"
167#include "socket.h"
168#include "if.h"
169#include "main.h"
170#include "misc.h"
171#include "ctl.h"
172#ifdef USE_PPP
173#include "ppp/pppd.h"
174#include "ppp/ppp.h"
175#endif
176
177#include "bootp.h"
178#include "tftp.h"
179#include "libslirp.h"
180
181extern struct ttys *ttys_unit[MAX_INTERFACES];
182
183#ifndef NULL
184#define NULL (void *)0
185#endif
186
187#ifndef FULL_BOLT
188void if_start _P((void));
189#else
190void if_start _P((struct ttys *));
191#endif
192
193#ifdef BAD_SPRINTF
194# define vsprintf vsprintf_len
195# define sprintf sprintf_len
196 extern int vsprintf_len _P((char *, const char *, va_list));
197 extern int sprintf_len _P((char *, const char *, ...));
198#endif
199
200#ifdef DECLARE_SPRINTF
201# ifndef BAD_SPRINTF
202 extern int vsprintf _P((char *, const char *, va_list));
203# endif
204 extern int vfprintf _P((FILE *, const char *, va_list));
205#endif
206
207#ifndef HAVE_STRERROR
208 extern char *strerror _P((int error));
209#endif
210
211#ifndef HAVE_INDEX
212 char *index _P((const char *, int));
213#endif
214
215#ifndef HAVE_GETHOSTID
216 long gethostid _P((void));
217#endif
218
219void lprint _P((const char *, ...));
220
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800221
222#define DEFAULT_BAUD 115200
223
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700224#define SO_OPTIONS DO_KEEPALIVE
225#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
226
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800227/* cksum.c */
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700228int cksum(struct mbuf *m, int len);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800229
230/* if.c */
231void if_init _P((void));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700232void if_output _P((struct socket *, struct mbuf *));
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800233
234/* ip_input.c */
235void ip_init _P((void));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700236void ip_input _P((struct mbuf *));
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800237void ip_slowtimo _P((void));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700238void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800239
240/* ip_output.c */
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700241int ip_output _P((struct socket *, struct mbuf *));
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800242
243/* tcp_input.c */
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700244void tcp_input _P((register struct mbuf *, int, struct socket *));
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800245int tcp_mss _P((register struct tcpcb *, u_int));
246
247/* tcp_output.c */
248int tcp_output _P((register struct tcpcb *));
249void tcp_setpersist _P((register struct tcpcb *));
250
251/* tcp_subr.c */
252void tcp_init _P((void));
253void tcp_template _P((struct tcpcb *));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700254void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800255struct tcpcb * tcp_newtcpcb _P((struct socket *));
256struct tcpcb * tcp_close _P((register struct tcpcb *));
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800257void tcp_sockclosed _P((struct tcpcb *));
258int tcp_fconnect _P((struct socket *));
259void tcp_connect _P((struct socket *));
260int tcp_attach _P((struct socket *));
261u_int8_t tcp_tos _P((struct socket *));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700262int tcp_emu _P((struct socket *, struct mbuf *));
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800263int tcp_ctl _P((struct socket *));
264struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
265
266#ifdef USE_PPP
267#define MIN_MRU MINMRU
268#define MAX_MRU MAXMRU
269#else
270#define MIN_MRU 128
271#define MAX_MRU 16384
272#endif
273
274#ifndef _WIN32
275#define min(x,y) ((x) < (y) ? (x) : (y))
276#define max(x,y) ((x) > (y) ? (x) : (y))
277#endif
278
279#endif