2 * Compatibility header
\r
4 * Copyright (C) 2009 Thomas d'Otreppe
\r
6 * This program is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * This program is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
21 #ifndef _AIRCRACK_NG_BYTEORDER_H_
\r
22 #define _AIRCRACK_NG_BYTEORDER_H_
\r
24 #define ___my_swab16(x) \
\r
26 (((u_int16_t) (x) & (u_int16_t) 0x00ffU) << 8) | \
\r
27 (((u_int16_t) (x) & (u_int16_t) 0xff00U) >> 8)))
\r
28 #define ___my_swab32(x) \
\r
30 (((u_int32_t) (x) & (u_int32_t) 0x000000ffUL) << 24) | \
\r
31 (((u_int32_t) (x) & (u_int32_t) 0x0000ff00UL) << 8) | \
\r
32 (((u_int32_t) (x) & (u_int32_t) 0x00ff0000UL) >> 8) | \
\r
33 (((u_int32_t) (x) & (u_int32_t) 0xff000000UL) >> 24)))
\r
34 #define ___my_swab64(x) \
\r
36 (u_int64_t) (((u_int64_t) (x) & (u_int64_t)
37 0x00000000000000ffULL) << 56) |
38 \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
39 0x000000000000ff00ULL) << 40) |
40 \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
41 0x0000000000ff0000ULL) << 24) |
42 \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
43 0x00000000ff000000ULL) << 8) |
44 \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
45 0x000000ff00000000ULL) >> 8) |
46 \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
47 0x0000ff0000000000ULL) >> 24) |
48 \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
49 0x00ff000000000000ULL) >> 40) |
50 \
\r(u_int64_t) (((u_int64_t) (x) & (u_int64_t)
51 0xff00000000000000ULL) >> 56)))
\r \r \r
55 #if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux__)
\r
60 #ifndef __int8_t_defined
\r
61 typedef uint64_t u_int64_t;
62 \rtypedef uint32_t u_int32_t;
63 \rtypedef uint16_t u_int16_t;
64 \rtypedef uint8_t u_int8_t;
70 #if __BYTE_ORDER == __LITTLE_ENDIAN
\r
71 #define htobe16(x) ___my_swab16 (x)
\r
72 #define htole16(x) (x)
\r
73 #define be16toh(x) ___my_swab16 (x)
\r
74 #define le16toh(x) (x)
\r
76 #define htobe32(x) ___my_swab32 (x)
\r
77 #define htole32(x) (x)
\r
78 #define be32toh(x) ___my_swab32 (x)
\r
79 #define le32toh(x) (x)
\r
81 #define htobe64(x) ___my_swab64 (x)
\r
82 #define htole64(x) (x)
\r
83 #define be64toh(x) ___my_swab64 (x)
\r
84 #define le64toh(x) (x)
\r
86 #define htobe16(x) (x)
\r
87 #define htole16(x) ___my_swab16 (x)
\r
88 #define be16toh(x) (x)
\r
89 #define le16toh(x) ___my_swab16 (x)
\r
91 #define htobe32(x) (x)
\r
92 #define htole32(x) ___my_swab32 (x)
\r
93 #define be32toh(x) (x)
\r
94 #define le32toh(x) ___my_swab32 (x)
\r
96 #define htobe64(x) (x)
\r
97 #define htole64(x) ___my_swab64 (x)
\r
98 #define be64toh(x) (x)
\r
99 #define le64toh(x) ___my_swab64 (x)
\r
108 #if defined(__CYGWIN32__)
\r
109 #include <asm/byteorder.h>
\r
110 #include <unistd.h>
\r
112 #define __be64_to_cpu(x) ___my_swab64(x)
\r
113 #define __be32_to_cpu(x) ___my_swab32(x)
\r
114 #define __be16_to_cpu(x) ___my_swab16(x)
\r
115 #define __cpu_to_be64(x) ___my_swab64(x)
\r
116 #define __cpu_to_be32(x) ___my_swab32(x)
\r
117 #define __cpu_to_be16(x) ___my_swab16(x)
\r
118 #define __le64_to_cpu(x) (x)
\r
119 #define __le32_to_cpu(x) (x)
\r
120 #define __le16_to_cpu(x) (x)
\r
121 #define __cpu_to_le64(x) (x)
\r
122 #define __cpu_to_le32(x) (x)
\r
123 #define __cpu_to_le16(x) (x)
\r
125 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
132 #if defined(__WIN__)
\r
136 #define __be64_to_cpu(x) ___my_swab64(x)
\r
137 #define __be32_to_cpu(x) ___my_swab32(x)
\r
138 #define __be16_to_cpu(x) ___my_swab16(x)
\r
139 #define __cpu_to_be64(x) ___my_swab64(x)
\r
140 #define __cpu_to_be32(x) ___my_swab32(x)
\r
141 #define __cpu_to_be16(x) ___my_swab16(x)
\r
142 #define __le64_to_cpu(x) (x)
\r
143 #define __le32_to_cpu(x) (x)
\r
144 #define __le16_to_cpu(x) (x)
\r
145 #define __cpu_to_le64(x) (x)
\r
146 #define __cpu_to_le32(x) (x)
\r
147 #define __cpu_to_le16(x) (x)
\r
149 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
156 #if defined(__APPLE_CC__)
\r
157 #if defined(__x86_64__) && defined(__APPLE__)
\r
159 #include <libkern/OSByteOrder.h>
\r
161 #define __swab64(x) (unsigned long long) OSSwapInt64((uint64_t)x)
\r
162 #define __swab32(x) (unsigned long) OSSwapInt32((uint32_t)x)
\r
163 #define __swab16(x) (unsigned short) OSSwapInt16((uint16_t)x)
\r
164 #define __be64_to_cpu(x) (unsigned long long) OSSwapBigToHostInt64((uint64_t)x)
\r
165 #define __be32_to_cpu(x) (unsigned long) OSSwapBigToHostInt32((uint32_t)x)
\r
166 #define __be16_to_cpu(x) (unsigned short) OSSwapBigToHostInt16((uint16_t)x)
\r
167 #define __le64_to_cpu(x) (unsigned long long) OSSwapLittleToHostInt64((uint64_t)x)
\r
168 #define __le32_to_cpu(x) (unsigned long) OSSwapLittleToHostInt32((uint32_t)x)
\r
169 #define __le16_to_cpu(x) (unsigned short) OSSwapLittleToHostInt16((uint16_t)x)
\r
170 #define __cpu_to_be64(x) (unsigned long long) OSSwapHostToBigInt64((uint64_t)x)
\r
171 #define __cpu_to_be32(x) (unsigned long) OSSwapHostToBigInt32((uint32_t)x)
\r
172 #define __cpu_to_be16(x) (unsigned short) OSSwapHostToBigInt16((uint16_t)x)
\r
173 #define __cpu_to_le64(x) (unsigned long long) OSSwapHostToLittleInt64((uint64_t)x)
\r
174 #define __cpu_to_le32(x) (unsigned long) OSSwapHostToLittleInt32((uint32_t)x)
\r
175 #define __cpu_to_le16(x) (unsigned short) OSSwapHostToLittleInt16((uint16_t)x)
\r
179 #include <architecture/byte_order.h>
\r
181 #define __swab64(x) NXSwapLongLong(x)
\r
182 #define __swab32(x) NXSwapLong(x)
\r
183 #define __swab16(x) NXSwapShort(x)
\r
184 #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
\r
185 #define __be32_to_cpu(x) NXSwapBigLongToHost(x)
\r
186 #define __be16_to_cpu(x) NXSwapBigShortToHost(x)
\r
187 #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
\r
188 #define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
\r
189 #define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
\r
190 #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
\r
191 #define __cpu_to_be32(x) NXSwapHostLongToBig(x)
\r
192 #define __cpu_to_be16(x) NXSwapHostShortToBig(x)
\r
193 #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
\r
194 #define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
\r
195 #define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
\r
199 #define __LITTLE_ENDIAN 1234
\r
200 #define __BIG_ENDIAN 4321
\r
201 #define __PDP_ENDIAN 3412
\r
202 #define __BYTE_ORDER __BIG_ENDIAN
\r
204 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
212 #if defined(__sparc__) && defined(__sun__)
\r
213 #include <sys/byteorder.h>
\r
214 #include <sys/types.h>
\r
215 #include <unistd.h>
\r
217 #define __be64_to_cpu(x) (x)
\r
218 #define __be32_to_cpu(x) (x)
\r
219 #define __be16_to_cpu(x) (x)
\r
220 #define __cpu_to_be64(x) (x)
\r
221 #define __cpu_to_be32(x) (x)
\r
222 #define __cpu_to_be16(x) (x)
\r
223 #define __le64_to_cpu(x) ___my_swab64(x)
\r
224 #define __le32_to_cpu(x) ___my_swab32(x)
\r
225 #define __le16_to_cpu(x) ___my_swab16(x)
\r
226 #define __cpu_to_le64(x) ___my_swab64(x)
\r
227 #define __cpu_to_le32(x) ___my_swab32(x)
\r
228 #define __cpu_to_le16(x) ___my_swab16(x)
\r
229 \rtypedef uint64_t u_int64_t;
230 \rtypedef uint32_t u_int32_t;
231 \rtypedef uint16_t u_int16_t;
232 \rtypedef uint8_t u_int8_t;
235 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
242 #if defined(__MACH__) && !defined(__APPLE_CC__)
\r
243 #include <libkern/OSByteOrder.h>
\r
244 #define __cpu_to_be64(x) = OSSwapHostToBigInt64(x)
\r
245 #define __cpu_to_be32(x) = OSSwapHostToBigInt32(x)
\r
247 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
253 #include <machine/endian.h>
\r
256 // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...?
\r
258 // XXX: Mac: Check http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h
\r
259 // http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html
\r
260 // Write to apple to ask what should be used.
\r
262 #if defined(LITTLE_ENDIAN)
\r
263 #define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN
\r
264 #elif defined(__LITTLE_ENDIAN)
\r
265 #define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN
\r
266 #elif defined(_LITTLE_ENDIAN)
\r
267 #define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN
\r
270 #if defined(BIG_ENDIAN)
\r
271 #define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN
\r
272 #elif defined(__BIG_ENDIAN)
\r
273 #define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN
\r
274 #elif defined(_BIG_ENDIAN)
\r
275 #define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN
\r
278 #if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && !defined(AIRCRACK_NG_BIG_ENDIAN)
\r
279 #error Impossible to determine endianness (Little or Big endian), please contact the author.
\r
282 #if defined(BYTE_ORDER)
\r
283 #if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
\r
284 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
\r
285 #elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
\r
286 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
\r
288 #elif defined(__BYTE_ORDER)
\r
289 #if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
\r
290 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
\r
291 #elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
\r
292 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
\r
294 #elif defined(_BYTE_ORDER)
\r
295 #if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
\r
296 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
\r
297 #elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
\r
298 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
\r
302 #ifndef AIRCRACK_NG_BYTE_ORDER
\r
303 #error Impossible to determine endianness (Little or Big endian), please contact the author.
\r
306 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
\r
308 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
309 #define __be64_to_cpu(x) ___my_swab64(x)
\r
310 #define __be32_to_cpu(x) ___my_swab32(x)
\r
311 #define __be16_to_cpu(x) ___my_swab16(x)
\r
312 #define __cpu_to_be64(x) ___my_swab64(x)
\r
313 #define __cpu_to_be32(x) ___my_swab32(x)
\r
314 #define __cpu_to_be16(x) ___my_swab16(x)
\r
315 #define __le64_to_cpu(x) (x)
\r
316 #define __le32_to_cpu(x) (x)
\r
317 #define __le16_to_cpu(x) (x)
\r
318 #define __cpu_to_le64(x) (x)
\r
319 #define __cpu_to_le32(x) (x)
\r
320 #define __cpu_to_le16(x) (x)
\r
324 #define htobe16 ___my_swab16
\r
327 #define htobe32 ___my_swab32
\r
330 #define betoh16 ___my_swab16
\r
333 #define betoh32 ___my_swab32
\r
337 #define htole16(x) (x)
\r
340 #define htole32(x) (x)
\r
343 #define letoh16(x) (x)
\r
346 #define letoh32(x) (x)
\r
351 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
\r
353 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
\r
354 #define __be64_to_cpu(x) (x)
\r
355 #define __be32_to_cpu(x) (x)
\r
356 #define __be16_to_cpu(x) (x)
\r
357 #define __cpu_to_be64(x) (x)
\r
358 #define __cpu_to_be32(x) (x)
\r
359 #define __cpu_to_be16(x) (x)
\r
360 #define __le64_to_cpu(x) ___my_swab64(x)
\r
361 #define __le32_to_cpu(x) ___my_swab32(x)
\r
362 #define __le16_to_cpu(x) ___my_swab16(x)
\r
363 #define __cpu_to_le64(x) ___my_swab64(x)
\r
364 #define __cpu_to_le32(x) ___my_swab32(x)
\r
365 #define __cpu_to_le16(x) ___my_swab16(x)
\r
369 #define htobe16(x) (x)
\r
372 #define htobe32(x) (x)
\r
375 #define betoh16(x) (x)
\r
378 #define betoh32(x) (x)
\r
382 #define htole16 ___my_swab16
\r
385 #define htole32 ___my_swab32
\r
388 #define letoh16 ___my_swab16
\r
391 #define letoh32 ___my_swab32
\r
397 #define cpu_to_le64 __cpu_to_le64
\r
398 #define le64_to_cpu __le64_to_cpu
\r
399 #define cpu_to_le32 __cpu_to_le32
\r
400 #define le32_to_cpu __le32_to_cpu
\r
401 #define cpu_to_le16 __cpu_to_le16
\r
402 #define le16_to_cpu __le16_to_cpu
\r
403 #define cpu_to_be64 __cpu_to_be64
\r
404 #define be64_to_cpu __be64_to_cpu
\r
405 #define cpu_to_be32 __cpu_to_be32
\r
406 #define be32_to_cpu __be32_to_cpu
\r
407 #define cpu_to_be16 __cpu_to_be16
\r
408 #define be16_to_cpu __be16_to_cpu
\r
411 #define le16toh le16_to_cpu
\r
414 #define be16toh be16_to_cpu
\r
417 #define le32toh le32_to_cpu
\r
420 #define be32toh be32_to_cpu
\r
424 #define htons be16_to_cpu
\r
427 #define htonl cpu_to_be16
\r
430 #define ntohs cpu_to_be16
\r
433 #define ntohl cpu_to_be32
\r