4.4BSD/usr/src/contrib/bind-4.9/contrib/misc/hostent.shar

#Return-Path: phil@dgbt.doc.ca
#Received: by cognition.pa.dec.com; id AA13396; Sun, 25 Apr 93 21:09:45 -0700
#Received: by inet-gw-1.pa.dec.com; id AA02573; Sun, 25 Apr 93 21:09:39 -0700
#Received: by dgbt.doc.ca (4.1/smail2.5/12-02-88)
#	id AA28233; Mon, 26 Apr 93 00:08:19 EDT
#Message-Id: <9304260408.AA28233@dgbt.doc.ca>
#From: phil@dgbt.doc.ca (Phil Blanchfield)
#Date: Mon, 26 Apr 93 00:08:19 EDT
#In-Reply-To: Paul A Vixie <vixie@pa.dec.com>
#       "send me your tools" (Apr 25, 12:28pm)
#Reply-To: phil@dgbt.doc.ca
#X-Mailer: Mail User's Shell (6.5 4/17/89)
#To: Paul A Vixie <vixie>
#Subject: Re: send me your tools
#
#On Apr 25, 12:28pm, Paul A Vixie wrote:
#} Subject: send me your tools
#> 
#> for the final 4.9 release i would like to include a "contrib" directory in
#> which a whole pile of contributed scripts and converters and checkers can
#> live.  if you have something which converts to/from /etc/hosts to/from
#> hosts.txt to/from zone files, or which scans any of those files for syntax
#> errors, or which checks domains for consistency, or which does something
#> else that you think other BIND users would want, please send it to me now.
#> 
#> it doesn't have to be pretty, or well-documented, though it would be nice.
#
#This is (embarrassingly) simple but heck I use it all the time. It simply
#prints out the "hostent" structure using gethostbyname(3) or gethostbyaddr(3).

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  hostent.1 hostent.c Makefile
# Wrapped by phil@dgbt.doc.ca on Mon Apr 26 00:06:51 1993
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'hostent.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'hostent.1'\"
else
echo shar: Extracting \"'hostent.1'\" \(1421 characters\)
sed "s/^X//" >'hostent.1' <<'END_OF_FILE'
X.TH HOSTENT 1 "31 July 1992"
X.SH NAME
Xhostent \- Displays the hostent structure for a given hostname
X.SH SYNOPSIS
X.B hostent {hostname | address}
X
X.SH DESCRIPTION
X.LP
X.B hostent
Xdisplays the
X.I hostent
Xsystem structure for the given hostname or dotted quad IP number.
XIt uses the system call gethostbyname(3) or gethostbyaddr(3) to
Xfill the hostent structure. Hostent was written to be used as a tool
Xto help debug name resolving issues. The interface that hostent uses
Xis exactly the same interface that utilities such as
X.I telnet
Xand
X.I ftp
Xuse to resolve IP numbers and names. It is especially useful if your
Xsystem uses multi-tier resolving (NIS, /etc/hosts, BIND).
Xresolving 
X.SH EXAMPLES
X.RS 
X.nf
X.ft B
Xexample% hostent ucbvax.berkeley.edu
XCannonical (Official) hostname = ucbvax.berkeley.edu
X
XList of aliases: <NONE EXIST>
X
X
XList of IP addresses:
X
Xaddress# 0  = 128.32.133.1
Xaddress# 1  = 128.32.130.12
Xaddress# 2  = 128.32.149.36
X.DT 
X.ft P
X.fi 
X.RE
X.LP
Xdisplays the contents of the hostent structure for
X.B ucbvax.berkeley.edu
Xon the standard output.
X.LP
X.RS 
X.nf
X.ft B
Xexample% hostent 128.32.133.1
XCannonical (Official) hostname = ucbvax.Berkeley.EDU
X
XList of aliases: <NONE EXIST>
X
X
XList of IP addresses:
X
Xaddress# 0  = 128.32.133.1
Xaddress# 1  = 128.32.130.12
Xaddress# 2  = 128.32.149.36
X.DT 
X.ft P
X.fi 
X.RE
X.LP
Xdoes the same in reverse.
X.SH "SEE ALSO"
X.BR gethostent (3)
X.SH AUTHOR
XPhil Blanchfield C.R.C.
END_OF_FILE
if test 1421 -ne `wc -c <'hostent.1'`; then
    echo shar: \"'hostent.1'\" unpacked with wrong size!
