1 /* 2 * Copyright (c) 1987, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)endian.h 8.1 (Berkeley) 06/10/93 8 */ 9 10 #ifndef _ENDIAN_H_ 11 #define _ENDIAN_H_ 12 13 /* 14 * Define the order of 32-bit words in 64-bit words. 15 */ 16 #define _QUAD_HIGHWORD 0 17 #define _QUAD_LOWWORD 1 18 19 #ifndef _POSIX_SOURCE 20 /* 21 * Definitions for byte order, according to byte significance from low 22 * address to high. 23 */ 24 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ 25 #define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ 26 #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ 27 28 #define BYTE_ORDER BIG_ENDIAN 29 30 #include <sys/cdefs.h> 31 32 __BEGIN_DECLS 33 unsigned long htonl __P((unsigned long)); 34 unsigned short htons __P((unsigned short)); 35 unsigned long ntohl __P((unsigned long)); 36 unsigned short ntohs __P((unsigned short)); 37 __END_DECLS 38 39 /* 40 * Macros for network/external number representation conversion. 41 */ 42 #if BYTE_ORDER == BIG_ENDIAN && !defined(lint) 43 #define ntohl(x) (x) 44 #define ntohs(x) (x) 45 #define htonl(x) (x) 46 #define htons(x) (x) 47 48 #define NTOHL(x) (x) 49 #define NTOHS(x) (x) 50 #define HTONL(x) (x) 51 #define HTONS(x) (x) 52 53 #else 54 55 #define NTOHL(x) (x) = ntohl((u_long)x) 56 #define NTOHS(x) (x) = ntohs((u_short)x) 57 #define HTONL(x) (x) = htonl((u_long)x) 58 #define HTONS(x) (x) = htons((u_short)x) 59 #endif 60 #endif /* !_POSIX_SOURCE */ 61 #endif /* !_ENDIAN_H_ */ 62