xref: /csrg-svn/sys/pmax/include/endian.h (revision 40610)
133280Sbostic /*
233280Sbostic  * Copyright (c) 1987 Regents of the University of California.
333280Sbostic  * All rights reserved.
433280Sbostic  *
533280Sbostic  * Redistribution and use in source and binary forms are permitted
634867Sbostic  * provided that the above copyright notice and this paragraph are
734867Sbostic  * duplicated in all such forms and that any documentation,
834867Sbostic  * advertising materials, and other materials related to such
934867Sbostic  * distribution and use acknowledge that the software was developed
1034867Sbostic  * by the University of California, Berkeley.  The name of the
1134867Sbostic  * University may not be used to endorse or promote products derived
1234867Sbostic  * from this software without specific prior written permission.
1334867Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434867Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534867Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1633280Sbostic  *
17*40610Skarels  *	@(#)endian.h	7.4 (Berkeley) 03/23/90
1833280Sbostic  */
1933280Sbostic 
2033280Sbostic /*
2133280Sbostic  * Definitions for byte order,
2233280Sbostic  * according to byte significance from low address to high.
2333280Sbostic  */
2433280Sbostic #define	LITTLE_ENDIAN	1234	/* least-significant byte first (vax) */
2533280Sbostic #define	BIG_ENDIAN	4321	/* most-significant byte first (IBM, net) */
2633280Sbostic #define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long (pdp) */
2733280Sbostic 
2833280Sbostic #define	BYTE_ORDER	LITTLE_ENDIAN	/* byte order on vax */
2933280Sbostic 
3033280Sbostic /*
3133280Sbostic  * Macros for network/external number representation conversion.
3233280Sbostic  */
3333381Skarels #if BYTE_ORDER == BIG_ENDIAN && !defined(lint)
3433280Sbostic #define	ntohl(x)	(x)
3533280Sbostic #define	ntohs(x)	(x)
3633280Sbostic #define	htonl(x)	(x)
3733280Sbostic #define	htons(x)	(x)
38*40610Skarels 
39*40610Skarels #define	NTOHL(x)	(x)
40*40610Skarels #define	NTOHS(x)	(x)
41*40610Skarels #define	HTONL(x)	(x)
42*40610Skarels #define	HTONS(x)	(x)
43*40610Skarels 
4433280Sbostic #else
45*40610Skarels 
4633280Sbostic unsigned short	ntohs(), htons();
4733280Sbostic unsigned long	ntohl(), htonl();
48*40610Skarels 
49*40610Skarels #define	NTOHL(x)	(x) = ntohl(x)
50*40610Skarels #define	NTOHS(x)	(x) = ntohs(x)
51*40610Skarels #define	HTONL(x)	(x) = htonl(x)
52*40610Skarels #define	HTONS(x)	(x) = htons(x)
5333280Sbostic #endif
54