#include <netdb.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>

/*
 * Internet name resolution command.
 * Please give has many names you want on the command-line (at least one).
 */
int main(int argc,char *argv[]) {
  struct hostent *he; int i;

  if (argc<2) {
    fprintf(stderr,"usage: %s name [name...]\n",argv[0]); exit(EXIT_FAILURE);
  }
  for (i=1; i<argc; i++) { // foreach arg
    char **aliases;
    struct in_addr **addresses;
    printf("--------%s\n",argv[i]); // which arg it is ?
    he = gethostbyname(argv[i]); // get it...
    if (he==NULL) { // something's wrong, bypass
      printf("unknown\n");
      continue;
    }
    printf("Official name : %s\n",he->h_name);
    aliases = he->h_aliases;
    while ((*aliases)!=NULL) { // Please give me all aliases of the canonical name
      printf("Alias         : %s\n",*(aliases++));
    }
    // and every addresses
    for (addresses=(struct in_addr **)he->h_addr_list; *addresses!=NULL; addresses++) {
      printf("Address       : %s\n",inet_ntoa(**addresses));
    }
  }
}