This repo is obsolete, please see git://git.code.sf.net/p/dummynet/code@master
[ipfw.git] / tcc_glue.h
1 /*
2  * Copyright (c) 2010 Luigi Rizzo, Universita` di Pisa
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25 /*
26  * headers to build userland ipfw under tcc.
27  */
28  
29 #ifndef _TCC_GLUE_H
30 #define _TCC_GLUE_H
31
32 //#define       __restrict
33 #define NULL    ((void *)0)
34 typedef int size_t;
35 typedef unsigned char   u_char;
36 typedef unsigned char   uint8_t;
37 typedef unsigned char   u_int8_t;
38 typedef unsigned short  u_short;
39 typedef unsigned short  uint16_t;
40 typedef unsigned short  u_int16_t;
41 typedef int             __int32_t;
42 typedef int             int32_t;
43 typedef int             socklen_t;
44 typedef int             pid_t;
45 typedef unsigned int    time_t;
46 typedef unsigned int    uint;
47 typedef unsigned int    u_int;
48 typedef unsigned int    uint32_t;
49 typedef unsigned int    u_int32_t;
50 typedef unsigned int    gid_t;
51 typedef unsigned int    uid_t;
52 typedef unsigned long   u_long;
53 typedef unsigned long   uintptr_t;
54 typedef long long int   int64_t;
55 typedef unsigned long long      int uint64_t;
56 typedef unsigned long long      int u_int64_t;
57
58 typedef uint32_t        in_addr_t;
59 struct in_addr {
60         uint32_t        s_addr;
61 };
62 struct sockaddr_in {
63         uint8_t _sin_len;
64         uint8_t sin_family;
65         uint16_t        sin_port;
66         struct  in_addr sin_addr;
67         char    sin_zero[8];
68 };
69 #define IFNAMSIZ        16
70 #define INET6_ADDRSTRLEN        64
71
72 struct in6_addr {
73         union {
74                 uint8_t         __s6_addr8[16];
75                 uint16_t        __s6_addr16[8];
76                 uint32_t        __s6_addr32[4];
77         } __u6; // _addr;                    /* 128-bit IP6 address */
78 };
79
80
81 #define LITTLE_ENDIAN 1234
82 #define BYTE_ORDER LITTLE_ENDIAN
83
84 /* to be revised */
85 #define EX_OK           0
86 #define EX_DATAERR      1
87 #define EX_OSERR        2
88 #define EX_UNAVAILABLE  3
89 #define EX_USAGE        4
90 #define EX_NOHOST       5
91
92 #define EEXIST          1
93 #define EINVAL          2
94 #define ERANGE          3
95 #define ESRCH           4
96
97 #define IPPROTO_IP              1
98 #define IPPROTO_IPV6            2
99 #define IPPROTO_RAW             100
100
101 #define IPTOS_LOWDELAY          100
102 #define IPTOS_MINCOST           101
103 #define IPTOS_RELIABILITY       102
104 #define IPTOS_THROUGHPUT        103
105 #define SOCK_RAW                12
106 #define AF_INET                 2
107 #define AF_INET6                28
108
109 #define INADDR_ANY              0
110
111
112 #define bcmp(src, dst, len)     memcmp(src, dst, len)
113 #define bcopy(src, dst, len)    memcpy(dst, src, len)
114 #define bzero(p, len)   memset(p, 0, len)
115 #define index(s, c)     strchr(s, c)
116
117 char *strsep(char **stringp, const char *delim);
118
119 void    warn(const char *, ...);
120 //void    warnx(const char *, ...);
121 #define warnx warn
122 void    err(int, const char *, ...);
123 #define errx err
124
125 uint16_t        htons(uint16_t)__attribute__ ((stdcall));
126 uint16_t        ntohs(uint16_t)__attribute__ ((stdcall));
127 uint32_t        htonl(uint32_t)__attribute__ ((stdcall));
128 uint32_t        ntohl(uint32_t)__attribute__ ((stdcall));
129 int inet_aton(const char *cp, struct in_addr *pin);
130 char * inet_ntoa(struct in_addr);
131 const char * inet_ntop(int af, const void * src, char * dst,
132          socklen_t size);
133 int inet_pton(int af, const char * src, void * dst);
134
135 struct group {
136         gid_t   gr_gid;
137         char    gr_name[16];
138 };
139 struct passwd {
140         uid_t   pw_uid;
141         char    pw_name[16];
142 };
143
144 #define getpwnam(s)     (NULL)
145 #define getpwuid(s)     (NULL)
146
147 #define getgrnam(x) (NULL)
148 #define getgrgid(x) (NULL)
149
150 int getopt(int argc, char * const argv[], const char *optstring);
151
152 int getsockopt(int s, int level, int optname, void * optval,
153          socklen_t * optlen);
154
155 int setsockopt(int s, int level, int optname, const void *optval,
156          socklen_t optlen);
157
158 struct  protoent {
159         char    *p_name;           /* official protocol name */
160         char    **p_aliases;  /* alias list */
161         short   p_proto;                /* protocol # */
162 };
163
164 struct  servent {
165         char    *s_name;           /* official service name */
166         char    **s_aliases;  /* alias list */
167         short   s_port;                 /* port # */
168         char    *s_proto;          /* protocol to use */
169 };
170
171 struct  hostent {
172         char    *h_name;           /* official name of host */
173         char    **h_aliases;  /* alias list */
174         short   h_addrtype;             /* host address type */
175         short   h_length;               /* length of address */
176         char    **h_addr_list; /* list of addresses */
177 #define h_addr  h_addr_list[0]          /* address, for backward compat */
178 };
179
180 struct hostent* gethostbyaddr(const char* addr, int len, int type)__attribute__ ((stdcall));
181 struct hostent* gethostbyname(const char *name)__attribute__ ((stdcall));
182
183 struct protoent* getprotobynumber(int number)__attribute__ ((stdcall));
184 struct protoent* getprotobyname(const char* name)__attribute__ ((stdcall));
185
186 struct servent* getservbyport(int port, const char* proto)__attribute__ ((stdcall));
187 struct servent* getservbyname(const char* name, const char* proto) __attribute__ ((stdcall));
188
189 extern int optind;
190 extern char *optarg;
191
192 #include <windef.h>
193
194 #define WSADESCRIPTION_LEN      256
195 #define WSASYS_STATUS_LEN       128
196
197 typedef struct WSAData {
198         WORD                    wVersion;
199         WORD                    wHighVersion;
200         char                    szDescription[WSADESCRIPTION_LEN+1];
201         char                    szSystemStatus[WSASYS_STATUS_LEN+1];
202         unsigned short          iMaxSockets;
203         unsigned short          iMaxUdpDg;
204         char FAR *              lpVendorInfo;
205 } WSADATA, * LPWSADATA;
206
207 int WSAStartup(
208     WORD wVersionRequested,
209     LPWSADATA lpWSAData
210     );
211
212 int
213 WSACleanup(void);
214
215 int WSAGetLastError();
216
217 /* return error on process handling */
218 #define pipe(f)         (-1)
219 #define kill(p, s)      (-1)
220 #define waitpid(w,s,o)  (-1)
221 #define fork(x)         (-1)
222 #define execvp(f, a)    (-1)
223
224 #define _W_INT(i)       (i)
225 #define _WSTATUS(x)     (_W_INT(x) & 0177)
226 #define WIFEXITED(x)    (_WSTATUS(x) == 0)
227 #define WEXITSTATUS(x)  (_W_INT(x) >> 8)
228 #define _WSTOPPED       0177            /* _WSTATUS if process is stopped */
229 #define WIFSIGNALED(x)  (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
230 #define WTERMSIG(x)     (_WSTATUS(x))
231
232 #endif /* _TCC_GLUE_H */