title: Array of in_addr
body: <p>I would like to create a array of in_addr using gethostbyname().  After looking on Google, I have found this short code (at <a href="http://www.logix.cz/michal/devel/various/gethostbyname.c.xp" rel="nofollow noreferrer">http://www.logix.cz/michal/devel/various/gethostbyname.c.xp</a>):</p>
  
  <pre><code>/*
   * gethostbyname.c - Example of using gethostbyname(3)
   * Martin Vidner &lt;mvidner@suse.cz&gt;
   */
  
  #include &lt;stdio.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;netinet/in.h&gt;
  
  struct hostent *he;
  struct in_addr a;
  
  int
  main (int argc, char **argv)
  {
      if (argc != 2)
      {
          fprintf(stderr, "usage: %s hostname\n", argv[0]);
          return 1;
      }
      he = gethostbyname (argv[1]);
      if (he)
      {
          printf("name: %s\n", he-&gt;h_name);
          while (*he-&gt;h_aliases)
              printf("alias: %s\n", *he-&gt;h_aliases++);
          while (*he-&gt;h_addr_list)
          {
              bcopy(*he-&gt;h_addr_list++, (char *) &amp;a, sizeof(a));
              printf("address: %s\n", inet_ntoa(a));
          }
      }
      else
          herror(argv[0]);
      return 0;
  }
  </code></pre>
  
  <p>I tested this code with this:</p>
  
  <pre><code>$ ./a.out google.com
  name: google.com
  address: 74.125.45.100
  address: 74.125.53.100
  address: 74.125.67.100
  </code></pre>
  
  <p>Seeing this result, I am satisfied because I wanted a list of IP addresses from a domain.</p>
  
  <p>But I just have one problem: I don't know how to save this list of IP addresses in a array (with the same size than addresses number)... have you got an example by chance?</p>
  
  <p>Thank you</p>