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