fi
# end of 'hostent.1'
fi
if test -f 'hostent.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'hostent.c'\"
else
echo shar: Extracting \"'hostent.c'\" \(2130 characters\)
sed "s/^X//" >'hostent.c' <<'END_OF_FILE'
X/*
X *	hostent.c
X *
X *	Program to print out a "hostent" structure given a hostname or
X *	"dotted quad" address. Therefore this is exactly what FTP Telnet
X *	or any utility that uses gethostbyname(3) sees.
X *
X *	Using nslookup alone can often give you a false sense of security.
X *
X *	Usage: hostent {hostname | address}
X *
X *	P. Blanchfield <phil@dgbt.doc.ca>
X *	The Communications Research Centre
X */
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netdb.h>
X
Xmain(argc,argv)
Xchar **argv;
X{
X	struct hostent *gethostbyaddr(), *gethostbyname(), *p2hostent;
X	int iaddr[4];	/* scanf can only convert integers */
X	char addr[4];	/* but we will need them as bytes */
X	int len;
X
X 	if( argc != 2 )
X	{
X	 fprintf(stderr,"Usage: %s {hostname | address}\n",argv[0]);
X	 exit(1);
X	}
X
X	if( (*argv[1] > '0') && (*argv[1] < '9') )	/* name or number? */
X	{ /* number */
X	  sscanf(argv[1],"%d.%d.%d.%d",&iaddr[0],&iaddr[1],&iaddr[2],&iaddr[3]);
X	  addr[0] = (char) iaddr[0];
X	  addr[1] = (char) iaddr[1];
X	  addr[2] = (char) iaddr[2];
X	  addr[3] = (char) iaddr[3];
X	  p2hostent = gethostbyaddr(addr, 4, AF_INET);
X	}
X	else /* name */
X	  p2hostent = gethostbyname(argv[1]);
X
X	if( p2hostent == NULL )
X	{
X		fprintf(stderr,"Lookup failure on host \"%s\"\n",argv[1]);
X		exit(1);
X	}
X
X	/* all is well, print the entry */
X
X	print_hostentry(p2hostent);
X
X}
X
X/* Function to print a "hostent" structure */
X
Xprint_hostentry(p2hostent)
Xstruct hostent *p2hostent;
X{ 
X
X	int i,j;
X	char *none;
X
X	/* Official name */
X
X	printf("Cannonical (Official) hostname = %s\n\n",p2hostent->h_name);
X
X	/* list of aliases */
X
X	if(p2hostent->h_aliases[0]) none = ""; else none = " <NONE EXIST>";
X	printf("List of aliases:%s\n\n",none);
X
X	for(i=0;p2hostent->h_aliases[i];i++)
X	  printf("alias# %d  = %s\n",i,p2hostent->h_aliases[i]);
X	printf("\n");
X
X	/* print out the list of addresses */
X
X	printf("List of IP addresses:\n\n");
X
X	for(i=0;p2hostent->h_addr_list[i];i++)
X	{
X	  printf("address# %d  = ",i);
X	  for(j=0;j<3;j++)
X	    printf("%u.",(unsigned char)p2hostent->h_addr_list[i][j]);
X	  printf("%u\n",(unsigned char)p2hostent->h_addr_list[i][j]);
X	}
X
X}
END_OF_FILE
if test 2130 -ne `wc -c <'hostent.c'`; then
    echo shar: \"'hostent.c'\" unpacked with wrong size!
fi
# end of 'hostent.c'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(1236 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X#
X# To use this Makefile you must first fill in the configuration information
X# below.
X#
X# To compile and link:
X# make
X#
X# To install:
X# make install
X#
X# To uninstall (remove):
X# make uninstall
X#
X# To clean up after the build type:
X# make clean
X#
X
X# START OF CONFIGURATION AREA
X
X# Change the following to the name of your program.
X# If your program source is called prog.c it would be:
X# PROGNAME=prog
X
XPROGNAME=hostent
X
X# Where to install the binary
XBINDIR = /usr/local/bin
X
X# Where to install the manual page.
XMANDIR = /usr/local/man/man1
X
X# cc flags (options which will be used by the c compiler)
X# Various "local" include files need -I/usr/local/include
X# most X11 applications will need -I/usr/openwin/include/X11
X
XCFLAGS= -O
X
X# C compiler to use.
X# cc by default, for gcc (GNU C) uncomment the next line
X#CC=gcc
X
X# linker flags.
X
XLDFLAGS= 
X
X# END OF CONFIGURATION AREA
X
X$(PROGNAME): $(PROGNAME).o
X	$(CC) $(PROGNAME).o -o $(PROGNAME) $(LDFLAGS)
X
Xinstall:
X	install $(PROGNAME) $(BINDIR)
X	-cp $(PROGNAME).1 $(MANDIR)
X	@echo
X	@echo "      If this is the first time that you have built this program"
X	@echo "      you must now type \"rehash\"."
X	@echo
X
Xuninstall:
X	rm -f $(BINDIR)/$(PROGNAME)
X
Xclean:
X	rm -f $(PROGNAME).o $(PROGNAME)
X
END_OF_FILE
if test 1236 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
echo shar: End of shell archive.
exit 0

#-- 
#Phil Blanchfield
#The Communications Research Centre 3701 Carling Avenue, Ottawa Ontario CANADA
#Internet: Phil.Blanchfield@CRC.DOC.CA