nghttp2_net.c 944 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (C) 2015-2018 Alibaba Group Holding Limited
  3. */
  4. #include <stdio.h>
  5. #include <stdint.h>
  6. #include "nghttp2_net.h"
  7. #if IOT_BYTE_ORDER == LITTLE_ENDIAN
  8. uint32_t nghttp2_htonl(uint32_t hostlong) {
  9. uint32_t res;
  10. unsigned char *p = (unsigned char *)&res;
  11. *p++ = hostlong >> 24;
  12. *p++ = (hostlong >> 16) & 0xffu;
  13. *p++ = (hostlong >> 8) & 0xffu;
  14. *p = hostlong & 0xffu;
  15. return res;
  16. }
  17. uint16_t nghttp2_htons(uint16_t hostshort) {
  18. uint16_t res;
  19. unsigned char *p = (unsigned char *)&res;
  20. *p++ = hostshort >> 8;
  21. *p = hostshort & 0xffu;
  22. return res;
  23. }
  24. uint32_t nghttp2_ntohl(uint32_t netlong) {
  25. uint32_t res;
  26. unsigned char *p = (unsigned char *)&netlong;
  27. res = *p++ << 24;
  28. res += *p++ << 16;
  29. res += *p++ << 8;
  30. res += *p;
  31. return res;
  32. }
  33. uint16_t nghttp2_ntohs(uint16_t netshort) {
  34. uint16_t res;
  35. unsigned char *p = (unsigned char *)&netshort;
  36. res = *p++ << 8;
  37. res += *p;
  38. return res;
  39. }
  40. #endif