1 /*===-- htonl.c -----------------------------------------------------------===// 2 // 3 // The KLEE Symbolic Virtual Machine 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===*/ 9 10 #include <sys/types.h> 11 #include <sys/param.h> 12 #include <stdint.h> 13 14 #undef htons 15 #undef htonl 16 #undef ntohs 17 #undef ntohl 18 19 /* Make sure we can recognize the endianness. */ 20 #if (!defined(BYTE_ORDER) || !defined(BIG_ENDIAN) || !defined(LITTLE_ENDIAN)) 21 #error "Unknown platform endianness!" 22 #endif 23 24 #if BYTE_ORDER == LITTLE_ENDIAN 25 htons(uint16_t v)26uint16_t htons(uint16_t v) { 27 return (v >> 8) | (v << 8); 28 } htonl(uint32_t v)29uint32_t htonl(uint32_t v) { 30 return htons(v >> 16) | (htons((uint16_t) v) << 16); 31 } 32 33 #else 34 htons(uint16_t v)35uint16_t htons(uint16_t v) { 36 return v; 37 } htonl(uint32_t v)38uint32_t htonl(uint32_t v) { 39 return v; 40 } 41 42 #endif 43 ntohs(uint16_t v)44uint16_t ntohs(uint16_t v) { 45 return htons(v); 46 } ntohl(uint32_t v)47uint32_t ntohl(uint32_t v) { 48 return htonl(v); 49 } 50