title: Unix - how to get IP address of domain name?
body: <p>In a C program in UNIX, gethostbyname() can be used to obtain the address of domain like "localhost". How does one convert the result from gethostbyname() to dotted decimal notation.</p>
  
  <pre><code>struct hostent* pHostInfo;
  long nHostAddress;
  
  /* get IP address from name */
  pHostInfo=gethostbyname("localhost");
  
  if(!pHostInfo){
      printf("Could not resolve host name\n");
      return 0;
  }
  
  /* copy address into long */
  memset(&amp;nHostAddress, 0, sizeof(nHostAddress));
  memcpy(&amp;nHostAddress,pHostInfo-&gt;h_addr,pHostInfo-&gt;h_length);
  </code></pre>
  
  <p>nHostAddress contains the following:</p>
  
  <pre><code>16777243
  </code></pre>
  
  <p>How do I convert the result so that I can get the output as :</p>
  
  <pre><code>127.0.0.1
  </code></pre>