]>
Commit | Line | Data |
---|---|---|
772db4bb | 1 | /** @file |
2 | ||
3 | Copyright (c) 2004, Intel Corporation | |
4 | All rights reserved. This program and the accompanying materials | |
5 | are licensed and made available under the terms and conditions of the BSD License | |
6 | which accompanies this distribution. The full text of the license may be found at | |
7 | http://opensource.org/licenses/bsd-license.php | |
8 | ||
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
11 | ||
12 | Module name: | |
13 | hton.h | |
14 | ||
15 | Abstract: | |
16 | Byte swapping macros. | |
17 | ||
18 | ||
19 | **/ | |
20 | ||
21 | #ifndef _HTON_H_ | |
22 | #define _HTON_H_ | |
23 | ||
24 | // | |
25 | // Only Intel order functions are defined at this time. | |
26 | // | |
27 | #define HTONS(v) (UINT16) ((((v) << 8) & 0xff00) + (((v) >> 8) & 0x00ff)) | |
28 | ||
29 | #define HTONL(v) \ | |
30 | (UINT32) ((((v) << 24) & 0xff000000) + (((v) << 8) & 0x00ff0000) + (((v) >> 8) & 0x0000ff00) + (((v) >> 24) & 0x000000ff)) | |
31 | ||
32 | #define HTONLL(v) swap64 (v) | |
33 | ||
34 | #define U8PTR(na) ((UINT8 *) &(na)) | |
35 | ||
36 | #define NTOHS(ns) ((UINT16) (((*U8PTR (ns)) << 8) +*(U8PTR (ns) + 1))) | |
37 | ||
38 | #define NTOHL(ns) \ | |
39 | ((UINT32) (((*U8PTR (ns)) << 24) + ((*(U8PTR (ns) + 1)) << 16) + ((*(U8PTR (ns) + 2)) << 8) +*(U8PTR (ns) + 3))) | |
40 | ||
41 | #endif /* _HTON_H_ */ | |
42 | ||
43 | /* EOF - hton.h */ |