home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / n / bind / bind-4.001 / bind-4~ / bind-4.9.3-BETA9 / contrib / decwrl / host.c < prev    next >
C/C++ Source or Header  |  1994-06-01  |  2KB  |  71 lines

  1. /* host - print information about a host
  2.  * originally written by Paul Vixie @DEC WRL, January 1989
  3.  */
  4.  
  5. /* DECWRL Header: host.c,v 1.1 89/04/05 15:41:12 vixie Locked $ */
  6.  
  7. #ifndef lint
  8. static char RcsId[] = "$Id: host.c,v 1.3 1994/06/01 21:09:34 vixie Exp $";
  9. #endif
  10.  
  11. #include <sys/param.h>
  12. #include <sys/socket.h>
  13. #include <netinet/in.h>
  14. #include <arpa/inet.h>
  15.  
  16. #include <stdio.h>
  17. #include <netdb.h>
  18. #include <syslog.h>
  19.  
  20. #ifndef LOG_PERROR
  21. #define LOG_PERROR 0
  22. #endif
  23.  
  24. main(argc, argv)
  25.     char **argv;
  26. {
  27.     long l_addr;
  28.     struct in_addr addr, **ap;
  29.     struct hostent *host;
  30.     char **cp;
  31.  
  32. #ifdef LOG_USER
  33.     openlog("host", LOG_PERROR, LOG_USER);
  34. #else
  35.     openlog("host", LOG_PERROR);
  36. #endif
  37.     if (argc != 2) {
  38.         printf("usage:  %s (hostname|ipaddr)\n", argv[0]);
  39.         exit(1);
  40.     }
  41.     l_addr = inet_addr(argv[1]);
  42.     if (l_addr != -1) {
  43.         addr = * (struct in_addr *) &l_addr;
  44.         printf("[%s]\n", inet_ntoa(addr));
  45.         if (!(host = gethostbyaddr((char*)&addr, sizeof addr,
  46.                        AF_INET))) {
  47.             herror("gethostbyaddr");
  48.             exit(1);
  49.         }
  50.     } else {
  51.         printf("{%s}\n", argv[1]);
  52.         if (!(host = gethostbyname(argv[1]))) {
  53.             herror("gethostbyname");
  54.             exit(1);
  55.         }
  56.     }
  57.     printf("name: %s\n", host->h_name);
  58.     if (host->h_aliases && *host->h_aliases) {
  59.         printf("aliases:");
  60.         for (cp = (char **) host->h_aliases; *cp; cp++)
  61.             printf(" %s", *cp);
  62.         printf("\n");
  63.     }
  64.     if (host->h_addr_list && *host->h_addr_list) {
  65.         printf("addresses:");
  66.         for (ap = (struct in_addr **) host->h_addr_list; *ap; ap++)
  67.             printf(" %s", inet_ntoa(**ap));
  68.         printf("\n");
  69.     }
  70. }
  71.