From 3f098aed4500da38db8afdff111f02198158203a Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 20 Aug 1998 14:37:17 +0000 Subject: FreeBSD stack compiles for the first time (except libc/strsep.c). --- c/src/libnetworking/machine/endian.h | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 c/src/libnetworking/machine/endian.h (limited to 'c/src/libnetworking/machine/endian.h') diff --git a/c/src/libnetworking/machine/endian.h b/c/src/libnetworking/machine/endian.h new file mode 100644 index 0000000000..cd0d6f551c --- /dev/null +++ b/c/src/libnetworking/machine/endian.h @@ -0,0 +1,60 @@ +#ifndef _MACHINE_ENDIAN_H_ +#define _MACHINE_ENDIAN_H_ + +#include + +/* + * BSD-style endian declaration + */ +#define BIG_ENDIAN 4321 +#define LITTLE_ENDIAN 1234 + +#if CPU_BIG_ENDIAN +# define BYTE_ORDER BIG_ENDIAN +#elif CPU_LITTLE_ENDIAN +# define BYTE_ORDER LITTLE_ENDIAN +#else +# error "Can't decide which end is which!" +#endif + +#if ( CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES == FALSE ) + +#if ( CPU_BIG_ENDIAN == TRUE ) + +/* + * Very simply on big endian CPUs + */ + +#define ntohl(_x) (_x) +#define ntohs(_x) (_x) +#define htonl(_x) (_x) +#define htons(_x) (_x) + +#define NTOHS(x) +#define HTONS(x) +#define NTOHL(x) +#define HTONL(x) + +#elif ( CPU_LITTLE_ENDIAN == TRUE ) + +/* + * A little more complicated on little endian CPUs + */ + +#define ntohl(_x) ((long) CPU_swap_u32((unsigned32)_x)) +#define ntohs(_x) ((short) CPU_swap_u16((unsigned16)_x)) +#define htonl(_x) ((long) CPU_swap_u32((unsigned32)_x)) +#define htons(_x) ((short) CPU_swap_u16((unsigned16)_x)) + +#define NTOHS(x) (x) = ntohs(x) +#define HTONS(x) (x) = htons(x) +#define NTOHL(x) (x) = ntohl(x) +#define HTONL(x) (x) = htonl(x) + +#else +#error "Unknown endian-ness for this cpu" +#endif + +#endif /* CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES */ + +#endif /* _MACHINE_ENDIAN_H_ */ -- cgit v1.2.3