1: #ifndef lint
   2: static char sccsid[] = "@(#)nsquery.c	4.1 (Berkeley) 5/12/86";
   3: #endif
   4: 
   5: /*
   6:  * Copyright (c) 1986 Regents of the University of California
   7:  *	All Rights Reserved
   8:  */
   9: 
  10: #include <stdio.h>
  11: #include <sys/types.h>
  12: #include <arpa/nameser.h>
  13: #include <netdb.h>
  14: #include <sys/socket.h>
  15: #include <netinet/in.h>
  16: #include <resolv.h>
  17: 
  18: struct state orig;
  19: extern struct state _res;
  20: 
  21: main(c, v)
  22:     char **v;
  23: {
  24:     char h[32];
  25:     register struct hostent *hp;
  26:     register char *s;
  27: 
  28:     gethostname(h, 32);
  29:     s = h;
  30:     if (c < 2) {
  31:         fprintf(stderr, "Usage: lookup host [server]\n");
  32:         exit(1);
  33:     }
  34:     if (c > 2)
  35:         s = v[2];
  36: 
  37:     hp = gethostbyname(s);
  38:     if (hp == NULL) {
  39:         hperror(h_errno);
  40:         exit(1);
  41:     }
  42:     printanswer(hp);
  43: 
  44:     _res.nsaddr.sin_addr = *(struct in_addr *)hp->h_addr;
  45:     _res.options &= ~RES_DEFNAMES;
  46: 
  47:     hp = gethostbyname(v[1]);
  48:     if (hp == NULL) {
  49:         hperror(h_errno);
  50:         exit(1);
  51:     }
  52:     printanswer(hp);
  53:     exit(0);
  54: }
  55: 
  56: printanswer(hp)
  57:     register struct hostent *hp;
  58: {
  59:     register char **cp;
  60:     extern char *inet_ntoa();
  61: 
  62:     printf("Name: %s\n", hp->h_name);
  63:     printf("Address: %s\n", inet_ntoa(*(struct in_addr *)hp->h_addr));
  64:     printf("Aliases:");
  65:     for (cp = hp->h_aliases; cp && *cp && **cp; cp++)
  66:         printf(" %s", *cp);
  67:     printf("\n\n");
  68: }
  69: 
  70: hperror(errno)
  71: int errno;
  72: {
  73: switch(errno) {
  74:     case HOST_NOT_FOUND:
  75:         fprintf(stderr,"Host not found.\n");
  76:         break;
  77:     case TRY_AGAIN:
  78:         fprintf(stderr,"Host not found, try again.\n");
  79:         break;
  80:     case NO_RECOVERY:
  81:         fprintf(stderr,"No recovery, Host not found.\n");
  82:         break;
  83:     case NO_ADDRESS:
  84:         fprintf(stderr,"No Address, look for MF record.\n");
  85:         break;
  86:     }
  87: }

Defined functions

hperror defined in line 70; used 2 times
main defined in line 21; never used
printanswer defined in line 56; used 2 times

Defined variables

orig defined in line 18; never used
sccsid defined in line 2; never used
Last modified: 1986-05-12
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1111
Valid CSS Valid XHTML 1.0 Strict