home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.sbin / named / tools / nsquery / nsquery.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-25  |  3.4 KB  |  111 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, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. char copyright[] =
  36. "@(#) Copyright (c) 1986 Regents of the University of California.\n\
  37.  All rights reserved.\n";
  38. #endif /* not lint */
  39.  
  40. #ifndef lint
  41. static char sccsid[] = "@(#)nsquery.c    4.8 (Berkeley) 6/1/90";
  42. #endif /* not lint */
  43.  
  44. #include <sys/param.h>
  45. #include <arpa/nameser.h>
  46. #include <netdb.h>
  47. #include <sys/socket.h>
  48. #include <netinet/in.h>
  49. #include <resolv.h>
  50. #include <stdio.h>
  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.     if (argc == 3) {
  70.         hp = gethostbyname(argv[2]);
  71.         if (hp == NULL) {
  72.             fprintf(stderr, "nsquery:");
  73.             herror(argv[2]);
  74.             exit(1);
  75.         }
  76.         printf("\nServer:\n");
  77.         printanswer(hp);
  78.         _res.nsaddr.sin_addr = *(struct in_addr *)hp->h_addr;
  79.     }
  80.  
  81.     hp = gethostbyname(argv[1]);
  82.     if (hp == NULL) {
  83.         fprintf(stderr, "nsquery: %s: ", argv[1]);
  84.         herror((char *)NULL);
  85.         exit(1);
  86.     }
  87.     printanswer(hp);
  88.     exit(0);
  89. }
  90.  
  91. printanswer(hp)
  92.     register struct hostent *hp;
  93. {
  94.     register char **cp;
  95.     extern char *inet_ntoa();
  96.  
  97.     printf("Name: %s\n", hp->h_name);
  98. #if BSD >= 43 || defined(h_addr)
  99.     printf("Addresses:");
  100.     for (cp = hp->h_addr_list; cp && *cp; cp++)
  101.         printf(" %s", inet_ntoa(*(struct in_addr *)(*cp)));
  102.     printf("\n");
  103. #else
  104.     printf("Address: %s\n", inet_ntoa(*(struct in_addr *)hp->h_addr));
  105. #endif
  106.     printf("Aliases:");
  107.     for (cp = hp->h_aliases; cp && *cp && **cp; cp++)
  108.         printf(" %s", *cp);
  109.     printf("\n\n");
  110. }
  111.