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: #if !defined(lint) && defined(DOSCCS)
  21: char copyright[] =
  22: "@(#) Copyright (c) 1986 Regents of the University of California.\n\
  23:  All rights reserved.\n";
  24: 
  25: static char sccsid[] = "@(#)nsquery.c	4.8 (Berkeley) 6/1/90";
  26: #endif
  27: 
  28: #include <sys/param.h>
  29: #include <arpa/nameser.h>
  30: #include <netdb.h>
  31: #include <sys/socket.h>
  32: #include <netinet/in.h>
  33: #include <resolv.h>
  34: #include <stdio.h>
  35: 
  36: main(argc, argv)
  37:     int argc;
  38:     char **argv;
  39: {
  40:     extern struct state _res;
  41:     register struct hostent *hp;
  42: 
  43:     if (argc >= 2 && strcmp(argv[1], "-d") == 0) {
  44:         _res.options |= RES_DEBUG;
  45:         argc--;
  46:         argv++;
  47:     }
  48:     if (argc < 2) {
  49:         fprintf(stderr, "usage: nsquery [-d] host [server]\n");
  50:         exit(1);
  51:     }
  52:     if (argc == 3) {
  53:         hp = gethostbyname(argv[2]);
  54:         if (hp == NULL) {
  55:             fprintf(stderr, "nsquery:");
  56:             herror(argv[2]);
  57:             exit(1);
  58:         }
  59:         printf("\nServer:\n");
  60:         printanswer(hp);
  61:         _res.nsaddr.sin_addr = *(struct in_addr *)hp->h_addr;
  62:     }
  63: 
  64:     hp = gethostbyname(argv[1]);
  65:     if (hp == NULL) {
  66:         fprintf(stderr, "nsquery: %s: ", argv[1]);
  67:         herror((char *)NULL);
  68:         exit(1);
  69:     }
  70:     printanswer(hp);
  71:     exit(0);
  72: }
  73: 
  74: printanswer(hp)
  75:     register struct hostent *hp;
  76: {
  77:     register char **cp;
  78:     extern char *inet_ntoa();
  79: 
  80:     printf("Name: %s\n", hp->h_name);
  81: #if BSD >= 43 || defined(h_addr)
  82:     printf("Addresses:");
  83:     for (cp = hp->h_addr_list; cp && *cp; cp++)
  84:         printf(" %s", inet_ntoa(*(struct in_addr *)(*cp)));
  85:     printf("\n");
  86: #else
  87:     printf("Address: %s\n", inet_ntoa(*(struct in_addr *)hp->h_addr));
  88: #endif
  89:     printf("Aliases:");
  90:     for (cp = hp->h_aliases; cp && *cp && **cp; cp++)
  91:         printf(" %s", *cp);
  92:     printf("\n\n");
  93: }

Defined functions

main defined in line 36; never used
printanswer defined in line 74; used 2 times

Defined variables

copyright defined in line 21; never used
sccsid defined in line 25; never used
Last modified: 1993-04-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1379
Valid CSS Valid XHTML 1.0 Strict