title: Getting the ip address of my machine in dotted decimal with C?
body: <p>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 <code>INADDR_LOOPBACK</code> with the following code. </p>
  
  <pre><code>char addr[INET_ADDRSTRLEN];
  struct in_addr *in_addr1 = malloc(sizeof(struct in_addr));
  in_addr1-&gt;s_addr = INADDR_LOOPBACK;
  inet_ntop(AF_INET, in_addr1, addr, INET_ADDRSTRLEN);
  printf("addr: %s\n", addr);
  </code></pre>
  
  <p>Here's what I get from the <code>printf</code>:</p>
  
  <blockquote>
    <p>1.0.0.127</p>
  </blockquote>
  
  <ol>
  <li>Why is it the localhost address reverse? Should it print
  <code>127.0.0.1</code>?</li>
  <li>Honestly I was expecting to get the ip I would get calling for
  example <code>$ ifconfig</code>... not the localhost! Did I misunderstand what <code>INADDR_LOOBACK</code> does?</li>
  </ol>