]>
Commit | Line | Data |
---|---|---|
ccc36f2f | 1 | /* |
91447636 A |
2 | * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
91447636 | 11 | * |
37839358 A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
91447636 A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
91447636 A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | ||
23 | /* | |
24 | * Copyright (c) 1995 NeXT Computer, Inc. All rights reserved. | |
ccc36f2f A |
25 | * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. |
26 | * | |
27 | * @APPLE_LICENSE_HEADER_START@ | |
28 | * | |
37839358 A |
29 | * The contents of this file constitute Original Code as defined in and |
30 | * are subject to the Apple Public Source License Version 1.1 (the | |
31 | * "License"). You may not use this file except in compliance with the | |
32 | * License. Please obtain a copy of the License at | |
33 | * http://www.apple.com/publicsource and read it before using this file. | |
ccc36f2f | 34 | * |
37839358 A |
35 | * This Original Code and all software distributed under the License are |
36 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
ccc36f2f A |
37 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
38 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
39 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
40 | * License for the specific language governing rights and limitations | |
41 | * under the License. | |
ccc36f2f A |
42 | * |
43 | * @APPLE_LICENSE_HEADER_END@ | |
44 | */ | |
ccc36f2f | 45 | /* |
91447636 | 46 | * Copyright (c) 1987, 1991, 1993 |
ccc36f2f A |
47 | * The Regents of the University of California. All rights reserved. |
48 | * | |
ccc36f2f A |
49 | * Redistribution and use in source and binary forms, with or without |
50 | * modification, are permitted provided that the following conditions | |
51 | * are met: | |
52 | * 1. Redistributions of source code must retain the above copyright | |
53 | * notice, this list of conditions and the following disclaimer. | |
54 | * 2. Redistributions in binary form must reproduce the above copyright | |
55 | * notice, this list of conditions and the following disclaimer in the | |
56 | * documentation and/or other materials provided with the distribution. | |
57 | * 3. All advertising materials mentioning features or use of this software | |
58 | * must display the following acknowledgement: | |
59 | * This product includes software developed by the University of | |
60 | * California, Berkeley and its contributors. | |
61 | * 4. Neither the name of the University nor the names of its contributors | |
62 | * may be used to endorse or promote products derived from this software | |
63 | * without specific prior written permission. | |
64 | * | |
65 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
66 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
67 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
68 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
69 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
70 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
71 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
72 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
73 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
74 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
75 | * SUCH DAMAGE. | |
ccc36f2f | 76 | */ |
ccc36f2f | 77 | |
91447636 A |
78 | #ifndef _SYS__ENDIAN_H_ |
79 | #define _SYS__ENDIAN_H_ | |
80 | ||
81 | #include <sys/cdefs.h> | |
ccc36f2f | 82 | |
ccc36f2f | 83 | /* |
91447636 | 84 | * Macros for network/external number representation conversion. |
ccc36f2f | 85 | */ |
91447636 A |
86 | #if __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN && !defined(lint) |
87 | #define ntohl(x) (x) | |
88 | #define ntohs(x) (x) | |
89 | #define htonl(x) (x) | |
90 | #define htons(x) (x) | |
ccc36f2f | 91 | |
91447636 A |
92 | #if defined(KERNEL) || !defined(_POSIX_C_SOURCE) |
93 | #define NTOHL(x) (x) | |
94 | #define NTOHS(x) (x) | |
95 | #define HTONL(x) (x) | |
96 | #define HTONS(x) (x) | |
97 | #endif /* defined(KERNEL) || !defined(_POSIX_C_SOURCE) */ | |
ccc36f2f | 98 | |
91447636 | 99 | #else |
ccc36f2f | 100 | |
91447636 | 101 | #if !defined(__ASSEMBLER__) |
ccc36f2f | 102 | |
91447636 A |
103 | #include <stdint.h> |
104 | #include <machine/byte_order.h> | |
105 | ||
ccc36f2f | 106 | __BEGIN_DECLS |
91447636 A |
107 | uint16_t ntohs(uint16_t); |
108 | uint16_t htons(uint16_t); | |
109 | uint32_t ntohl(uint32_t); | |
110 | uint32_t htonl(uint32_t); | |
ccc36f2f | 111 | __END_DECLS |
91447636 A |
112 | #endif /* !defined(__ASSEMBLER__) */ |
113 | ||
114 | #define ntohs(x) NXSwapBigShortToHost(x) | |
115 | #define htons(x) NXSwapHostShortToBig(x) | |
ccc36f2f | 116 | |
91447636 A |
117 | #if defined(__LP64__) |
118 | #define ntohl(x) NXSwapBigIntToHost(x) | |
119 | #define htonl(x) NXSwapHostIntToBig(x) | |
120 | #else | |
121 | #define ntohl(x) NXSwapBigLongToHost(x) | |
122 | #define htonl(x) NXSwapHostLongToBig(x) | |
123 | #endif /* defined(__LP64__) */ | |
ccc36f2f | 124 | |
91447636 A |
125 | #if defined(KERNEL) || !defined(_POSIX_C_SOURCE) |
126 | #define NTOHL(x) (x) = ntohl((u_long)x) | |
127 | #define NTOHS(x) (x) = ntohs((u_short)x) | |
128 | #define HTONL(x) (x) = htonl((u_long)x) | |
129 | #define HTONS(x) (x) = htons((u_short)x) | |
130 | #endif /* defined(KERNEL) || !defined(_POSIX_C_SOURCE) */ | |
131 | #endif /* __DARWIN_BYTE_ORDER != __DARWIN_BIG_ENDIAN || defined(lint) */ | |
132 | #endif /* !_SYS__ENDIAN_H_ */ |