I'm trying to get a string with the ip address in dotted decimal of my machine. What I do is trying to get the string from INADDR_LOOPBACK
with the following code.
char addr[INET_ADDRSTRLEN];
struct in_addr *in_addr1 = malloc(sizeof(struct in_addr));
in_addr1->s_addr = INADDR_LOOPBACK;
inet_ntop(AF_INET, in_addr1, addr, INET_ADDRSTRLEN);
printf("addr: %s\n", addr);
Here's what I get from the printf
:
1.0.0.127
- Why is it the localhost address reverse? Should it print
127.0.0.1
? - Honestly I was expecting to get the ip I would get calling for
example
$ ifconfig
... not the localhost! Did I misunderstand whatINADDR_LOOBACK
does?