From 6133110386a5637044683ffe737564130617665a Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 28 Mar 2015 19:58:44 +0900 Subject: [PATCH] Remove dependency on libws2_32 on Windows build --- configure.ac | 14 -------------- lib/nghttp2_net.h | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index f8cad2b1..5c885a87 100644 --- a/configure.ac +++ b/configure.ac @@ -508,13 +508,6 @@ AC_CHECK_HEADERS([ \ unistd.h \ ]) -case "${host}" in - *mingw*) - # For ntohl, ntohs in Windows - AC_CHECK_HEADERS([winsock2.h]) - ;; -esac - # Checks for typedefs, structures, and compiler characteristics. AC_TYPE_SIZE_T AC_TYPE_SSIZE_T @@ -564,13 +557,6 @@ AM_CONDITIONAL([ENABLE_TINY_NGHTTPD], [ test "x${have_epoll}" = "xyes" && test "x${have_timerfd_create}" = "xyes"]) -dnl Windows library for winsock2 -case "${host}" in - *mingw*) - LIBS="$LIBS -lws2_32" - ;; -esac - ac_save_CFLAGS=$CFLAGS CFLAGS= diff --git a/lib/nghttp2_net.h b/lib/nghttp2_net.h index 3f82adf7..bfa9f15d 100644 --- a/lib/nghttp2_net.h +++ b/lib/nghttp2_net.h @@ -37,8 +37,49 @@ #include #endif /* HAVE_NETINET_IN_H */ -#ifdef HAVE_WINSOCK2_H -#include -#endif /* HAVE_WINSOCK2_H */ +#include + +#if defined(WIN32) +/* Windows requires ws2_32 library for ntonl family functions. We + define inline functions for those function so that we don't have + dependeny on that lib. */ + +static inline uint32_t htonl(uint32_t hostlong) { + uint32_t res; + unsigned char *p = (unsigned char *)&res; + *p++ = hostlong >> 24; + *p++ = (hostlong >> 16) & 0xffu; + *p++ = (hostlong >> 8) & 0xffu; + *p = hostlong & 0xffu; + return res; +} + +static inline uint16_t htons(uint16_t hostshort) { + uint16_t res; + unsigned char *p = (unsigned char *)&res; + *p++ = hostshort >> 8; + *p = hostshort & 0xffu; + return res; +} + +static inline uint32_t ntohl(uint32_t netlong) { + uint32_t res; + unsigned char *p = (unsigned char *)&netlong; + res = *p++ << 24; + res += *p++ << 16; + res += *p++ << 8; + res += *p; + return res; +} + +static inline uint16_t ntohs(uint16_t netshort) { + uint16_t res; + unsigned char *p = (unsigned char *)&netshort; + res = *p++ << 8; + res += *p; + return res; +} + +#endif /* WIN32 */ #endif /* NGHTTP2_NET_H */