I have always wondered, why don't I have to use htons/ntohl when using write/read? (At least all examples I have seen so far don't.)
How do I know that the bytes received have the correct endianness?
I have always wondered, why don't I have to use htons/ntohl when using write/read? (At least all examples I have seen so far don't.)
How do I know that the bytes received have the correct endianness?
Well, you have to, if you ever intend your files to be exchanged between systems of a different endianness - it is just that the problem tends to come up more rarely in the context of files than with network protocols and so is often ignored.