I am not sure why htonsand ntohsexist in the standard library. They do exactly the same thing - if I'm not embarrassed in any way!
htons
ntohs
The same goes for htonland ntohl.
htonl
ntohl
They do for self-documenting code that tells the reader whether the data is in host or network mode.
This is if the machine has some kind of unusual endianness , other than big-endian or little-endian, which is not one or more simple byte swaps.
, 0x0A0B0C0D 0B 0C 0D 0A, htonl 0x0A0B0C0D, ntohl 0x0C0D0A0B.
0x0A0B0C0D
0B 0C 0D 0A
0x0C0D0A0B
- , , - - .