using htonl() to properly convert localhost using C++ -
i have define following:
#define localhost 2130706433
i'm trying correct network/host bytes order when working sockaddr_in
:
struct sockaddr_in src; src.sin_port = htons(0); src.sin_family = af_inet; src.sin_addr.s_addr = htonl( localhost );
this seems ordering incorrectly i'm seeing 1.0.0.127
if print src.sin_addr.s_addr
stdout.
what's right way of doing this?
2130706433
in decimal 0x7f000001
in hexadecimal, 127.0.0.1 in network byte order.
if you're using htonl()
on intel x86 platform, since x86 little-endian, htonl()
ends reversing bits.
Comments
Post a Comment