Home | History | Annotate | Download | only in slirp-android
      1 #ifndef __COMMON_H__
      2 #define __COMMON_H__
      3 
      4 #define CONFIG_QEMU
      5 
      6 //#define DEBUG 1
      7 
      8 // Uncomment the following line to enable SLIRP statistics printing in Qemu
      9 //#define LOG_ENABLED
     10 
     11 #ifdef LOG_ENABLED
     12 #define STAT(expr) expr
     13 #else
     14 #define STAT(expr) do { } while(0)
     15 #endif
     16 
     17 #ifndef CONFIG_QEMU
     18 #include "version.h"
     19 #endif
     20 #include "config-host.h"
     21 #include <stdint.h>
     22 #include "slirp_config.h"
     23 
     24 #include <stddef.h>
     25 #include "android/sockets.h"
     26 
     27 #ifdef _WIN32
     28 # include <inttypes.h>
     29 
     30 typedef uint8_t u_int8_t;
     31 typedef uint16_t u_int16_t;
     32 typedef uint32_t u_int32_t;
     33 typedef uint64_t u_int64_t;
     34 typedef char *caddr_t;
     35 
     36 # include <windows.h>
     37 # include <sys/timeb.h>
     38 # include <iphlpapi.h>
     39 #else
     40 # define O_BINARY 0
     41 #endif
     42 
     43 #include <sys/types.h>
     44 #ifdef HAVE_SYS_BITYPES_H
     45 # include <sys/bitypes.h>
     46 #endif
     47 
     48 #include <sys/time.h>
     49 
     50 #ifdef NEED_TYPEDEFS
     51 typedef char int8_t;
     52 typedef unsigned char u_int8_t;
     53 
     54 # if SIZEOF_SHORT == 2
     55     typedef short int16_t;
     56     typedef unsigned short u_int16_t;
     57 # else
     58 #  if SIZEOF_INT == 2
     59     typedef int int16_t;
     60     typedef unsigned int u_int16_t;
     61 #  else
     62     #error Cannot find a type with sizeof() == 2
     63 #  endif
     64 # endif
     65 
     66 # if SIZEOF_SHORT == 4
     67    typedef short int32_t;
     68    typedef unsigned short u_int32_t;
     69 # else
     70 #  if SIZEOF_INT == 4
     71     typedef int int32_t;
     72     typedef unsigned int u_int32_t;
     73 #  else
     74     #error Cannot find a type with sizeof() == 4
     75 #  endif
     76 # endif
     77 #endif /* NEED_TYPEDEFS */
     78 
     79 #ifdef HAVE_UNISTD_H
     80 # include <unistd.h>
     81 #endif
     82 
     83 #ifdef HAVE_STDLIB_H
     84 # include <stdlib.h>
     85 #endif
     86 
     87 #include <stdio.h>
     88 #include <errno.h>
     89 
     90 #ifndef HAVE_MEMMOVE
     91 #define memmove(x, y, z) bcopy(y, x, z)
     92 #endif
     93 
     94 #if TIME_WITH_SYS_TIME
     95 # include <sys/time.h>
     96 # include <time.h>
     97 #else
     98 # ifdef HAVE_SYS_TIME_H
     99 #  include <sys/time.h>
    100 # else
    101 #  include <time.h>
    102 # endif
    103 #endif
    104 
    105 #ifdef HAVE_STRING_H
    106 # include <string.h>
    107 #else
    108 # include <strings.h>
    109 #endif
    110 
    111 #ifndef _WIN32
    112 #include <sys/uio.h>
    113 #endif
    114 
    115 #undef _P
    116 #ifndef NO_PROTOTYPES
    117 #  define   _P(x)   x
    118 #else
    119 #  define   _P(x)   ()
    120 #endif
    121 
    122 #ifndef _WIN32
    123 #include <arpa/inet.h>
    124 #endif
    125 
    126 #ifdef GETTIMEOFDAY_ONE_ARG
    127 #define gettimeofday(x, y) gettimeofday(x)
    128 #endif
    129 
    130 /* Systems lacking strdup() definition in <string.h>. */
    131 #if defined(ultrix)
    132 char *strdup _P((const char *));
    133 #endif
    134 
    135 /* Systems lacking malloc() definition in <stdlib.h>. */
    136 #if defined(ultrix) || defined(hcx)
    137 void *malloc _P((size_t arg));
    138 void free _P((void *ptr));
    139 #endif
    140 
    141 #ifdef __STDC__
    142 #include <stdarg.h>
    143 #else
    144 #include <varargs.h>
    145 #endif
    146 
    147 /* Avoid conflicting with the libc insque() and remque(), which
    148    have different prototypes. */
    149 #define insque slirp_insque
    150 #define remque slirp_remque
    151 
    152 #ifdef HAVE_SYS_STROPTS_H
    153 #include <sys/stropts.h>
    154 #endif
    155 
    156 #include "debug.h"
    157 
    158 #include "ip.h"
    159 #include "tcp.h"
    160 #include "tcp_timer.h"
    161 #include "tcp_var.h"
    162 #include "tcpip.h"
    163 #include "udp.h"
    164 #include "icmp_var.h"
    165 #include "mbuf.h"
    166 #include "sbuf.h"
    167 #include "socket.h"
    168 #include "if.h"
    169 #include "main.h"
    170 #include "misc.h"
    171 #include "ctl.h"
    172 #ifdef USE_PPP
    173 #include "ppp/pppd.h"
    174 #include "ppp/ppp.h"
    175 #endif
    176 
    177 #include "bootp.h"
    178 #include "tftp.h"
    179 #include "libslirp.h"
    180 
    181 extern struct ttys *ttys_unit[MAX_INTERFACES];
    182 
    183 #ifndef NULL
    184 #define NULL (void *)0
    185 #endif
    186 
    187 #ifndef FULL_BOLT
    188 void if_start _P((void));
    189 #else
    190 void if_start _P((struct ttys *));
    191 #endif
    192 
    193 #ifdef BAD_SPRINTF
    194 # define vsprintf vsprintf_len
    195 # define sprintf sprintf_len
    196  extern int vsprintf_len _P((char *, const char *, va_list));
    197  extern int sprintf_len _P((char *, const char *, ...));
    198 #endif
    199 
    200 #ifdef DECLARE_SPRINTF
    201 # ifndef BAD_SPRINTF
    202  extern int vsprintf _P((char *, const char *, va_list));
    203 # endif
    204  extern int vfprintf _P((FILE *, const char *, va_list));
    205 #endif
    206 
    207 #ifndef HAVE_STRERROR
    208  extern char *strerror _P((int error));
    209 #endif
    210 
    211 #ifndef HAVE_INDEX
    212  char *index _P((const char *, int));
    213 #endif
    214 
    215 #ifndef HAVE_GETHOSTID
    216  long gethostid _P((void));
    217 #endif
    218 
    219 void lprint _P((const char *, ...));
    220 
    221 
    222 #define DEFAULT_BAUD 115200
    223 
    224 #define SO_OPTIONS DO_KEEPALIVE
    225 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
    226 
    227 /* cksum.c */
    228 int cksum(struct mbuf *m, int len);
    229 
    230 /* if.c */
    231 void if_init _P((void));
    232 void if_output _P((struct socket *, struct mbuf *));
    233 
    234 /* ip_input.c */
    235 void ip_init _P((void));
    236 void ip_input _P((struct mbuf *));
    237 void ip_slowtimo _P((void));
    238 void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
    239 
    240 /* ip_output.c */
    241 int ip_output _P((struct socket *, struct mbuf *));
    242 
    243 /* tcp_input.c */
    244 void tcp_input _P((register struct mbuf *, int, struct socket *));
    245 int tcp_mss _P((register struct tcpcb *, u_int));
    246 
    247 /* tcp_output.c */
    248 int tcp_output _P((register struct tcpcb *));
    249 void tcp_setpersist _P((register struct tcpcb *));
    250 
    251 /* tcp_subr.c */
    252 void tcp_init _P((void));
    253 void tcp_template _P((struct tcpcb *));
    254 void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
    255 struct tcpcb * tcp_newtcpcb _P((struct socket *));
    256 struct tcpcb * tcp_close _P((register struct tcpcb *));
    257 void tcp_sockclosed _P((struct tcpcb *));
    258 int tcp_fconnect _P((struct socket *));
    259 void tcp_connect _P((struct socket *));
    260 int tcp_attach _P((struct socket *));
    261 u_int8_t tcp_tos _P((struct socket *));
    262 int tcp_emu _P((struct socket *, struct mbuf *));
    263 int tcp_ctl _P((struct socket *));
    264 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
    265 
    266 #ifdef USE_PPP
    267 #define MIN_MRU MINMRU
    268 #define MAX_MRU MAXMRU
    269 #else
    270 #define MIN_MRU 128
    271 #define MAX_MRU 16384
    272 #endif
    273 
    274 #ifndef _WIN32
    275 #define min(x,y) ((x) < (y) ? (x) : (y))
    276 #define max(x,y) ((x) > (y) ? (x) : (y))
    277 #endif
    278 
    279 #endif
    280