Over a million developers have joined DZone.

Gethostbyname

·

#include 
#include 
#include 
#include 
#include 

int main(int argc, char **argv) {

   int i;
   struct hostent *host;
   host = (argc > 1) ? gethostbyname(argv[1]) : gethostbyname("s2.enemy.org");

   if (!host) {
      perror("Invalid Address");
      exit(0);
   }

   printf("Addresses for %s\n", host->h_name);

   i=0;
   while (host->h_addr_list[i]) {
      printf("\t%s\n",
         inet_ntoa(*(struct in_addr *)host->h_addr_list[i]));
      i++;
   }
   return;
}

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}