#ifndef _SYS_BYTEORDER_H
#define _SYS_BYTEORDER_H
#if !defined (__GNUC__) && !defined (__GNUG__)
#error You lose! This file is only useful with GNU compilers.
#endif
#ifndef __BYTE_ORDER__
#define __LITTLE_ENDIAN__ 1234
#define __BIG_ENDIAN__ 4321
#define __PDP_ENDIAN__ 3412
#endif
#ifdef __STDC__
static __inline__ unsigned long htonl (unsigned long);
static __inline__ unsigned short htons (unsigned int);
static __inline__ unsigned long ntohl (unsigned long);
static __inline__ unsigned short ntohs (unsigned int);
#endif
#if defined (__i386__)
#ifndef __BYTE_ORDER__
#define __BYTE_ORDER__ __LITTLE_ENDIAN__
#endif
static __inline__ unsigned long
htonl (unsigned long __arg)
{
register unsigned long __result;
__asm__ ("xchg%B0 %b0,%h0
ror%L0 $16,%0
xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
return __result;
}
static __inline__ unsigned short
htons (unsigned int __arg)
{
register unsigned short __result;
__asm__ ("xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
return __result;
}
#elif ((defined (__i860__) && !defined (__i860_big_endian__)) \
|| defined (__ns32k__) || defined (__vax__) \
|| defined (__spur__) || defined (__arm__))
#ifndef __BYTE_ORDER__
#define __BYTE_ORDER__ __LITTLE_ENDIAN__
#endif
static __inline__ unsigned long
htonl (unsigned long __arg)
{
register unsigned long __result;
__result = (__arg >> 24) & 0x000000ff;
__result |= (__arg >> 8) & 0x0000ff00;
__result |= (__arg << 8) & 0x00ff0000;
__result |= (__arg << 24) & 0xff000000;
return __result;
}
static __inline__ unsigned short
htons (unsigned int __arg)
{
register unsigned short __result;
__result = (__arg << 8) & 0xff00;
__result |= (__arg >> 8) & 0x00ff;
return __result;
}
#else
#ifndef __BYTE_ORDER__
#define __BYTE_ORDER__ __BIG_ENDIAN__
#endif
static __inline__ unsigned long
htonl (unsigned long __arg)
{
return __arg;
}
static __inline__ unsigned short
htons (unsigned int __arg)
{
return __arg;
}
#endif
static __inline__ unsigned long
ntohl (unsigned long __arg)
{
return htonl (__arg);
}
static __inline__ unsigned short
ntohs (unsigned int __arg)
{
return htons (__arg);
}
#endif