Guest User

Untitled

a guest
Jul 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #ifndef BYTECONVERSION_H
  2. #define BYTECONVERSION_H
  3.  
  4. #ifdef HASENDIAN_H
  5. #include <endian.h>
  6. #else
  7. #include <stdint.h>
  8.  
  9. #ifndef ISBIGENDIAN
  10. uint32_t be32toh(uint32_t val) {return val;}
  11. uint32_t htobe32(uint32_t val) {return val;}
  12. uint64_t be64toh(uint64_t val) {return val;}
  13. uint64_t htobe64(uint64_t val) {return val;}
  14. #else
  15. #include <arpa/inet.h>
  16.  
  17. uint32_t be32toh(uint32_t val) {
  18. return (ntohl(val));
  19. }
  20.  
  21. uint32_t htobe32(uint32_t val) {
  22. return htonl(val);
  23. }
  24. uint64_t be64toh(uint64_t val) {
  25. return ((uint64_t)ntohl(val >> 32)) | ((uint64_t)ntohl(val) << 32);
  26. }
  27. uint64_t htobe64(uint64_t val) {
  28. return ((uint64_t)htonl(val >> 32)) | ((uint64_t)htonl(val) << 32);
  29. }
  30. #endif
  31. #endif
  32.  
  33. #endif
Add Comment
Please, Sign In to add comment