Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Jun 2000 20:37:21 -0700 (MST)
From:      "Chad R. Larson" <chad@DCFinc.com>
To:        blk@skynet.be (Brad Knowles)
Cc:        freebsd.stable@lists.craxx.nl, freebsd-stable@FreeBSD.ORG
Subject:   Re: Weird NSLOOKUP output...
Message-ID:  <200006230337.UAA07934@freeway.dcfinc.com>
In-Reply-To: <v04220815b577cdd16cd8@[195.238.1.121]> from Brad Knowles at "Jun 22, 0 04:10:29 pm"

next in thread | previous in thread | raw e-mail | index | archive | help

--ELM961731441-7805-0_
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

As I recall, Brad Knowles wrote:
> It is my understanding that the current version of nslookup is
> unlikely to live much longer.  BIND-knowledgeable people I know of
> strongly recommend that you use "dig" instead, and in fact I've
> heard rumours that future versions of nslookup may in fact simply
> be another interface to the "dig" program, or may be a script of
> some sort that simply calls dig.

And, I've become sorta fond of the "host(1)" program, which by
default does pretty much what you would do when looking up a system.

However, as I've noted here before, there is a pitfall.  Most
application programs don't call the resolver routines directly.
They call "gethostbyname(3)", which =may= query the /etc/hosts file
before checking with DNS via the resolver.  So, if you've overloaded
a DNS address with one in the hosts file (deliberately or
accidentally), your application will not get the same answer you
will get from dig/host/nslookup.  Much confusion can result.  Don't
ask my how I know this.

Attached is a tiny, no-man-page, trivial utility that wraps a
command line interface around the gethostbyname call specifically to
help sort out such confusions.

	-crl
--
Chad R. Larson (CRL15)   602-953-1392   Brother, can you paradigm?
chad@dcfinc.com         chad@larsons.org          larson1@home.net   
DCF, Inc. - 14623 North 49th Place, Scottsdale, Arizona 85254-2207

--ELM961731441-7805-0_
Content-Type: application/x-shar
Content-Disposition: attachment; filename=gethost.shar
Content-Description: command line interface to gethostbyname(3)
Content-Transfer-Encoding: 7bit

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	gethost.c
#	Makefile
#
echo x - gethost.c
sed 's/^X//' >gethost.c << 'END-of-gethost.c'
X/* $Id: gethost.c,v 1.1 2000/05/17 04:52:06 chad Exp $*/
X
X/*
X * Print the "hostent" information for every host whose name is
X * specified on the command line.
X */
X
X#include	<stdio.h>
X#include	<sys/types.h>
X#include	<netdb.h>		/* for struct hostent */
X#include	<sys/socket.h>		/* for AF_INET */
X#include	<netinet/in.h>		/* for struct in_addr */
X#include	<arpa/inet.h>		/* for inet_ntoa() */
X
X#define FALSE 0
X#define TRUE ~FALSE
X
Xmain(argc, argv)
Xint	argc;
Xchar	**argv;
X{
X	register char		*ptr;
X	register struct hostent	*hostptr;
X	int			tcp_flag = FALSE;	/* stream or dgram ? */
X
X	if (argc < 2) {
X	    printf("Usage: %s hostname [...]\n", argv[0]);
X	    exit(1);
X	}
X
X	if (argc > 2) {	/* use virtual circuit if more than one query */
X	    tcp_flag = TRUE;
X	    sethostent(TRUE);
X	}
X
X	while (--argc > 0) {
X		ptr = *++argv;
X		if ( (hostptr = gethostbyname(ptr)) == NULL) {
X		    printf("gethostbyname error for host %s: ", ptr);
X		    err_ret(h_errno);
X			continue;
X		}
X		printf("\nOfficial host name: %s\n", hostptr->h_name);
X
X		/* go through the list of aliases */
X		while ( (ptr = *(hostptr->h_aliases)) != NULL) {
X			printf("	alias: %s\n", ptr);
X			hostptr->h_aliases++;
X		}
X
X		switch (hostptr->h_addrtype) {
X		case AF_INET:
X			pr_inet(hostptr->h_addr_list, hostptr->h_length);
X			break;
X
X		default:
X			printf("unknown address type");
X			break;
X		}
X	}
X	if (tcp_flag)
X	    endhostent();
X}
X
X/*
X * Go through a list of Internet addresses,
X * printing each one in dotted-decimal notation.
X */
X
Xpr_inet(listptr, length)
Xchar	**listptr;
Xint	length;
X{
X	struct in_addr	*ptr;
X
X	while ( (ptr = (struct in_addr *) *listptr++) != NULL)
X		printf("	Internet address: %s\n", inet_ntoa(*ptr));
X}
X
X/*
X * Display hostent error code
X */
X
Xerr_ret(err)
Xint	err;
X{
X    switch (err) {
X	case HOST_NOT_FOUND:
X	    printf("Authoritative Answer Host not found\n");
X	    break;
X	case TRY_AGAIN:
X	    printf("Non-Authoritive Host not found, or server fail\n");
X	    break;
X	case NO_RECOVERY:
X	    printf("Non recoverable errors, FORMERR, REFUSED, NOTIMP\n");
X	    break;
X	case NO_DATA:
X	    printf("Valid name, no data record of requested type\n");
X	default:
X	    printf("Unknown error code %d\n", err);
X	    break;
X    }
X}
END-of-gethost.c
echo x - Makefile
sed 's/^X//' >Makefile << 'END-of-Makefile'
X# Makefile for the host name lookup program
X#  $Id: Makefile,v 1.1 2000/05/17 04:52:06 chad Exp $
X
XBINDIR =	/usr/local/bin
X
Xgethost:	gethost.o
X	$(CC) $(CFLAGS) gethost.o -o gethost
X
Xinstall:	gethost
X	install -C -s gethost $(BINDIR)
X
X.c.o:
X	$(CC) $(CFLAGS) -c $<
END-of-Makefile
exit


--ELM961731441-7805-0_--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200006230337.UAA07934>