1 2 3 4 5 6 7 8 9 10
#include <netinet/in.h> uint16_t ntohs(uint16_t n) { union { uint16_t s; uint8_t b[2]; } u = { n }; return (u.b[0]<<8) | u.b[1]; }