slirp fix for -smb command (Initial patch by Juergen Keil)
[qemu] / slirp / slirp.h
1 #ifndef __COMMON_H__
2 #define __COMMON_H__
3
4 #define CONFIG_QEMU
5
6 #define DEBUG 1
7
8 #ifndef CONFIG_QEMU
9 #include "version.h"
10 #endif
11 #include "config.h"
12 #include "slirp_config.h"
13
14 #ifdef _WIN32
15 # include <inttypes.h>
16
17 typedef uint8_t u_int8_t;
18 typedef uint16_t u_int16_t;
19 typedef uint32_t u_int32_t;
20 typedef uint64_t u_int64_t;
21 typedef char *caddr_t;
22
23 # include <winsock2.h>
24 # include <sys/timeb.h>
25 # include <iphlpapi.h>
26
27 # define EWOULDBLOCK WSAEWOULDBLOCK
28 # define EINPROGRESS WSAEINPROGRESS
29 # define ENOTCONN WSAENOTCONN
30 # define EHOSTUNREACH WSAEHOSTUNREACH
31 # define ENETUNREACH WSAENETUNREACH
32 # define ECONNREFUSED WSAECONNREFUSED
33 #else
34 # define ioctlsocket ioctl
35 # define closesocket(s) close(s)
36 # define O_BINARY 0
37 #endif
38
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_BITYPES_H
41 # include <sys/bitypes.h>
42 #endif
43
44 #include <sys/time.h>
45
46 #ifdef NEED_TYPEDEFS
47 typedef char int8_t;
48 typedef unsigned char u_int8_t;
49
50 # if SIZEOF_SHORT == 2
51     typedef short int16_t;
52     typedef unsigned short u_int16_t;
53 # else
54 #  if SIZEOF_INT == 2
55     typedef int int16_t;
56     typedef unsigned int u_int16_t;
57 #  else
58     #error Cannot find a type with sizeof() == 2
59 #  endif
60 # endif
61
62 # if SIZEOF_SHORT == 4
63    typedef short int32_t;
64    typedef unsigned short u_int32_t;
65 # else
66 #  if SIZEOF_INT == 4
67     typedef int int32_t;
68     typedef unsigned int u_int32_t;
69 #  else
70     #error Cannot find a type with sizeof() == 4
71 #  endif
72 # endif
73 #endif /* NEED_TYPEDEFS */
74
75 #ifdef HAVE_UNISTD_H
76 # include <unistd.h>
77 #endif
78
79 #ifdef HAVE_STDLIB_H
80 # include <stdlib.h>
81 #endif
82
83 #include <stdio.h>
84 #include <errno.h>
85
86 #ifndef HAVE_MEMMOVE
87 #define memmove(x, y, z) bcopy(y, x, z)
88 #endif
89
90 #if TIME_WITH_SYS_TIME
91 # include <sys/time.h>
92 # include <time.h>
93 #else
94 # if HAVE_SYS_TIME_H
95 #  include <sys/time.h>
96 # else
97 #  include <time.h>
98 # endif
99 #endif
100
101 #ifdef HAVE_STRING_H
102 # include <string.h>
103 #else
104 # include <strings.h>
105 #endif
106
107 #ifndef _WIN32
108 #include <sys/uio.h>
109 #endif
110
111 #ifndef _P
112 #ifndef NO_PROTOTYPES
113 #  define   _P(x)   x
114 #else
115 #  define   _P(x)   ()
116 #endif
117 #endif
118
119 #ifndef _WIN32
120 #include <netinet/in.h>
121 #include <arpa/inet.h>
122 #endif
123
124 #ifdef GETTIMEOFDAY_ONE_ARG
125 #define gettimeofday(x, y) gettimeofday(x)
126 #endif
127
128 /* Systems lacking strdup() definition in <string.h>. */
129 #if defined(ultrix)
130 char *strdup _P((const char *));
131 #endif
132
133 /* Systems lacking malloc() definition in <stdlib.h>. */
134 #if defined(ultrix) || defined(hcx)
135 void *malloc _P((size_t arg));
136 void free _P((void *ptr));
137 #endif
138
139 #ifndef HAVE_INET_ATON
140 int inet_aton _P((const char *cp, struct in_addr *ia));
141 #endif
142
143 #include <fcntl.h>
144 #ifndef NO_UNIX_SOCKETS
145 #include <sys/un.h>
146 #endif
147 #include <signal.h>
148 #ifdef HAVE_SYS_SIGNAL_H
149 # include <sys/signal.h>
150 #endif
151 #ifndef _WIN32
152 #include <sys/socket.h>
153 #endif
154
155 #if defined(HAVE_SYS_IOCTL_H)
156 # include <sys/ioctl.h>
157 #endif
158
159 #ifdef HAVE_SYS_SELECT_H
160 # include <sys/select.h>
161 #endif
162
163 #ifdef HAVE_SYS_WAIT_H
164 # include <sys/wait.h>
165 #endif
166
167 #ifdef HAVE_SYS_FILIO_H
168 # include <sys/filio.h>
169 #endif
170
171 #ifdef USE_PPP
172 #include <ppp/slirppp.h>
173 #endif
174
175 #ifdef __STDC__
176 #include <stdarg.h>
177 #else
178 #include <varargs.h>
179 #endif
180
181 #include <sys/stat.h>
182
183 /* Avoid conflicting with the libc insque() and remque(), which
184    have different prototypes. */
185 #define insque slirp_insque
186 #define remque slirp_remque
187
188 #ifdef HAVE_SYS_STROPTS_H
189 #include <sys/stropts.h>
190 #endif
191
192 #include "debug.h"
193
194 #include "ip.h"
195 #include "tcp.h"
196 #include "tcp_timer.h"
197 #include "tcp_var.h"
198 #include "tcpip.h"
199 #include "udp.h"
200 #include "icmp_var.h"
201 #include "mbuf.h"
202 #include "sbuf.h"
203 #include "socket.h"
204 #include "if.h"
205 #include "main.h"
206 #include "misc.h"
207 #include "ctl.h"
208 #ifdef USE_PPP
209 #include "ppp/pppd.h"
210 #include "ppp/ppp.h"
211 #endif
212
213 #include "bootp.h"
214 #include "tftp.h"
215 #include "libslirp.h"
216
217 extern struct ttys *ttys_unit[MAX_INTERFACES];
218
219 #ifndef NULL
220 #define NULL (void *)0
221 #endif
222
223 #ifndef FULL_BOLT
224 void if_start _P((void));
225 #else
226 void if_start _P((struct ttys *));
227 #endif
228
229 #ifdef BAD_SPRINTF
230 # define vsprintf vsprintf_len
231 # define sprintf sprintf_len
232  extern int vsprintf_len _P((char *, const char *, va_list));
233  extern int sprintf_len _P((char *, const char *, ...));
234 #endif
235
236 #ifdef DECLARE_SPRINTF
237 # ifndef BAD_SPRINTF
238  extern int vsprintf _P((char *, const char *, va_list));
239 # endif
240  extern int vfprintf _P((FILE *, const char *, va_list));
241 #endif
242
243 #ifndef HAVE_STRERROR
244  extern char *strerror _P((int error));
245 #endif
246
247 #ifndef HAVE_INDEX
248  char *index _P((const char *, int));
249 #endif
250
251 #ifndef HAVE_GETHOSTID
252  long gethostid _P((void));
253 #endif
254
255 void lprint _P((const char *, ...));
256
257 extern int do_echo;
258
259 #if SIZEOF_CHAR_P == 4
260 # define insque_32 insque
261 # define remque_32 remque
262 #else
263  inline void insque_32 _P((void *, void *));
264  inline void remque_32 _P((void *));
265 #endif
266
267 #ifndef _WIN32
268 #include <netdb.h>
269 #endif
270
271 #define DEFAULT_BAUD 115200
272
273 /* cksum.c */
274 int cksum(struct mbuf *m, int len);
275
276 /* if.c */
277 void if_init _P((void));
278 void if_output _P((struct socket *, struct mbuf *));
279
280 /* ip_input.c */
281 void ip_init _P((void));
282 void ip_input _P((struct mbuf *));
283 struct ip * ip_reass _P((register struct ipasfrag *, register struct ipq *));
284 void ip_freef _P((struct ipq *));
285 void ip_enq _P((register struct ipasfrag *, register struct ipasfrag *));
286 void ip_deq _P((register struct ipasfrag *));
287 void ip_slowtimo _P((void));
288 void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
289
290 /* ip_output.c */
291 int ip_output _P((struct socket *, struct mbuf *));
292
293 /* tcp_input.c */
294 int tcp_reass _P((register struct tcpcb *, register struct tcpiphdr *, struct mbuf *));
295 void tcp_input _P((register struct mbuf *, int, struct socket *));
296 void tcp_dooptions _P((struct tcpcb *, u_char *, int, struct tcpiphdr *));
297 void tcp_xmit_timer _P((register struct tcpcb *, int));
298 int tcp_mss _P((register struct tcpcb *, u_int));
299
300 /* tcp_output.c */
301 int tcp_output _P((register struct tcpcb *));
302 void tcp_setpersist _P((register struct tcpcb *));
303
304 /* tcp_subr.c */
305 void tcp_init _P((void));
306 void tcp_template _P((struct tcpcb *));
307 void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
308 struct tcpcb * tcp_newtcpcb _P((struct socket *));
309 struct tcpcb * tcp_close _P((register struct tcpcb *));
310 void tcp_drain _P((void));
311 void tcp_sockclosed _P((struct tcpcb *));
312 int tcp_fconnect _P((struct socket *));
313 void tcp_connect _P((struct socket *));
314 int tcp_attach _P((struct socket *));
315 u_int8_t tcp_tos _P((struct socket *));
316 int tcp_emu _P((struct socket *, struct mbuf *));
317 int tcp_ctl _P((struct socket *));
318 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
319
320 #ifdef USE_PPP
321 #define MIN_MRU MINMRU
322 #define MAX_MRU MAXMRU
323 #else
324 #define MIN_MRU 128
325 #define MAX_MRU 16384
326 #endif
327
328 #ifndef _WIN32
329 #define min(x,y) ((x) < (y) ? (x) : (y))
330 #define max(x,y) ((x) > (y) ? (x) : (y))
331 #endif
332
333 #ifdef _WIN32
334 #undef errno
335 #define errno (WSAGetLastError())
336 #endif
337
338 #endif