Why do both `htons` and `ntohs` exist?
问题 I am not sure why htons and ntohs both exist in the standard library. They do exactly the same thing -- unless I'm confused somehow! The same goes for htonl and ntohl . 回答1: They make for self-documenting code that tells the reader whether the data is in host- or network- order. 回答2: This is in case a machine has some sort of unusual endianness besides big-endian or little-endian that isn't one or more simple byte swaps. For example, if the value 0x0A0B0C0D was represented internally as 0B 0C