1 #include <byteswap.h> 2 #include <netinet/in.h> 3 htons(uint16_t n)4 uint16_t htons(uint16_t n) { 5 union { 6 int i; 7 char c; 8 } u = {1}; 9 return u.c ? bswap_16(n) : n; 10 } 11