3 ms·
My TL;DR take on this: that htons() both takes and returns a 16 bit integer is hazardous I'd agree that if you exposed integers that had been given the htons()
by greenbit 3y ago
My TL;DR take on this: that htons() both takes and returns a 16 bit integer is hazardous
I'd agree that if you exposed integers that had been given the htons() treatment far and wide in your code, that could lead to trouble. Would lead to trouble.
However .. in practice I've virtually never seen htons, htonl used anywhere but in close proximity to stuffing a sockaddr prior to a bind/connect/sendto etc, i.e., in relation to classic BSD socket calls. That you're forced to overtly stuff structs (and deal with low-level crufties like endieness) to feed to the API seems like an API design issue.
- mytailorisrich 3y agoThese functions return the same type as their argument for simplicity and practicality but the only actual use is to convert between wire/byte stream format and internal representation. It's not a problem.
- OnlyMortal 3y agoI used it with some Adobe files when my Mac application was ported from PPC to Intel - way back when.