133280Sbostic /* 2*47793Sbostic * Copyright (c) 1987, 1991 Regents of the University of California. 333280Sbostic * All rights reserved. 433280Sbostic * 544541Sbostic * %sccs.include.redist.c% 633280Sbostic * 7*47793Sbostic * @(#)endian.h 7.8 (Berkeley) 04/03/91 833280Sbostic */ 933280Sbostic 1033280Sbostic /* 11*47793Sbostic * Definitions for byte order, according to byte significance from low 12*47793Sbostic * address to high. 1333280Sbostic */ 14*47793Sbostic #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ 15*47793Sbostic #define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ 16*47793Sbostic #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ 1733280Sbostic 18*47793Sbostic #define BYTE_ORDER LITTLE_ENDIAN 1933280Sbostic 20*47793Sbostic #ifndef KERNEL 21*47793Sbostic #include <sys/cdefs.h> 22*47793Sbostic #endif 23*47793Sbostic 24*47793Sbostic __BEGIN_DECLS 25*47793Sbostic unsigned long htonl __P((unsigned long)); 26*47793Sbostic unsigned short htons __P((unsigned short)); 27*47793Sbostic unsigned long ntohl __P((unsigned long)); 28*47793Sbostic unsigned short ntohs __P((unsigned short)); 29*47793Sbostic __END_DECLS 30*47793Sbostic 3133280Sbostic /* 3233280Sbostic * Macros for network/external number representation conversion. 3333280Sbostic */ 3433381Skarels #if BYTE_ORDER == BIG_ENDIAN && !defined(lint) 3533280Sbostic #define ntohl(x) (x) 3633280Sbostic #define ntohs(x) (x) 3733280Sbostic #define htonl(x) (x) 3833280Sbostic #define htons(x) (x) 3940610Skarels 4040610Skarels #define NTOHL(x) (x) 4140610Skarels #define NTOHS(x) (x) 4240610Skarels #define HTONL(x) (x) 4340610Skarels #define HTONS(x) (x) 4440610Skarels 4533280Sbostic #else 4640610Skarels 4740804Ssklower #define NTOHL(x) (x) = ntohl((u_long)x) 4840804Ssklower #define NTOHS(x) (x) = ntohs((u_short)x) 4940804Ssklower #define HTONL(x) (x) = htonl((u_long)x) 5040804Ssklower #define HTONS(x) (x) = htons((u_short)x) 5133280Sbostic #endif 52