00001 #ifndef __COMMON_H__
00002 #define __COMMON_H__
00003
00004 #define CONFIG_QEMU
00005
00006
00007
00008
00009
00010
00011 #ifdef LOG_ENABLED
00012 #define STAT(expr) expr
00013 #else
00014 #define STAT(expr) do { } while(0)
00015 #endif
00016
00017 #ifndef CONFIG_QEMU
00018 #include "version.h"
00019 #endif
00020 #include "config-host.h"
00021 #include "slirp_config.h"
00022
00023 #ifdef _WIN32
00024 # include <inttypes.h>
00025
00026 typedef uint8_t u_int8_t;
00027 typedef uint16_t u_int16_t;
00028 typedef uint32_t u_int32_t;
00029 typedef uint64_t u_int64_t;
00030 typedef char *caddr_t;
00031
00032 #define WIN32_LEAN_AND_MEAN
00033 # include <windows.h>
00034 # include <winsock2.h>
00035 # include <ws2tcpip.h>
00036 # include <sys/timeb.h>
00037 # include <iphlpapi.h>
00038
00039 # define EWOULDBLOCK WSAEWOULDBLOCK
00040 # define EINPROGRESS WSAEINPROGRESS
00041 # define ENOTCONN WSAENOTCONN
00042 # define EHOSTUNREACH WSAEHOSTUNREACH
00043 # define ENETUNREACH WSAENETUNREACH
00044 # define ECONNREFUSED WSAECONNREFUSED
00045 #else
00046 # define ioctlsocket ioctl
00047 # define closesocket(s) close(s)
00048 # define O_BINARY 0
00049 #endif
00050
00051 #include <sys/types.h>
00052 #ifdef HAVE_SYS_BITYPES_H
00053 # include <sys/bitypes.h>
00054 #endif
00055
00056 #include <sys/time.h>
00057
00058 #ifdef NEED_TYPEDEFS
00059 typedef char int8_t;
00060 typedef unsigned char u_int8_t;
00061
00062 # if SIZEOF_SHORT == 2
00063 typedef short int16_t;
00064 typedef unsigned short u_int16_t;
00065 # else
00066 # if SIZEOF_INT == 2
00067 typedef int int16_t;
00068 typedef unsigned int u_int16_t;
00069 # else
00070 #error Cannot find a type with sizeof() == 2
00071 # endif
00072 # endif
00073
00074 # if SIZEOF_SHORT == 4
00075 typedef short int32_t;
00076 typedef unsigned short u_int32_t;
00077 # else
00078 # if SIZEOF_INT == 4
00079 typedef int int32_t;
00080 typedef unsigned int u_int32_t;
00081 # else
00082 #error Cannot find a type with sizeof() == 4
00083 # endif
00084 # endif
00085 #endif
00086
00087 #ifdef HAVE_UNISTD_H
00088 # include <unistd.h>
00089 #endif
00090
00091 #ifdef HAVE_STDLIB_H
00092 # include <stdlib.h>
00093 #endif
00094
00095 #include <stdio.h>
00096 #include <errno.h>
00097
00098 #ifndef HAVE_MEMMOVE
00099 #define memmove(x, y, z) bcopy(y, x, z)
00100 #endif
00101
00102 #if TIME_WITH_SYS_TIME
00103 # include <sys/time.h>
00104 # include <time.h>
00105 #else
00106 # ifdef HAVE_SYS_TIME_H
00107 # include <sys/time.h>
00108 # else
00109 # include <time.h>
00110 # endif
00111 #endif
00112
00113 #ifdef HAVE_STRING_H
00114 # include <string.h>
00115 #else
00116 # include <strings.h>
00117 #endif
00118
00119 #ifndef _WIN32
00120 #include <sys/uio.h>
00121 #endif
00122
00123 #undef _P
00124 #ifndef NO_PROTOTYPES
00125 # define _P(x) x
00126 #else
00127 # define _P(x) ()
00128 #endif
00129
00130 #ifndef _WIN32
00131 #include <netinet/in.h>
00132 #include <arpa/inet.h>
00133 #endif
00134
00135 #ifdef GETTIMEOFDAY_ONE_ARG
00136 #define gettimeofday(x, y) gettimeofday(x)
00137 #endif
00138
00139
00140 #if defined(ultrix)
00141 char *strdup _P((const char *));
00142 #endif
00143
00144
00145 #if defined(ultrix) || defined(hcx)
00146 void *malloc _P((size_t arg));
00147 void free _P((void *ptr));
00148 #endif
00149
00150 #ifndef HAVE_INET_ATON
00151 int inet_aton _P((const char *cp, struct in_addr *ia));
00152 #endif
00153
00154 #include <fcntl.h>
00155 #ifndef NO_UNIX_SOCKETS
00156 #include <sys/un.h>
00157 #endif
00158 #include <signal.h>
00159 #ifdef HAVE_SYS_SIGNAL_H
00160 # include <sys/signal.h>
00161 #endif
00162 #ifndef _WIN32
00163 #include <sys/socket.h>
00164 #endif
00165
00166 #if defined(HAVE_SYS_IOCTL_H)
00167 # include <sys/ioctl.h>
00168 #endif
00169
00170 #ifdef HAVE_SYS_SELECT_H
00171 # include <sys/select.h>
00172 #endif
00173
00174 #ifdef HAVE_SYS_WAIT_H
00175 # include <sys/wait.h>
00176 #endif
00177
00178 #ifdef HAVE_SYS_FILIO_H
00179 # include <sys/filio.h>
00180 #endif
00181
00182 #ifdef USE_PPP
00183 #include <ppp/slirppp.h>
00184 #endif
00185
00186 #ifdef __STDC__
00187 #include <stdarg.h>
00188 #else
00189 #include <varargs.h>
00190 #endif
00191
00192 #include <sys/stat.h>
00193
00194
00195
00196 #define insque slirp_insque
00197 #define remque slirp_remque
00198
00199 #ifdef HAVE_SYS_STROPTS_H
00200 #include <sys/stropts.h>
00201 #endif
00202
00203 #include "debug.h"
00204
00205 #include "ip.h"
00206 #include "tcp.h"
00207 #include "tcp_timer.h"
00208 #include "tcp_var.h"
00209 #include "tcpip.h"
00210 #include "udp.h"
00211 #include "icmp_var.h"
00212 #include "mbuf.h"
00213 #include "sbuf.h"
00214 #include "socket.h"
00215 #include "if.h"
00216 #include "main.h"
00217 #include "misc.h"
00218 #include "ctl.h"
00219 #ifdef USE_PPP
00220 #include "ppp/pppd.h"
00221 #include "ppp/ppp.h"
00222 #endif
00223
00224 #include "bootp.h"
00225 #include "tftp.h"
00226 #include "libslirp.h"
00227
00228 extern struct ttys *ttys_unit[MAX_INTERFACES];
00229
00230 #ifndef NULL
00231 #define NULL (void *)0
00232 #endif
00233
00234 #ifndef FULL_BOLT
00235 void if_start _P((void));
00236 #else
00237 void if_start _P((struct ttys *));
00238 #endif
00239
00240 #ifdef BAD_SPRINTF
00241 # define vsprintf vsprintf_len
00242 # define sprintf sprintf_len
00243 extern int vsprintf_len _P((char *, const char *, va_list));
00244 extern int sprintf_len _P((char *, const char *, ...));
00245 #endif
00246
00247 #ifdef DECLARE_SPRINTF
00248 # ifndef BAD_SPRINTF
00249 extern int vsprintf _P((char *, const char *, va_list));
00250 # endif
00251 extern int vfprintf _P((FILE *, const char *, va_list));
00252 #endif
00253
00254 #ifndef HAVE_STRERROR
00255 extern char *strerror _P((int error));
00256 #endif
00257
00258 #ifndef HAVE_INDEX
00259 char *index _P((const char *, int));
00260 #endif
00261
00262 #ifndef HAVE_GETHOSTID
00263 long gethostid _P((void));
00264 #endif
00265
00266 void lprint _P((const char *, ...));
00267
00268 #ifndef _WIN32
00269 #include <netdb.h>
00270 #endif
00271
00272 #define DEFAULT_BAUD 115200
00273
00274 #define SO_OPTIONS DO_KEEPALIVE
00275 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
00276
00277
00278 int cksum(struct mbuf *m, int len);
00279
00280
00281 void if_init _P((void));
00282 void if_output _P((struct socket *, struct mbuf *));
00283
00284
00285 void ip_init _P((void));
00286 void ip_input _P((struct mbuf *));
00287 void ip_slowtimo _P((void));
00288 void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
00289
00290
00291 int ip_output _P((struct socket *, struct mbuf *));
00292
00293
00294 void tcp_input _P((register struct mbuf *, int, struct socket *));
00295 int tcp_mss _P((register struct tcpcb *, u_int));
00296
00297
00298 int tcp_output _P((register struct tcpcb *));
00299 void tcp_setpersist _P((register struct tcpcb *));
00300
00301
00302 void tcp_init _P((void));
00303 void tcp_template _P((struct tcpcb *));
00304 void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
00305 struct tcpcb * tcp_newtcpcb _P((struct socket *));
00306 struct tcpcb * tcp_close _P((register struct tcpcb *));
00307 void tcp_sockclosed _P((struct tcpcb *));
00308 int tcp_fconnect _P((struct socket *));
00309 void tcp_connect _P((struct socket *));
00310 int tcp_attach _P((struct socket *));
00311 u_int8_t tcp_tos _P((struct socket *));
00312 int tcp_emu _P((struct socket *, struct mbuf *));
00313 int tcp_ctl _P((struct socket *));
00314 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
00315
00316 #ifdef USE_PPP
00317 #define MIN_MRU MINMRU
00318 #define MAX_MRU MAXMRU
00319 #else
00320 #define MIN_MRU 128
00321 #define MAX_MRU 16384
00322 #endif
00323
00324 #ifndef _WIN32
00325 #define min(x,y) ((x) < (y) ? (x) : (y))
00326 #define max(x,y) ((x) > (y) ? (x) : (y))
00327 #endif
00328
00329 #ifdef _WIN32
00330 #undef errno
00331 #define errno (WSAGetLastError())
00332 #endif
00333
00334 #endif