This repo is obsolete, please see git://git.code.sf.net/p/dummynet/code@master
[ipfw.git] / dummynet2 / 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 5563 2010-02-26 16:25:23Z svn_magno $
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 #define printf          DbgPrint
75 #define log(lev, ...)   DbgPrint(__VA_ARGS__)
76 const char* texify_cmd(int i);
77 const char* texify_proto(unsigned int p);
78 //*** end DEBUG STUFF ***
79
80 #define snprintf _snprintf
81 #define timespec timeval
82 struct timeval {
83         long tv_sec;
84         long tv_usec;
85 };
86
87 struct in_addr {
88         in_addr_t s_addr;
89 };
90
91 struct sockaddr_in {
92         uint8_t sin_len;
93         sa_family_t     sin_family;
94         in_port_t       sin_port;
95         struct  in_addr sin_addr;
96         char    sin_zero[8];
97 };
98
99 /* XXX watch out, windows names are actually longer */
100 #define IFNAMSIZ        16
101 #define IF_NAMESIZE     16
102
103 #define ETHER_ADDR_LEN 6
104
105 /* we do not include the windows headers for in6_addr so
106  * we need to provide our own definition for the kernel.
107  */
108 struct in6_addr {
109         union {
110                 uint8_t         __u6_addr8[16];
111                 uint16_t        __u6_addr16[8]; 
112                 uint32_t        __u6_addr32[4];
113         } __u6_addr;                    /* 128-bit IP6 address */
114 };
115
116 #define htons(x) RtlUshortByteSwap(x)
117 #define ntohs(x) RtlUshortByteSwap(x)
118 #define htonl(x) RtlUlongByteSwap(x)
119 #define ntohl(x) RtlUlongByteSwap(x)
120
121 #define ENOSPC          28      /* No space left on device */
122 #define EOPNOTSUPP      45      /* Operation not supported */
123 #define EACCES          13      /* Permission denied */
124 #define ENOENT          2       /* No such file or directory */
125 #define EINVAL          22      /* Invalid argument */
126 #define EPROTONOSUPPORT 43      /* Protocol not supported */
127 #define ENOMEM          12      /* Cannot allocate memory */
128 #define EEXIST          17      /* File exists */
129 #define ESRCH           3
130 #define ENOBUFS         55      /* No buffer space available */
131 #define EBUSY           16      /* Module busy */
132
133
134 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
135 #define __unused
136 #define __packed 
137 #define __aligned(x);
138 #define __user
139 #define __init
140 #define __exit
141 #define __func__ __FUNCTION__
142 #define inline __inline
143
144 struct sockaddr_in6 {
145         int dummy;
146 };
147
148 //SPINLOCKS
149 #define DEFINE_SPINLOCK(x)              NDIS_SPIN_LOCK x
150 #define mtx_init(m,a,b,c)               NdisAllocateSpinLock(m)
151 #define mtx_lock(_l)                    NdisAcquireSpinLock(_l)
152 #define mtx_unlock(_l)                  NdisReleaseSpinLock(_l)
153 #define mtx_destroy(m)                  NdisFreeSpinLock(m)
154 #define mtx_assert(a, b)
155
156 #define rw_rlock(_l)                    NdisAcquireSpinLock(_l)
157 #define rw_runlock(_l)                  NdisReleaseSpinLock(_l)
158 #define rw_assert(a, b)
159 #define rw_wlock(_l)                    NdisAcquireSpinLock(_l)
160 #define rw_wunlock(_l)                  NdisReleaseSpinLock(_l)
161 #define rw_destroy(_l)                  NdisFreeSpinLock(_l)
162 #define rw_init(_l, msg)                NdisAllocateSpinLock(_l)
163 #define rw_init_flags(_l, s, v)         NdisAllocateSpinLock(_l)
164
165 #define rwlock_t NDIS_SPIN_LOCK
166 #define spinlock_t NDIS_SPIN_LOCK
167
168 #define s6_addr   __u6_addr.__u6_addr8
169
170
171 struct icmphdr {
172         u_char  icmp_type;              /* type of message, see below */
173         u_char  icmp_code;              /* type sub code */
174         u_short icmp_cksum;             /* ones complement cksum of struct */
175 };
176
177 #define ICMP_ECHO               8               /* echo service */
178
179 #define IPOPT_OPTVAL            0               /* option ID */
180 #define IPOPT_OLEN              1               /* option length */
181 #define IPOPT_EOL               0               /* end of option list */
182 #define IPOPT_NOP               1               /* no operation */
183 #define IPOPT_LSRR              131             /* loose source route */
184 #define IPOPT_SSRR              137             /* strict source route */
185 #define IPOPT_RR                7               /* record packet route */
186 #define IPOPT_TS                68              /* timestamp */
187
188 #define IPPROTO_ICMP    1               /* control message protocol */
189 #define IPPROTO_TCP             6               /* tcp */
190 #define IPPROTO_UDP             17              /* user datagram protocol */
191 #define IPPROTO_ICMPV6          58              /* ICMP6 */
192 #define IPPROTO_SCTP            132             /* SCTP */
193 #define IPPROTO_HOPOPTS         0               /* IP6 hop-by-hop options */
194 #define IPPROTO_ROUTING         43              /* IP6 routing header */
195 #define IPPROTO_FRAGMENT        44              /* IP6 fragmentation header */
196 #define IPPROTO_DSTOPTS         60              /* IP6 destination option */
197 #define IPPROTO_AH              51              /* IP6 Auth Header */
198 #define IPPROTO_ESP             50              /* IP6 Encap Sec. Payload */
199 #define IPPROTO_NONE            59              /* IP6 no next header */
200 #define IPPROTO_PIM             103             /* Protocol Independent Mcast */
201
202 #define IPPROTO_IPV6            41
203 #define IPPROTO_IPV4            4               /* IPv4 encapsulation */
204
205
206 #define INADDR_ANY              (uint32_t)0x00000000
207
208 #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
209 #define AF_LINK         18              /* Link layer interface */
210
211 #define IN_CLASSD(i)            (((uint32_t)(i) & 0xf0000000) == 0xe0000000)
212 #define IN_MULTICAST(i)         IN_CLASSD(i)
213
214 #define DROP 0
215 #define PASS 1
216 #define DUMMYNET 2
217 #define INCOMING 0
218 #define OUTGOING 1
219
220 size_t strlcpy(char *dst, const char *src, size_t siz);
221 void do_gettimeofday(struct timeval *tv);
222 int ffs(int bits);
223 int time_uptime_w32();
224
225 #endif /* _WINMISSING_H_ */