4 * Copyright (C) 2009 Thomas d'Otreppe
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef _AIRCRACK_NG_BYTEORDER_H_
22 #define _AIRCRACK_NG_BYTEORDER_H_
24 #define ___my_swab16(x) \
26 (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \
27 (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) ))
29 #define ___my_swab32(x) \
31 (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \
32 (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) << 8) | \
33 (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >> 8) | \
34 (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) ))
35 #define ___my_swab64(x) \
37 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000000000ffULL) << 56) | \
38 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \
39 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \
40 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000ff000000ULL) << 8) | \
41 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000ff00000000ULL) >> 8) | \
42 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \
43 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \
44 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) ))
49 #if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux__)
54 #ifndef __int8_t_defined
55 typedef uint64_t u_int64_t;
56 \rtypedef uint32_t u_int32_t;
57 \rtypedef uint16_t u_int16_t;
58 \rtypedef uint8_t u_int8_t;
64 #if __BYTE_ORDER == __LITTLE_ENDIAN
65 #define htobe16(x) ___my_swab16 (x)
66 #define htole16(x) (x)
67 #define be16toh(x) ___my_swab16 (x)
68 #define le16toh(x) (x)
70 #define htobe32(x) ___my_swab32 (x)
71 #define htole32(x) (x)
72 #define be32toh(x) ___my_swab32 (x)
73 #define le32toh(x) (x)
75 #define htobe64(x) ___my_swab64 (x)
76 #define htole64(x) (x)
77 #define be64toh(x) ___my_swab64 (x)
78 #define le64toh(x) (x)
80 #define htobe16(x) (x)
81 #define htole16(x) ___my_swab16 (x)
82 #define be16toh(x) (x)
83 #define le16toh(x) ___my_swab16 (x)
85 #define htobe32(x) (x)
86 #define htole32(x) ___my_swab32 (x)
87 #define be32toh(x) (x)
88 #define le32toh(x) ___my_swab32 (x)
90 #define htobe64(x) (x)
91 #define htole64(x) ___my_swab64 (x)
92 #define be64toh(x) (x)
93 #define le64toh(x) ___my_swab64 (x)
101 #if defined(__CYGWIN32__)
102 #include <asm/byteorder.h>
104 #define __be64_to_cpu(x) ___my_swab64(x)
105 #define __be32_to_cpu(x) ___my_swab32(x)
106 #define __be16_to_cpu(x) ___my_swab16(x)
107 #define __cpu_to_be64(x) ___my_swab64(x)
108 #define __cpu_to_be32(x) ___my_swab32(x)
109 #define __cpu_to_be16(x) ___my_swab16(x)
110 #define __le64_to_cpu(x) (x)
111 #define __le32_to_cpu(x) (x)
112 #define __le16_to_cpu(x) (x)
113 #define __cpu_to_le64(x) (x)
114 #define __cpu_to_le32(x) (x)
115 #define __cpu_to_le16(x) (x)
116 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
123 #define __be64_to_cpu(x) ___my_swab64(x)
124 #define __be32_to_cpu(x) ___my_swab32(x)
125 #define __be16_to_cpu(x) ___my_swab16(x)
126 #define __cpu_to_be64(x) ___my_swab64(x)
127 #define __cpu_to_be32(x) ___my_swab32(x)
128 #define __cpu_to_be16(x) ___my_swab16(x)
129 #define __le64_to_cpu(x) (x)
130 #define __le32_to_cpu(x) (x)
131 #define __le16_to_cpu(x) (x)
132 #define __cpu_to_le64(x) (x)
133 #define __cpu_to_le32(x) (x)
134 #define __cpu_to_le16(x) (x)
135 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
140 #if defined(__APPLE_CC__)
141 #if defined(__x86_64__) && defined(__APPLE__)
142 #include <libkern/OSByteOrder.h>
143 #define __swab64(x) (unsigned long long) OSSwapInt64((uint64_t)x)
144 #define __swab32(x) (unsigned long) OSSwapInt32((uint32_t)x)
145 #define __swab16(x) (unsigned short) OSSwapInt16((uint16_t)x)
146 #define __be64_to_cpu(x) (unsigned long long) OSSwapBigToHostInt64((uint64_t)x)
147 #define __be32_to_cpu(x) (unsigned long) OSSwapBigToHostInt32((uint32_t)x)
148 #define __be16_to_cpu(x) (unsigned short) OSSwapBigToHostInt16((uint16_t)x)
149 #define __le64_to_cpu(x) (unsigned long long) OSSwapLittleToHostInt64((uint64_t)x)
150 #define __le32_to_cpu(x) (unsigned long) OSSwapLittleToHostInt32((uint32_t)x)
151 #define __le16_to_cpu(x) (unsigned short) OSSwapLittleToHostInt16((uint16_t)x)
152 #define __cpu_to_be64(x) (unsigned long long) OSSwapHostToBigInt64((uint64_t)x)
153 #define __cpu_to_be32(x) (unsigned long) OSSwapHostToBigInt32((uint32_t)x)
154 #define __cpu_to_be16(x) (unsigned short) OSSwapHostToBigInt16((uint16_t)x)
155 #define __cpu_to_le64(x) (unsigned long long) OSSwapHostToLittleInt64((uint64_t)x)
156 #define __cpu_to_le32(x) (unsigned long) OSSwapHostToLittleInt32((uint32_t)x)
157 #define __cpu_to_le16(x) (unsigned short) OSSwapHostToLittleInt16((uint16_t)x)
159 #include <architecture/byte_order.h>
160 #define __swab64(x) NXSwapLongLong(x)
161 #define __swab32(x) NXSwapLong(x)
162 #define __swab16(x) NXSwapShort(x)
163 #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
164 #define __be32_to_cpu(x) NXSwapBigLongToHost(x)
165 #define __be16_to_cpu(x) NXSwapBigShortToHost(x)
166 #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
167 #define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
168 #define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
169 #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
170 #define __cpu_to_be32(x) NXSwapHostLongToBig(x)
171 #define __cpu_to_be16(x) NXSwapHostShortToBig(x)
172 #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
173 #define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
174 #define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
176 #define __LITTLE_ENDIAN 1234
177 #define __BIG_ENDIAN 4321
178 #define __PDP_ENDIAN 3412
179 #define __BYTE_ORDER __BIG_ENDIAN
180 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
186 #if defined(__sparc__) && defined(__sun__)
187 #include <sys/byteorder.h>
188 #include <sys/types.h>
190 #define __be64_to_cpu(x) (x)
191 #define __be32_to_cpu(x) (x)
192 #define __be16_to_cpu(x) (x)
193 #define __cpu_to_be64(x) (x)
194 #define __cpu_to_be32(x) (x)
195 #define __cpu_to_be16(x) (x)
196 #define __le64_to_cpu(x) ___my_swab64(x)
197 #define __le32_to_cpu(x) ___my_swab32(x)
198 #define __le16_to_cpu(x) ___my_swab16(x)
199 #define __cpu_to_le64(x) ___my_swab64(x)
200 #define __cpu_to_le32(x) ___my_swab32(x)
201 #define __cpu_to_le16(x) ___my_swab16(x)
202 \rtypedef uint64_t u_int64_t;
203 \rtypedef uint32_t u_int32_t;
204 \rtypedef uint16_t u_int16_t;
205 \rtypedef uint8_t u_int8_t;
208 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
213 #if defined(__MACH__) && !defined(__APPLE_CC__)
214 #include <libkern/OSByteOrder.h>
215 #define __cpu_to_be64(x) = OSSwapHostToBigInt64(x)
216 #define __cpu_to_be32(x) = OSSwapHostToBigInt32(x)
217 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
222 #include <machine/endian.h>
224 // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...?
226 // XXX: Mac: Check http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h
227 // http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html
228 // Write to apple to ask what should be used.
229 #if defined(LITTLE_ENDIAN)
230 #define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN
231 #elif defined(__LITTLE_ENDIAN)
232 #define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN
233 #elif defined(_LITTLE_ENDIAN)
234 #define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN
236 #if defined(BIG_ENDIAN)
237 #define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN
238 #elif defined(__BIG_ENDIAN)
239 #define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN
240 #elif defined(_BIG_ENDIAN)
241 #define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN
243 #if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && !defined(AIRCRACK_NG_BIG_ENDIAN)
244 #error Impossible to determine endianness (Little or Big endian), please contact the author.
246 #if defined(BYTE_ORDER)
247 #if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
248 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
249 #elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
250 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
252 #elif defined(__BYTE_ORDER)
253 #if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
254 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
255 #elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
256 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
258 #elif defined(_BYTE_ORDER)
259 #if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
260 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
261 #elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
262 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
265 #ifndef AIRCRACK_NG_BYTE_ORDER
266 #error Impossible to determine endianness (Little or Big endian), please contact the author.
268 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
269 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
270 #define __be64_to_cpu(x) ___my_swab64(x)
271 #define __be32_to_cpu(x) ___my_swab32(x)
272 #define __be16_to_cpu(x) ___my_swab16(x)
273 #define __cpu_to_be64(x) ___my_swab64(x)
274 #define __cpu_to_be32(x) ___my_swab32(x)
275 #define __cpu_to_be16(x) ___my_swab16(x)
276 #define __le64_to_cpu(x) (x)
277 #define __le32_to_cpu(x) (x)
278 #define __le16_to_cpu(x) (x)
279 #define __cpu_to_le64(x) (x)
280 #define __cpu_to_le32(x) (x)
281 #define __cpu_to_le16(x) (x)
284 #define htobe16 ___my_swab16
287 #define htobe32 ___my_swab32
290 #define betoh16 ___my_swab16
293 #define betoh32 ___my_swab32
296 #define htole16(x) (x)
299 #define htole32(x) (x)
302 #define letoh16(x) (x)
305 #define letoh32(x) (x)
308 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
309 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
310 #define __be64_to_cpu(x) (x)
311 #define __be32_to_cpu(x) (x)
312 #define __be16_to_cpu(x) (x)
313 #define __cpu_to_be64(x) (x)
314 #define __cpu_to_be32(x) (x)
315 #define __cpu_to_be16(x) (x)
316 #define __le64_to_cpu(x) ___my_swab64(x)
317 #define __le32_to_cpu(x) ___my_swab32(x)
318 #define __le16_to_cpu(x) ___my_swab16(x)
319 #define __cpu_to_le64(x) ___my_swab64(x)
320 #define __cpu_to_le32(x) ___my_swab32(x)
321 #define __cpu_to_le16(x) ___my_swab16(x)
324 #define htobe16(x) (x)
327 #define htobe32(x) (x)
330 #define betoh16(x) (x)
333 #define betoh32(x) (x)
336 #define htole16 ___my_swab16
339 #define htole32 ___my_swab32
342 #define letoh16 ___my_swab16
345 #define letoh32 ___my_swab32
349 #define cpu_to_le64 __cpu_to_le64
350 #define le64_to_cpu __le64_to_cpu
351 #define cpu_to_le32 __cpu_to_le32
352 #define le32_to_cpu __le32_to_cpu
353 #define cpu_to_le16 __cpu_to_le16
354 #define le16_to_cpu __le16_to_cpu
355 #define cpu_to_be64 __cpu_to_be64
356 #define be64_to_cpu __be64_to_cpu
357 #define cpu_to_be32 __cpu_to_be32
358 #define be32_to_cpu __be32_to_cpu
359 #define cpu_to_be16 __cpu_to_be16
360 #define be16_to_cpu __be16_to_cpu
362 #define le16toh le16_to_cpu
365 #define be16toh be16_to_cpu
368 #define le32toh le32_to_cpu
371 #define be32toh be32_to_cpu
375 #define htons be16_to_cpu
378 #define htonl cpu_to_be16
381 #define ntohs cpu_to_be16
384 #define ntohl cpu_to_be32