Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef BYTECONVERSION_H
- #define BYTECONVERSION_H
- #ifdef HASENDIAN_H
- #include <endian.h>
- #else
- #include <stdint.h>
- #ifndef ISBIGENDIAN
- uint32_t be32toh(uint32_t val) {return val;}
- uint32_t htobe32(uint32_t val) {return val;}
- uint64_t be64toh(uint64_t val) {return val;}
- uint64_t htobe64(uint64_t val) {return val;}
- #else
- #include <arpa/inet.h>
- uint32_t be32toh(uint32_t val) {
- return (ntohl(val));
- }
- uint32_t htobe32(uint32_t val) {
- return htonl(val);
- }
- uint64_t be64toh(uint64_t val) {
- return ((uint64_t)ntohl(val >> 32)) | ((uint64_t)ntohl(val) << 32);
- }
- uint64_t htobe64(uint64_t val) {
- return ((uint64_t)htonl(val >> 32)) | ((uint64_t)htonl(val) << 32);
- }
- #endif
- #endif
- #endif
Add Comment
Please, Sign In to add comment