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