Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 499
Brennan Vincent Avatar asked Jun 02 '16 17:06

Brennan Vincent


1 Answers

They make for self-documenting code that tells the reader whether the data is in host- or network- order.

like image 120
Jonathon Reinhart Avatar answered Nov 15 '22 05:11

Jonathon Reinhart