Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better endian functions #8

Open
divinity76 opened this issue Feb 21, 2019 · 0 comments
Open

better endian functions #8

divinity76 opened this issue Feb 21, 2019 · 0 comments

Comments

@divinity76
Copy link
Owner

divinity76 commented Feb 21, 2019

should do something like this instead imo

// ntohll => network to host long long => big endian to host endian, 64bit => BETOHE64
// ntohl => network to host long => big endian to host endian, 32bit => BETOHE32
// htonll => host to network long long => host endian to big endian, 64bit => HETOBE64
// htonl => host to network long => host endian to big endian, 32 bit => HETOBE32


#if !defined(HETOBE16)
#if !defined(__BYTE_ORDER__)
#error Failed to detect byte order!
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
// host endian to big endian 64bit
#define HETOBE64(x) (x)
// host endian to little endian 64bit
#define HETOLE64(x) __bswap_constant_64(x)
// host endian to big endian 32bit
#define HETOBE32(x) (x)
// host endian to little endian 32bit
#define HETOLE32(x) __bswap_constant_32(x)
// host endian to big endian 16bit
#define HETOBE16(x) (x)
// host endian to little endian 16bit
#define HETOLE16(x) __bswap_constant_16(x)
// little endian to host endian 64bit
#define LETOHE64(x) __bswap_constant_64(x)
// big endian to host endian 64bit
#define BETOHE64(x) (x)
// little endian to host endian 32bit
#define LETOHE32(x) __bswap_constant_32(x)
// big endian to host endian 32bit
#define BETOHE32(x) (x)
// little endian to host endian 16bit
#define LETOHE16(x) __bswap_constant_16(x)
// big endian to host endian 16bit
#define BETOHE16(x) (x)
#else
#if __BYTE_ORDER == __LITTLE_ENDIAN
// host endian to big endian 64bit
#define HETOBE64(x) __bswap_constant_64(x)
// host endian to little endian 64bit
#define HETOLE64(x) (x)
// host endian to big endian 32bit
#define HETOBE32(x) __bswap_constant_32(x)
// host endian to little endian 32bit
#define HETOLE32(x) (x)
// host endian to big endian 16bit
#define HETOBE16(x) __bswap_constant_16(x)
// host endian to little endian 16bit
#define HETOLE16(x) (x)
// little endian to host endian 64bit
#define LETOHE64(x) (x)
// big endian to host endian 64bit
#define BETOHE64(x) __bswap_constant_64(x)
// little endian to host endian 32bit
#define LETOHE32(x) (x)
// big endian to host endian 32bit
#define BETOHE32(x) __bswap_constant_32(x)
// little endian to host endian 16bit
#define LETOHE16(x) (x)
// big endian to host endian 16bit
#define BETOHE16(x) __bswap_constant_16(x)
#else
#error Failed to detect byte order! appears to be neither big endian nor little endian..
#endif
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant