home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / NETWORK / ISP / bind.4.8.3.lzh / BIND483 / TOOLS / nsquery.c < prev    next >
C/C++ Source or Header  |  1994-09-23  |  3KB  |  122 lines

  1. /*
  2.  * Copyright (c) 1986 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted provided
  6.  * that: (1) source distributions retain this entire copyright notice and
  7.  * comment, and (2) distributions including binaries display the following
  8.  * acknowledgement:  ``This product includes software developed by the
  9.  * University of California, Berkeley and its contributors'' in the
  10.  * documentation or other materials provided with the distribution and in
  11.  * all advertising materials mentioning features or use of this software.
  12.  * Neither the name of the University nor the names of its contributors may
  13.  * be used to endorse or promote products derived from this software without
  14.  * specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  16.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  17.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  */
  19.  
  20. #ifndef lint
  21. char copyright[] =
  22. "@(#) Copyright (c) 1986 Regents of the University of California.\n\
  23.  All rights reserved.\n";
  24. #endif /* not lint */
  25.  
  26. #ifndef lint
  27. static char sccsid[] = "@(#)nsquery.c    4.8 (Berkeley) 6/1/90";
  28. #endif /* not lint */
  29.  
  30. #include <sys/param.h>
  31. #ifdef OSK
  32. #include <types.h>
  33. #include <errno.h>
  34. #endif
  35. #include <arpa/nameser.h>
  36. #include <netdb.h>
  37. #ifdef OSK
  38. #include <socket.h>
  39. #include <in.h>
  40. #else
  41. #include <sys/socket.h>
  42. #include <netinet/in.h>
  43. #endif
  44. #include <resolv.h>
  45. #include <stdio.h>
  46.  
  47. #ifdef OSK
  48. int ev_id = 0;
  49. char evname[10];
  50. #endif
  51.  
  52. main(argc, argv)
  53.     int argc;
  54.     char **argv;
  55. {
  56.     extern struct state _res;
  57.     register struct hostent *hp;
  58.     register char *s;
  59.  
  60.     if (argc >= 2 && strcmp(argv[1], "-d") == 0) {
  61.         _res.options |= RES_DEBUG;
  62.         argc--;
  63.         argv++;
  64.     }
  65.     if (argc < 2) {
  66.         fprintf(stderr, "usage: nsquery [-d] host [server]\n");
  67.         exit(1);
  68.     }
  69. #ifdef OSK
  70.    strcpy(evname, "chsoaXXXXXX");
  71.    mktemp(evname);
  72.    if ((ev_id = _ev_link(evname)) == -1)
  73.       if ((ev_id = _ev_creat(0, -1, 1, mktemp(evname))) == -1) {
  74.          fprintf(stderr, "*** checksoa(%d): can't create event '%s'\n",
  75.                        getpid(), evname);
  76.          exit(errno);
  77.       }
  78.    _ev_set(ev_id, 0, 0);
  79. #endif         
  80.     if (argc == 3) {
  81.         hp = gethostbyname(argv[2]);
  82.         if (hp == NULL) {
  83.             fprintf(stderr, "nsquery:");
  84.             herror(argv[2]);
  85.             exit(1);
  86.         }
  87.         printf("\nServer:\n");
  88.         printanswer(hp);
  89.         _res.nsaddr.sin_addr = *(struct in_addr *)hp->h_addr;
  90.     }
  91.  
  92.     hp = gethostbyname(argv[1]);
  93.     if (hp == NULL) {
  94.         fprintf(stderr, "nsquery: %s: ", argv[1]);
  95.         herror((char *)NULL);
  96.         exit(1);
  97.     }
  98.     printanswer(hp);
  99.     exit(0);
  100. }
  101.  
  102. printanswer(hp)
  103.     register struct hostent *hp;
  104. {
  105.     register char **cp;
  106.     extern char *inet_ntoa();
  107.  
  108.     printf("Name: %s\n", hp->h_name);
  109. #if BSD >= 43 || defined(h_addr)
  110.     printf("Addresses:");
  111.     for (cp = hp->h_addr_list; cp && *cp; cp++)
  112.         printf(" %s", inet_ntoa(*(struct in_addr *)(*cp)));
  113.     printf("\n");
  114. #else
  115.     printf("Address: %s\n", inet_ntoa(*(struct in_addr *)hp->h_addr));
  116. #endif
  117.     printf("Aliases:");
  118.     for (cp = hp->h_aliases; cp && *cp && **cp; cp++)
  119.         printf(" %s", *cp);
  120.     printf("\n\n");
  121. }
  122.