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