diff --git a/lib/ngtcp2_conv.c b/lib/ngtcp2_conv.c index 7811c84d0bc19ac5359b8b4bd7c24f315c629775..18cf314791384dd97ae5be12c3e6588d59d3ad71 100644 --- a/lib/ngtcp2_conv.c +++ b/lib/ngtcp2_conv.c @@ -45,19 +45,19 @@ uint64_t ngtcp2_get_uint48(const uint8_t *p) { uint32_t ngtcp2_get_uint32(const uint8_t *p) { uint32_t n; memcpy(&n, p, 4); - return ntohl(n); + return ngtcp2_ntohl(n); } uint32_t ngtcp2_get_uint24(const uint8_t *p) { uint32_t n = 0; memcpy(((uint8_t *)&n) + 1, p, 3); - return ntohl(n); + return ngtcp2_ntohl(n); } uint16_t ngtcp2_get_uint16(const uint8_t *p) { uint16_t n; memcpy(&n, p, 2); - return ntohs(n); + return ngtcp2_ntohs(n); } uint64_t ngtcp2_get_varint(size_t *plen, const uint8_t *p) { @@ -76,11 +76,11 @@ uint64_t ngtcp2_get_varint(size_t *plen, const uint8_t *p) { case 2: memcpy(&n, p, 2); n.b[0] &= 0x3f; - return ntohs(n.n16); + return ngtcp2_ntohs(n.n16); case 4: memcpy(&n, p, 4); n.b[0] &= 0x3f; - return ntohl(n.n32); + return ngtcp2_ntohl(n.n32); case 8: memcpy(&n, p, 8); n.b[0] &= 0x3f; @@ -116,17 +116,17 @@ uint8_t *ngtcp2_put_uint48be(uint8_t *p, uint64_t n) { } uint8_t *ngtcp2_put_uint32be(uint8_t *p, uint32_t n) { - n = htonl(n); + n = ngtcp2_htonl(n); return ngtcp2_cpymem(p, (const uint8_t *)&n, sizeof(n)); } uint8_t *ngtcp2_put_uint24be(uint8_t *p, uint32_t n) { - n = htonl(n); + n = ngtcp2_htonl(n); return ngtcp2_cpymem(p, ((const uint8_t *)&n) + 1, 3); } uint8_t *ngtcp2_put_uint16be(uint8_t *p, uint16_t n) { - n = htons(n); + n = ngtcp2_htons(n); return ngtcp2_cpymem(p, (const uint8_t *)&n, sizeof(n)); } diff --git a/lib/ngtcp2_conv.h b/lib/ngtcp2_conv.h index 40d70911f7bba2389c614c0a0dd59170309660a1..25f9d91e5262b6ea193010bd332c53045f4d3c55 100644 --- a/lib/ngtcp2_conv.h +++ b/lib/ngtcp2_conv.h @@ -82,7 +82,7 @@ # define STIN static inline # endif -STIN uint32_t htonl(uint32_t hostlong) { +STIN uint32_t ngtcp2_htonl(uint32_t hostlong) { uint32_t res; unsigned char *p = (unsigned char *)&res; *p++ = hostlong >> 24; @@ -92,7 +92,7 @@ STIN uint32_t htonl(uint32_t hostlong) { return res; } -STIN uint16_t htons(uint16_t hostshort) { +STIN uint16_t ngtcp2_htons(uint16_t hostshort) { uint16_t res; unsigned char *p = (unsigned char *)&res; *p++ = hostshort >> 8; @@ -100,7 +100,7 @@ STIN uint16_t htons(uint16_t hostshort) { return res; } -STIN uint32_t ntohl(uint32_t netlong) { +STIN uint32_t ngtcp2_ntohl(uint32_t netlong) { uint32_t res; unsigned char *p = (unsigned char *)&netlong; res = *p++ << 24; @@ -110,7 +110,7 @@ STIN uint32_t ntohl(uint32_t netlong) { return res; } -STIN uint16_t ntohs(uint16_t netshort) { +STIN uint16_t ngtcp2_ntohs(uint16_t netshort) { uint16_t res; unsigned char *p = (unsigned char *)&netshort; res = *p++ << 8; @@ -118,6 +118,13 @@ STIN uint16_t ntohs(uint16_t netshort) { return res; } +#else /* WIN32 */ + +#define ngtcp2_htonl htonl +#define ngtcp2_htons htons +#define ngtcp2_ntohl ntohl +#define ngtcp2_ntohs ntohs + #endif /* WIN32 */ /*