home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE3.TAR / xarchie-2.0.1 / resolv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-22  |  1.1 KB  |  44 lines

  1. /*
  2.  * resolv.c : Program to test if you need -lresolv to ensure DNS
  3.  *          hostname lookups.
  4.  *
  5.  * George Ferguson, ferguson@cs.rochester.edu, 23 Apr 1993.
  6.  *
  7.  * Compile with: cc -o resolv resolv.c
  8.  *
  9.  * If you get an error message when you run the program, you need -lresolv.
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <netdb.h>
  14.  
  15. main(argc,argv)
  16. int argc;
  17. char *argv[];
  18. {
  19.     char *hostname = "archie.ans.net";
  20.     char *addr;
  21.     struct hostent *host;
  22.     int i;
  23.  
  24.     if (argc > 1)
  25.     hostname = argv[1];
  26.     if((host=gethostbyname(hostname)) == NULL) {
  27.         herror(hostname);
  28.         exit(1);
  29.     } else {
  30.     if (strcmp(hostname,host->h_name) != 0)
  31.         printf("%s has official name %s\n",hostname,host->h_name);
  32.     for (i=0; host->h_aliases[i]; i++)
  33.         if (strcmp(hostname,host->h_aliases[i]) != 0)
  34.         printf("%s has alias %s\n",hostname,host->h_aliases[i]);
  35.     for (i=0; host->h_addr_list[i]; i++) {
  36.         addr = host->h_addr_list[i];
  37.         printf("%s has address %d.%d.%d.%d\n",hostname,
  38.            ((unsigned char *)addr)[0],((unsigned char *)addr)[1],
  39.            ((unsigned char *)addr)[2],((unsigned char *)addr)[3]);
  40.     }
  41.     exit(0);
  42.     }
  43. }
  44.