Statistics
| Branch: | Revision:

root / slirp / slirp.h @ ac72472b

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