xref: /freebsd/sys/powerpc/include/endian.h (revision fa561e1e20629340c0ae693f5d6e7fe8fe3c602b)
1fa561e1eSDavid E. O'Brien /*
2fa561e1eSDavid E. O'Brien  * Copyright (c) 1987, 1991, 1993
3fa561e1eSDavid E. O'Brien  *	The Regents of the University of California.  All rights reserved.
4fa561e1eSDavid E. O'Brien  *
5fa561e1eSDavid E. O'Brien  * Redistribution and use in source and binary forms, with or without
6fa561e1eSDavid E. O'Brien  * modification, are permitted provided that the following conditions
7fa561e1eSDavid E. O'Brien  * are met:
8fa561e1eSDavid E. O'Brien  * 1. Redistributions of source code must retain the above copyright
9fa561e1eSDavid E. O'Brien  *    notice, this list of conditions and the following disclaimer.
10fa561e1eSDavid E. O'Brien  * 2. Redistributions in binary form must reproduce the above copyright
11fa561e1eSDavid E. O'Brien  *    notice, this list of conditions and the following disclaimer in the
12fa561e1eSDavid E. O'Brien  *    documentation and/or other materials provided with the distribution.
13fa561e1eSDavid E. O'Brien  * 3. All advertising materials mentioning features or use of this software
14fa561e1eSDavid E. O'Brien  *    must display the following acknowledgement:
15fa561e1eSDavid E. O'Brien  *	This product includes software developed by the University of
16fa561e1eSDavid E. O'Brien  *	California, Berkeley and its contributors.
17fa561e1eSDavid E. O'Brien  * 4. Neither the name of the University nor the names of its contributors
18fa561e1eSDavid E. O'Brien  *    may be used to endorse or promote products derived from this software
19fa561e1eSDavid E. O'Brien  *    without specific prior written permission.
20fa561e1eSDavid E. O'Brien  *
21fa561e1eSDavid E. O'Brien  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22fa561e1eSDavid E. O'Brien  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23fa561e1eSDavid E. O'Brien  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24fa561e1eSDavid E. O'Brien  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25fa561e1eSDavid E. O'Brien  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26fa561e1eSDavid E. O'Brien  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27fa561e1eSDavid E. O'Brien  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28fa561e1eSDavid E. O'Brien  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29fa561e1eSDavid E. O'Brien  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30fa561e1eSDavid E. O'Brien  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31fa561e1eSDavid E. O'Brien  * SUCH DAMAGE.
32fa561e1eSDavid E. O'Brien  *
33fa561e1eSDavid E. O'Brien  *	@(#)endian.h	8.1 (Berkeley) 6/10/93
34fa561e1eSDavid E. O'Brien  * $NetBSD: endian.h,v 1.7 1999/08/21 05:53:51 simonb Exp $
35fa561e1eSDavid E. O'Brien  * $FreeBSD$
36fa561e1eSDavid E. O'Brien  */
37fa561e1eSDavid E. O'Brien 
38fa561e1eSDavid E. O'Brien #ifndef _ENDIAN_H_
39fa561e1eSDavid E. O'Brien #define	_ENDIAN_H_
40fa561e1eSDavid E. O'Brien 
41fa561e1eSDavid E. O'Brien /*
42fa561e1eSDavid E. O'Brien  * Define the order of 32-bit words in 64-bit words.
43fa561e1eSDavid E. O'Brien  */
44fa561e1eSDavid E. O'Brien #define	_QUAD_HIGHWORD 0
45fa561e1eSDavid E. O'Brien #define	_QUAD_LOWWORD 1
46fa561e1eSDavid E. O'Brien 
47fa561e1eSDavid E. O'Brien #ifndef _POSIX_SOURCE
48fa561e1eSDavid E. O'Brien /*
49fa561e1eSDavid E. O'Brien  * Definitions for byte order, according to byte significance from low
50fa561e1eSDavid E. O'Brien  * address to high.
51fa561e1eSDavid E. O'Brien  */
52fa561e1eSDavid E. O'Brien #define	LITTLE_ENDIAN	1234	/* LSB first: i386, vax */
53fa561e1eSDavid E. O'Brien #define	BIG_ENDIAN	4321	/* MSB first: 68000, ibm, net */
54fa561e1eSDavid E. O'Brien #define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long */
55fa561e1eSDavid E. O'Brien 
56fa561e1eSDavid E. O'Brien #define	BYTE_ORDER	BIG_ENDIAN
57fa561e1eSDavid E. O'Brien 
58fa561e1eSDavid E. O'Brien #include <sys/cdefs.h>
59fa561e1eSDavid E. O'Brien #include <sys/types.h>
60fa561e1eSDavid E. O'Brien 
61fa561e1eSDavid E. O'Brien typedef u_int32_t in_addr_t;
62fa561e1eSDavid E. O'Brien typedef u_int16_t in_port_t;
63fa561e1eSDavid E. O'Brien 
64fa561e1eSDavid E. O'Brien __BEGIN_DECLS
65fa561e1eSDavid E. O'Brien in_addr_t	htonl __P((in_addr_t)) __attribute__((__const__));
66fa561e1eSDavid E. O'Brien in_port_t	htons __P((in_port_t)) __attribute__((__const__));
67fa561e1eSDavid E. O'Brien in_addr_t	ntohl __P((in_addr_t)) __attribute__((__const__));
68fa561e1eSDavid E. O'Brien in_port_t	ntohs __P((in_port_t)) __attribute__((__const__));
69fa561e1eSDavid E. O'Brien u_int16_t	bswap16 __P((u_int16_t)) __attribute__((__const__));
70fa561e1eSDavid E. O'Brien u_int32_t	bswap32 __P((u_int32_t)) __attribute__((__const__));
71fa561e1eSDavid E. O'Brien u_int64_t	bswap64 __P((u_int64_t)) __attribute__((__const__));
72fa561e1eSDavid E. O'Brien __END_DECLS
73fa561e1eSDavid E. O'Brien 
74fa561e1eSDavid E. O'Brien /*
75fa561e1eSDavid E. O'Brien  * Macros for network/external number representation conversion.
76fa561e1eSDavid E. O'Brien  */
77fa561e1eSDavid E. O'Brien #if BYTE_ORDER == BIG_ENDIAN && !defined(lint)
78fa561e1eSDavid E. O'Brien #define	ntohl(x)	(x)
79fa561e1eSDavid E. O'Brien #define	ntohs(x)	(x)
80fa561e1eSDavid E. O'Brien #define	htonl(x)	(x)
81fa561e1eSDavid E. O'Brien #define	htons(x)	(x)
82fa561e1eSDavid E. O'Brien 
83fa561e1eSDavid E. O'Brien #define	NTOHL(x)	(x)
84fa561e1eSDavid E. O'Brien #define	NTOHS(x)	(x)
85fa561e1eSDavid E. O'Brien #define	HTONL(x)	(x)
86fa561e1eSDavid E. O'Brien #define	HTONS(x)	(x)
87fa561e1eSDavid E. O'Brien 
88fa561e1eSDavid E. O'Brien #else
89fa561e1eSDavid E. O'Brien 
90fa561e1eSDavid E. O'Brien #define	NTOHL(x)	(x) = ntohl((in_addr_t)(x))
91fa561e1eSDavid E. O'Brien #define	NTOHS(x)	(x) = ntohs((in_port_t)(x))
92fa561e1eSDavid E. O'Brien #define	HTONL(x)	(x) = htonl((in_addr_t)(x))
93fa561e1eSDavid E. O'Brien #define	HTONS(x)	(x) = htons((in_port_t)(x))
94fa561e1eSDavid E. O'Brien #endif
95fa561e1eSDavid E. O'Brien 
96fa561e1eSDavid E. O'Brien #endif /* !_POSIX_SOURCE */
97fa561e1eSDavid E. O'Brien #endif /* !_ENDIAN_H_ */
98