2 * Copyright (c) 2010 Francesco Magno, Universita` di Pisa
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
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)
32 #ifndef _WINMISSING_H_
33 #define _WINMISSING_H_
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;
50 typedef INT32 int32_t;
51 typedef UINT32 u_int32_t;
52 typedef UINT32 uint32_t;
55 typedef UINT64 uint64_t;
56 typedef UINT64 u_int64_t;
57 typedef INT64 int64_t;
59 typedef UINT32 in_addr_t;
60 typedef UCHAR sa_family_t;
61 typedef USHORT in_port_t;
62 typedef UINT32 __gid_t;
64 typedef UINT32 __uid_t;
67 typedef char* caddr_t;
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 */
75 * To see the debugging messages you need DbgView
76 http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx
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 ***
84 #define snprintf _snprintf
85 #define timespec timeval
97 sa_family_t sin_family;
99 struct in_addr sin_addr;
103 /* XXX watch out, windows names are actually longer */
105 #define IF_NAMESIZE 16
107 #define ETHER_ADDR_LEN 6
109 /* we do not include the windows headers for in6_addr so
110 * we need to provide our own definition for the kernel.
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 */
120 #define htons(x) RtlUshortByteSwap(x)
121 #define ntohs(x) RtlUshortByteSwap(x)
122 #define htonl(x) RtlUlongByteSwap(x)
123 #define ntohl(x) RtlUlongByteSwap(x)
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 */
134 #define ENOBUFS 55 /* No buffer space available */
135 #define EBUSY 16 /* Module busy */
138 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
140 #define __aligned(x);
144 #define __func__ __FUNCTION__
145 #define inline __inline
147 struct sockaddr_in6 {
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)
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)
168 #define rwlock_t NDIS_SPIN_LOCK
169 #define spinlock_t NDIS_SPIN_LOCK
171 #define s6_addr __u6_addr.__u6_addr8
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 */
180 #define ICMP_ECHO 8 /* echo service */
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 */
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 */
205 #define IPPROTO_IPV6 41
206 #define IPPROTO_IPV4 4 /* IPv4 encapsulation */
209 #define INADDR_ANY (uint32_t)0x00000000
211 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
212 #define AF_LINK 18 /* Link layer interface */
214 #define IN_CLASSD(i) (((uint32_t)(i) & 0xf0000000) == 0xe0000000)
215 #define IN_MULTICAST(i) IN_CLASSD(i)
223 size_t strlcpy(char *dst, const char *src, size_t siz);
224 void do_gettimeofday(struct timeval *tv);
226 int time_uptime_w32();
228 #endif /* _WINMISSING_H_ */