#include // for uint16_t, htons #include // for bswap16 #include uint16_t htons(uint16_t hostshort) { union { int i; char c; } u = { 1 }; return u.c ? bswap16(hostshort) : hostshort; }