Files
externals/linux/include/celoxica/netutils.h
T
2017-10-04 14:16:02 -04:00

167 lines
4.7 KiB
C++

#pragma once
#if defined(__GNUC__) && defined(__cplusplus)
# if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
# include <memory.h>
# include <byteswap.h>
//# ifdef __GNUC__
//# pragma GCC diagnostic warning "-Wconversion"
//# endif
namespace baseutils
{
inline unsigned char ntoh(unsigned char p_value)
{
return(p_value);
}
inline char ntoh(char p_value)
{
return(p_value);
}
//# if __GNUC__ < 4 or __GNUC_MINOR__ < 5
//# pragma GCC diagnostic ignored "-Wconversion"
//# endif
inline unsigned short ntoh(unsigned short p_value)
{
return(static_cast<unsigned short>(__bswap_16(p_value)));
}
inline short ntoh(short p_value)
{
return(static_cast<short>(__bswap_16(p_value)));
}
//# if __GNUC__ < 4 or __GNUC_MINOR__ < 5
//# pragma GCC diagnostic warning "-Wconversion"
//# endif
inline unsigned int ntoh(unsigned int p_value)
{
return(static_cast<unsigned int>(__bswap_32(p_value)));
}
inline int ntoh(int p_value)
{
return(static_cast<int>(__bswap_32(static_cast<unsigned int>(p_value))));
}
inline unsigned long int ntoh(unsigned long int p_value)
{
return(static_cast<unsigned long int>(__bswap_64(p_value)));
}
inline long int ntoh(long int p_value)
{
return(static_cast<long int>(__bswap_64(static_cast<unsigned long int>(p_value))));
}
inline unsigned char hton(unsigned char p_value)
{
return(p_value);
}
inline char hton(char p_value)
{
return(p_value);
}
inline unsigned short hton(unsigned short p_value)
{
return(static_cast<unsigned short>(__bswap_16(p_value)));
}
inline short hton(short p_value)
{
return(static_cast<short>(__bswap_16(p_value)));
}
inline unsigned int hton(unsigned int p_value)
{
return(static_cast<unsigned int>(__bswap_32(p_value)));
}
inline int hton(int p_value)
{
return(static_cast<int>(__bswap_32(static_cast<unsigned int>(p_value))));
}
inline unsigned long int hton(unsigned long int p_value)
{
return(static_cast<unsigned long int>(__bswap_64(p_value)));
}
inline long int hton(long int p_value)
{
return(static_cast<long int>(__bswap_64(static_cast<unsigned long int>(p_value))));
}
inline signed short int htons16(signed short int p_value)
{
return(static_cast<signed short int>(__bswap_16(static_cast<unsigned long int>(p_value))));
}
inline unsigned short int htonu16(unsigned short int p_value)
{
return(static_cast<unsigned short int>(__bswap_16(static_cast<unsigned long int>(p_value))));
}
inline signed int htons32(signed int p_value)
{
return(static_cast<signed int>(__bswap_32(static_cast<unsigned int>(p_value))));
}
inline unsigned int htonu32(unsigned int p_value)
{
return(static_cast<unsigned int>(__bswap_32(p_value)));
}
inline signed long int htons64(signed long int p_value)
{
return(static_cast<signed long int>(__bswap_64(static_cast<unsigned long int>(p_value))));
}
inline unsigned long int htonu64(unsigned long int p_value)
{
return(static_cast<unsigned long int>(__bswap_64(p_value)));
}
inline signed short int ntohs16(signed short int p_value)
{
return(static_cast<signed short int>(__bswap_16(static_cast<unsigned long int>(p_value))));
}
inline unsigned short int ntohu16(unsigned short int p_value)
{
return(static_cast<unsigned short int>(__bswap_16(static_cast<unsigned long int>(p_value))));
}
inline signed int ntohs32(signed int p_value)
{
return(static_cast<signed int>(__bswap_32(static_cast<unsigned int>(p_value))));
}
inline unsigned int ntohu32(unsigned int p_value)
{
return(static_cast<unsigned int>(__bswap_32(p_value)));
}
inline signed long int ntohs64(signed long int p_value)
{
return(static_cast<signed long int>(__bswap_64(static_cast<unsigned long int>(p_value))));
}
inline unsigned long int ntohu64(unsigned long int p_value)
{
return(static_cast<unsigned long int>(__bswap_64(p_value)));
}
}
# else
# define ntoh(x) (x)
# endif
#endif