/*1* nghttp2 - HTTP/2 C Library2*3* Copyright (c) 2012 Tatsuhiro Tsujikawa4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sublicense, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice shall be14* included in all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE20* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*/24#ifndef NGHTTP2_NET_H25#define NGHTTP2_NET_H2627#ifdef HAVE_CONFIG_H28# include <config.h>29#endif /* HAVE_CONFIG_H */3031#ifdef HAVE_ARPA_INET_H32# include <arpa/inet.h>33#endif /* HAVE_ARPA_INET_H */3435#ifdef HAVE_NETINET_IN_H36# include <netinet/in.h>37#endif /* HAVE_NETINET_IN_H */3839#include <nghttp2/nghttp2.h>4041#if defined(WIN32)42/* Windows requires ws2_32 library for ntonl family functions. We43define inline functions for those function so that we don't have44dependency on that lib. */4546# ifdef _MSC_VER47# define STIN static __inline48# else49# define STIN static inline50# endif5152STIN uint32_t htonl(uint32_t hostlong) {53uint32_t res;54unsigned char *p = (unsigned char *)&res;55*p++ = (unsigned char)(hostlong >> 24);56*p++ = (hostlong >> 16) & 0xffu;57*p++ = (hostlong >> 8) & 0xffu;58*p = hostlong & 0xffu;59return res;60}6162STIN uint16_t htons(uint16_t hostshort) {63uint16_t res;64unsigned char *p = (unsigned char *)&res;65*p++ = (unsigned char)(hostshort >> 8);66*p = hostshort & 0xffu;67return res;68}6970STIN uint32_t ntohl(uint32_t netlong) {71uint32_t res;72unsigned char *p = (unsigned char *)&netlong;73res = (uint32_t)(*p++ << 24);74res += (uint32_t)(*p++ << 16);75res += (uint32_t)(*p++ << 8);76res += *p;77return res;78}7980STIN uint16_t ntohs(uint16_t netshort) {81uint16_t res;82unsigned char *p = (unsigned char *)&netshort;83res = (uint16_t)(*p++ << 8);84res += *p;85return res;86}8788#endif /* WIN32 */8990#endif /* NGHTTP2_NET_H */919293