133277Sbostic /* 2*63160Sbostic * Copyright (c) 1987, 1991, 1993 3*63160Sbostic * The Regents of the University of California. All rights reserved. 433277Sbostic * 544526Sbostic * %sccs.include.redist.c% 633277Sbostic * 7*63160Sbostic * @(#)endian.h 8.1 (Berkeley) 06/10/93 833277Sbostic */ 933277Sbostic 1059799Smckusick #ifndef _ENDIAN_H_ 1159799Smckusick #define _ENDIAN_H_ 1259799Smckusick 1333277Sbostic /* 1452003Smckusick * Define the order of 32-bit words in 64-bit words. 1552003Smckusick */ 1652003Smckusick #define _QUAD_HIGHWORD 0 1752003Smckusick #define _QUAD_LOWWORD 1 1852003Smckusick 1952003Smckusick #ifndef _POSIX_SOURCE 2052003Smckusick /* 2147794Sbostic * Definitions for byte order, according to byte significance from low 2247794Sbostic * address to high. 2333277Sbostic */ 2447794Sbostic #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ 2547794Sbostic #define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ 2647794Sbostic #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ 2733277Sbostic 2847792Sbostic #define BYTE_ORDER BIG_ENDIAN 2933277Sbostic 3047794Sbostic #include <sys/cdefs.h> 3147794Sbostic 3247794Sbostic __BEGIN_DECLS 3347794Sbostic unsigned long htonl __P((unsigned long)); 3447794Sbostic unsigned short htons __P((unsigned short)); 3547794Sbostic unsigned long ntohl __P((unsigned long)); 3647794Sbostic unsigned short ntohs __P((unsigned short)); 3747794Sbostic __END_DECLS 3847794Sbostic 3933277Sbostic /* 4033277Sbostic * Macros for network/external number representation conversion. 4133277Sbostic */ 4233380Skarels #if BYTE_ORDER == BIG_ENDIAN && !defined(lint) 4333277Sbostic #define ntohl(x) (x) 4433277Sbostic #define ntohs(x) (x) 4533277Sbostic #define htonl(x) (x) 4633277Sbostic #define htons(x) (x) 4740611Skarels 4840611Skarels #define NTOHL(x) (x) 4940611Skarels #define NTOHS(x) (x) 5040611Skarels #define HTONL(x) (x) 5140611Skarels #define HTONS(x) (x) 5240611Skarels 5333277Sbostic #else 5440611Skarels 5547794Sbostic #define NTOHL(x) (x) = ntohl((u_long)x) 5647794Sbostic #define NTOHS(x) (x) = ntohs((u_short)x) 5747794Sbostic #define HTONL(x) (x) = htonl((u_long)x) 5847794Sbostic #define HTONS(x) (x) = htons((u_short)x) 5933277Sbostic #endif 6052003Smckusick #endif /* !_POSIX_SOURCE */ 6159799Smckusick #endif /* !_ENDIAN_H_ */ 62