133280Sbostic /* 2*63358Sbostic * Copyright (c) 1987, 1991, 1993 3*63358Sbostic * The Regents of the University of California. All rights reserved. 433280Sbostic * 544541Sbostic * %sccs.include.redist.c% 633280Sbostic * 7*63358Sbostic * @(#)endian.h 8.1 (Berkeley) 06/11/93 833280Sbostic */ 933280Sbostic 1059803Smckusick #ifndef _ENDIAN_H_ 1159803Smckusick #define _ENDIAN_H_ 1259803Smckusick 1333280Sbostic /* 1452002Smckusick * Define _NOQUAD if the compiler does NOT support 64-bit integers. 1552002Smckusick */ 1652002Smckusick /* #define _NOQUAD */ 1752002Smckusick 1852002Smckusick /* 1952002Smckusick * Define the order of 32-bit words in 64-bit words. 2052002Smckusick */ 2152002Smckusick #define _QUAD_HIGHWORD 1 2252002Smckusick #define _QUAD_LOWWORD 0 2352002Smckusick 2452002Smckusick #ifndef _POSIX_SOURCE 2552002Smckusick /* 2647793Sbostic * Definitions for byte order, according to byte significance from low 2747793Sbostic * address to high. 2833280Sbostic */ 2947793Sbostic #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ 3047793Sbostic #define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ 3147793Sbostic #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ 3233280Sbostic 3347793Sbostic #define BYTE_ORDER LITTLE_ENDIAN 3433280Sbostic 3547793Sbostic #include <sys/cdefs.h> 3647793Sbostic 3747793Sbostic __BEGIN_DECLS 3847793Sbostic unsigned long htonl __P((unsigned long)); 3947793Sbostic unsigned short htons __P((unsigned short)); 4047793Sbostic unsigned long ntohl __P((unsigned long)); 4147793Sbostic unsigned short ntohs __P((unsigned short)); 4247793Sbostic __END_DECLS 4347793Sbostic 4433280Sbostic /* 4533280Sbostic * Macros for network/external number representation conversion. 4633280Sbostic */ 4733381Skarels #if BYTE_ORDER == BIG_ENDIAN && !defined(lint) 4833280Sbostic #define ntohl(x) (x) 4933280Sbostic #define ntohs(x) (x) 5033280Sbostic #define htonl(x) (x) 5133280Sbostic #define htons(x) (x) 5240610Skarels 5340610Skarels #define NTOHL(x) (x) 5440610Skarels #define NTOHS(x) (x) 5540610Skarels #define HTONL(x) (x) 5640610Skarels #define HTONS(x) (x) 5740610Skarels 5833280Sbostic #else 5940610Skarels 6040804Ssklower #define NTOHL(x) (x) = ntohl((u_long)x) 6140804Ssklower #define NTOHS(x) (x) = ntohs((u_short)x) 6240804Ssklower #define HTONL(x) (x) = htonl((u_long)x) 6340804Ssklower #define HTONS(x) (x) = htons((u_short)x) 6433280Sbostic #endif 6552002Smckusick #endif /* ! _POSIX_SOURCE */ 6659803Smckusick #endif /* !_ENDIAN_H_ */ 67