I came across two threads:
Socket with recv-timeout: What is wrong with this code?
Reading / Writing to a socket using a FILE stream in c
one uses
INADDR_ANY
is the "any address" in IPV4. That address is 0.0.0.0
in dotted notation, so 0x000000
in hex on any endianness. Passing it through htonl
has no effect.
Now if you want to wonder about other macro constants, look at INADDR_LOOPBACK
if it's defined on your platform. Chances are it will be a macro like this:
#define INADDR_LOOPBACK 0x7f000001 /* 127.0.0.1 */
(from linux/in.h
, equivalent definition in winsock.h
).
So for INADDR_LOOPBACK
, an htonl
is necessary.
For consistency, it could thus be better to use htonl
in all cases.