1 /* 2 * Functions to convert between host and network byte order. 3 * 4 * Copyright (C) 2003-2006 by Erik Andersen <andersen@uclibc.org> 5 * 6 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. 7 */ 8 9 #include <netinet/in.h> 10 11 #undef ntohl 12 #undef ntohs 13 #undef htonl 14 #undef htons 15 16 #if __BYTE_ORDER != __BIG_ENDIAN && __BYTE_ORDER != __LITTLE_ENDIAN 17 # error "You seem to have an unsupported byteorder" 18 #endif 19 ntohl(uint32_t x)20uint32_t ntohl (uint32_t x) 21 { 22 #if __BYTE_ORDER == __BIG_ENDIAN 23 return x; 24 #else 25 return __bswap_32(x); 26 #endif 27 } 28 libc_hidden_def(ntohl) strong_alias(ntohl,htonl)29strong_alias(ntohl,htonl) 30 libc_hidden_def(htonl) 31 32 uint16_t ntohs (uint16_t x) 33 { 34 #if __BYTE_ORDER == __BIG_ENDIAN 35 return x; 36 #else 37 return __bswap_16(x); 38 #endif 39 } 40 libc_hidden_def(ntohs) 41 strong_alias(ntohs,htons) 42 libc_hidden_def(htons) 43