tweak for building in fedora20
[ipfw-google.git] / kipfw / winmissing.h
1 /*
2  * Copyright (c) 2010 Francesco Magno, 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 /*
27  * $Id: winmissing.h 11647 2012-08-06 23:20:21Z luigi $
28  * definitions and other things needed to build freebsd kernel
29  * modules in Windows (with the MSVC compiler)
30  */
31
32 #ifndef _WINMISSING_H_
33 #define _WINMISSING_H_
34
35 #include <ntifs.h>
36 #include <ntddk.h>
37 #include <basetsd.h>
38 #include <windef.h>
39 #include <stdio.h>
40 #include <ndis.h>
41
42 typedef UCHAR   u_char;
43 typedef UCHAR   u_int8_t;
44 typedef UCHAR   uint8_t;
45 typedef USHORT  u_short;
46 typedef USHORT  u_int16_t;
47 typedef USHORT  uint16_t;
48 typedef USHORT  n_short;
49 typedef UINT    u_int;
50 typedef INT32   int32_t;
51 typedef UINT32  u_int32_t;
52 typedef UINT32  uint32_t;
53 typedef ULONG   u_long;
54 typedef ULONG   n_long;
55 typedef UINT64  uint64_t;
56 typedef UINT64  u_int64_t;
57 typedef INT64   int64_t;
58
59 typedef UINT32  in_addr_t;
60 typedef UCHAR   sa_family_t;
61 typedef USHORT  in_port_t;
62 typedef UINT32  __gid_t;
63 typedef UINT32  gid_t;
64 typedef UINT32  __uid_t;
65 typedef UINT32  uid_t;
66 typedef ULONG   n_time;
67 typedef char*   caddr_t;
68
69 /* linux_lookup uses __be32 and __be16 in the prototype */
70 typedef uint32_t __be32; /* XXX __u32 __bitwise __be32 */
71 typedef uint16_t __be16; /* XXX */
72
73 //*** DEBUG STUFF ***
74 /*
75  * To see the debugging messages you need DbgView
76 http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx
77  */
78 #define printf          DbgPrint
79 #define log(lev, ...)   DbgPrint(__VA_ARGS__)
80 const char* texify_cmd(int i);
81 const char* texify_proto(unsigned int p);
82 //*** end DEBUG STUFF ***
83
84 #define snprintf _snprintf
85 #define timespec timeval
86 struct timeval {
87         long tv_sec;
88         long tv_usec;
89 };
90
91 struct in_addr {
92         in_addr_t s_addr;
93 };
94
95 struct sockaddr_in {
96         uint8_t sin_len;
97         sa_family_t     sin_family;
98         in_port_t       sin_port;
99         struct  in_addr sin_addr;
100         char    sin_zero[8];
101 };
102
103 /* XXX watch out, windows names are actually longer */
104 #define IFNAMSIZ        16
105 #define IF_NAMESIZE     16
106
107 #define ETHER_ADDR_LEN 6
108
109 /* we do not include the windows headers for in6_addr so
110  * we need to provide our own definition for the kernel.
111  */
112 struct in6_addr {
113         union {
114                 uint8_t         __u6_addr8[16];
115                 uint16_t        __u6_addr16[8]; 
116                 uint32_t        __u6_addr32[4];
117         } __u6_addr;                    /* 128-bit IP6 address */
118 };
119
120 #define htons(x) RtlUshortByteSwap(x)
121 #define ntohs(x) RtlUshortByteSwap(x)
122 #define htonl(x) RtlUlongByteSwap(x)
123 #define ntohl(x) RtlUlongByteSwap(x)
124
125 #define ENOSPC          28      /* No space left on device */
126 #define EOPNOTSUPP      45      /* Operation not supported */
127 #define EACCES          13      /* Permission denied */
128 #define ENOENT          2       /* No such file or directory */
129 #define EINVAL          22      /* Invalid argument */
130 #define EPROTONOSUPPORT 43      /* Protocol not supported */
131 #define ENOMEM          12      /* Cannot allocate memory */
132 #define EEXIST          17      /* File exists */
133 #define ESRCH           3
134 #define ENOBUFS         55      /* No buffer space available */
135 #define EBUSY           16      /* Module busy */
136
137
138 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
139 #define __packed 
140 #define __aligned(x);
141 #define __user
142 #define __init
143 #define __exit
144 #define __func__ __FUNCTION__
145 #define inline __inline
146
147 struct sockaddr_in6 {
148         int dummy;
149 };
150
151 //SPINLOCKS
152 #define DEFINE_SPINLOCK(x)              NDIS_SPIN_LOCK x
153 #define mtx_init(m,a,b,c)               NdisAllocateSpinLock(m)
154 #define mtx_lock(_l)                    NdisAcquireSpinLock(_l)
155 #define mtx_unlock(_l)                  NdisReleaseSpinLock(_l)
156 #define mtx_destroy(m)                  NdisFreeSpinLock(m)
157 #define mtx_assert(a, b)
158
159 #define rw_rlock(_l)                    NdisAcquireSpinLock(_l)
160 #define rw_runlock(_l)                  NdisReleaseSpinLock(_l)
161 #define rw_assert(a, b)
162 #define rw_wlock(_l)                    NdisAcquireSpinLock(_l)
163 #define rw_wunlock(_l)                  NdisReleaseSpinLock(_l)
164 #define rw_destroy(_l)                  NdisFreeSpinLock(_l)
165 #define rw_init(_l, msg)                NdisAllocateSpinLock(_l)
166 #define rw_init_flags(_l, s, v)         NdisAllocateSpinLock(_l)
167
168 #define rwlock_t NDIS_SPIN_LOCK
169 #define spinlock_t NDIS_SPIN_LOCK
170
171 #define s6_addr   __u6_addr.__u6_addr8
172
173
174 struct icmphdr {
175         u_char  icmp_type;              /* type of message, see below */
176         u_char  icmp_code;              /* type sub code */
177         u_short icmp_cksum;             /* ones complement cksum of struct */
178 };
179
180 #define ICMP_ECHO               8               /* echo service */
181
182 #define IPOPT_OPTVAL            0               /* option ID */
183 #define IPOPT_OLEN              1               /* option length */
184 #define IPOPT_EOL               0               /* end of option list */
185 #define IPOPT_NOP               1               /* no operation */
186 #define IPOPT_LSRR              131             /* loose source route */
187 #define IPOPT_SSRR              137             /* strict source route */
188 #define IPOPT_RR                7               /* record packet route */
189 #define IPOPT_TS                68              /* timestamp */
190
191 #define IPPROTO_ICMP    1               /* control message protocol */
192 #define IPPROTO_TCP             6               /* tcp */
193 #define IPPROTO_UDP             17              /* user datagram protocol */
194 #define IPPROTO_ICMPV6          58              /* ICMP6 */
195 #define IPPROTO_SCTP            132             /* SCTP */
196 #define IPPROTO_HOPOPTS         0               /* IP6 hop-by-hop options */
197 #define IPPROTO_ROUTING         43              /* IP6 routing header */
198 #define IPPROTO_FRAGMENT        44              /* IP6 fragmentation header */
199 #define IPPROTO_DSTOPTS         60              /* IP6 destination option */
200 #define IPPROTO_AH              51              /* IP6 Auth Header */
201 #define IPPROTO_ESP             50              /* IP6 Encap Sec. Payload */
202 #define IPPROTO_NONE            59              /* IP6 no next header */
203 #define IPPROTO_PIM             103             /* Protocol Independent Mcast */
204
205 #define IPPROTO_IPV6            41
206 #define IPPROTO_IPV4            4               /* IPv4 encapsulation */
207
208
209 #define INADDR_ANY              (uint32_t)0x00000000
210
211 #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
212 #define AF_LINK         18              /* Link layer interface */
213
214 #define IN_CLASSD(i)            (((uint32_t)(i) & 0xf0000000) == 0xe0000000)
215 #define IN_MULTICAST(i)         IN_CLASSD(i)
216
217 #define DROP 0
218 #define PASS 1
219 #define DUMMYNET 2
220 #define INCOMING 0
221 #define OUTGOING 1
222
223 size_t strlcpy(char *dst, const char *src, size_t siz);
224 void do_gettimeofday(struct timeval *tv);
225 int ffs(int bits);
226 int time_uptime_w32();
227
228 #endif /* _WINMISSING_H_ */