📄 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 1993PATH=/bin:/usr/bin:/usr/ucb ; export PATHif test -f 'hostent.1' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hostent.1'\"elseecho shar: Extracting \"'hostent.1'\" \(1421 characters\)sed "s/^X//" >'hostent.1' <<'END_OF_FILE'X.TH HOSTENT 1 "31 July 1992"X.SH NAMEXhostent \- Displays the hostent structure for a given hostnameX.SH SYNOPSISX.B hostent {hostname | address}XX.SH DESCRIPTIONX.LPX.B hostentXdisplays theX.I hostentXsystem structure for the given hostname or dotted quad IP number.XIt uses the system call gethostbyname(3) or gethostbyaddr(3) toXfill the hostent structure. Hostent was written to be used as a toolXto help debug name resolving issues. The interface that hostent usesXis exactly the same interface that utilities such asX.I telnetXandX.I ftpXuse to resolve IP numbers and names. It is especially useful if yourXsystem uses multi-tier resolving (NIS, /etc/hosts, BIND).Xresolving X.SH EXAMPLESX.RS X.nfX.ft BXexample% hostent ucbvax.berkeley.eduXCannonical (Official) hostname = ucbvax.berkeley.eduXXList of aliases: <NONE EXIST>XXXList of IP addresses:XXaddress# 0 = 128.32.133.1Xaddress# 1 = 128.32.130.12Xaddress# 2 = 128.32.149.36X.DT X.ft PX.fi X.REX.LPXdisplays the contents of the hostent structure forX.B ucbvax.berkeley.eduXon the standard output.X.LPX.RS X.nfX.ft BXexample% hostent 128.32.133.1XCannonical (Official) hostname = ucbvax.Berkeley.EDUXXList of aliases: <NONE EXIST>XXXList of IP addresses:XXaddress# 0 = 128.32.133.1Xaddress# 1 = 128.32.130.12Xaddress# 2 = 128.32.149.36X.DT X.ft PX.fi X.REX.LPXdoes the same in reverse.X.SH "SEE ALSO"X.BR gethostent (3)X.SH AUTHORXPhil Blanchfield C.R.C.END_OF_FILEif test 1421 -ne `wc -c <'hostent.1'`; then echo shar: \"'hostent.1'\" unpacked with wrong size!fi# end of 'hostent.1'fiif test -f 'hostent.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hostent.c'\"elseecho shar: Extracting \"'hostent.c'\" \(2130 characters\)sed "s/^X//" >'hostent.c' <<'END_OF_FILE'X/*X * hostent.cX *X * Program to print out a "hostent" structure given a hostname orX * "dotted quad" address. Therefore this is exactly what FTP TelnetX * 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 CentreX */XX#include <stdio.h>X#include <sys/types.h>X#include <sys/socket.h>X#include <netdb.h>XXmain(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;XX if( argc != 2 )X {X fprintf(stderr,"Usage: %s {hostname | address}\n",argv[0]);X exit(1);X }XX 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]);XX if( p2hostent == NULL )X {X fprintf(stderr,"Lookup failure on host \"%s\"\n",argv[1]);X exit(1);X }XX /* all is well, print the entry */XX print_hostentry(p2hostent);XX}XX/* Function to print a "hostent" structure */XXprint_hostentry(p2hostent)Xstruct hostent *p2hostent;X{ XX int i,j;X char *none;XX /* Official name */XX printf("Cannonical (Official) hostname = %s\n\n",p2hostent->h_name);XX /* list of aliases */XX if(p2hostent->h_aliases[0]) none = ""; else none = " <NONE EXIST>";X printf("List of aliases:%s\n\n",none);XX for(i=0;p2hostent->h_aliases[i];i++)X printf("alias# %d = %s\n",i,p2hostent->h_aliases[i]);X printf("\n");XX /* print out the list of addresses */XX printf("List of IP addresses:\n\n");XX 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 }XX}END_OF_FILEif test 2130 -ne `wc -c <'hostent.c'`; then echo shar: \"'hostent.c'\" unpacked with wrong size!fi# end of 'hostent.c'fiif test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\"elseecho 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 informationX# below.X#X# To compile and link:X# makeX#X# To install:X# make installX#X# To uninstall (remove):X# make uninstallX#X# To clean up after the build type:X# make cleanX#XX# START OF CONFIGURATION AREAXX# Change the following to the name of your program.X# If your program source is called prog.c it would be:X# PROGNAME=progXXPROGNAME=hostentXX# Where to install the binaryXBINDIR = /usr/local/binXX# Where to install the manual page.XMANDIR = /usr/local/man/man1XX# cc flags (options which will be used by the c compiler)X# Various "local" include files need -I/usr/local/includeX# most X11 applications will need -I/usr/openwin/include/X11XXCFLAGS= -OXX# C compiler to use.X# cc by default, for gcc (GNU C) uncomment the next lineX#CC=gccXX# linker flags.XXLDFLAGS= XX# END OF CONFIGURATION AREAXX$(PROGNAME): $(PROGNAME).oX $(CC) $(PROGNAME).o -o $(PROGNAME) $(LDFLAGS)XXinstall:X install $(PROGNAME) $(BINDIR)X -cp $(PROGNAME).1 $(MANDIR)X @echoX @echo " If this is the first time that you have built this program"X @echo " you must now type \"rehash\"."X @echoXXuninstall:X rm -f $(BINDIR)/$(PROGNAME)XXclean:X rm -f $(PROGNAME).o $(PROGNAME)XEND_OF_FILEif test 1236 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size!fi# end of 'Makefile'fiecho 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -