From anarcat@anarcat.dyndns.org  Mon Nov 26 15:08:18 2001
Return-Path: <anarcat@anarcat.dyndns.org>
Received: from tomts14-srv.bellnexxia.net (tomts14.bellnexxia.net [209.226.175.35])
	by hub.freebsd.org (Postfix) with ESMTP id E060437B41B
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 26 Nov 2001 15:08:17 -0800 (PST)
Received: from khan.anarcat.dyndns.org ([65.94.177.56])
          by tomts6-srv.bellnexxia.net
          (InterMail vM.4.01.03.16 201-229-121-116-20010115) with ESMTP
          id <20011126225911.BMMD9997.tomts6-srv.bellnexxia.net@khan.anarcat.dyndns.org>
          for <FreeBSD-gnats-submit@freebsd.org>;
          Mon, 26 Nov 2001 17:59:11 -0500
Received: from shall.anarcat.dyndns.org (shall.anarcat.dyndns.org [192.168.0.1])
	by khan.anarcat.dyndns.org (Postfix) with ESMTP id F245518D3
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 26 Nov 2001 18:01:44 -0500 (EST)
Received: by shall.anarcat.dyndns.org (Postfix, from userid 1000)
	id 0DE1120ACB; Mon, 26 Nov 2001 18:00:38 -0500 (EST)
Message-Id: <20011126230038.0DE1120ACB@shall.anarcat.dyndns.org>
Date: Mon, 26 Nov 2001 18:00:38 -0500 (EST)
From: The Anarcat <anarcat@anarcat.dyndns.org>
Reply-To: The Anarcat <anarcat@anarcat.dyndns.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: no userland tool available to test resolver facilities
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         32318
>Category:       bin
>Synopsis:       no userland tool available to test resolver facilities
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    cjc
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 26 15:10:01 PST 2001
>Closed-Date:    Mon Aug 26 11:26:51 PDT 2002
>Last-Modified:  Mon Aug 26 11:26:51 PDT 2002
>Originator:     The Anarcat
>Release:        FreeBSD 4.4-STABLE i386
>Organization:
Nada, Inc.
>Environment:
System: FreeBSD shall.anarcat.dyndns.org 4.4-STABLE FreeBSD 4.4-STABLE #0: Fri Nov 16 12:57:38 EST 2001 anarcat@shall.anarcat.dyndns.org:/usr/obj/usr/src/sys/SHALL i386


>Description:

Traditionally, since BIND has been part of FreeBSD for a good while, a
few basic tools are available to query the DNS servers configured on a
machine. However, no tool is available to query the resolver (in the
sense of gethostbyname/addr() routines) transparently. Host(1), dig(1),
nslookup(1) all use the name servers, and not the /etc/hosts files or
NIS/YP.

>How-To-Repeat:

Try to do a address to hostname lookup using a command line tool for an
address in /etc/hosts that will actually use gethostbyname(3). I don't
know of any such tool and a post on -questions didn't yield anything
better.

>Fix:

Possible implementation of a iplookup tool.

Chris J. Clark sent code to freebsd-questions, for a tool that would to
reverse lookups with gethostbyaddr(3). I hacked it a bit to lookup names
-> addresses in case the address isn't parsable.

See:

Message-ID: <20011126010753.E222@gohan.cjclark.org>

on -questions for the original code.

/*
 * Copyright (c) 2001 Crist J. Clark
 * $Id: iplookup.c,v 1.2 2001/11/26 22:01:40 anarcat Exp $
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <err.h>
#include <netdb.h>
#include <stdio.h>
#include <sysexits.h>

int main(int argc, char *argv[])
{
	struct hostent	*h;
	struct in_addr	a;
	int		i, name_l;
	char 		addr[24];
	char 		**p;

	for (i = 1; i < argc; i++) {
		if (name_l = (inet_aton(argv[i], &a) == 0)) {
			h = gethostbyname(argv[i]);
		} else {
			h = gethostbyaddr((char *)&a, sizeof a, AF_INET);
		}
		if (h == NULL)
			errx(EX_OSERR, "address, %s, failed: %s",
			    argv[i], hstrerror(h_errno));

		if (name_l) {
			printf("%s: ", h->h_name);
			a.s_addr = inet_addr(h->h_addr);
        		for (p = h->h_addr_list ; p != NULL && *p ;) {
                		addr[0] = '\0';
                		inet_ntop(h->h_addrtype, *p, addr, sizeof addr);
                		printf("%s",addr);
				if (++p != NULL && *p) {
					printf(", ");
				}
        		}
			printf("\n");
		} else {
			printf("%s: %s\n", argv[i], h->h_name);
		}

		for (p = h->h_aliases; p != NULL && *p; p++)
			printf("\t%s\n", *p);
	}

	return 0;
}
>Release-Note:
>Audit-Trail:

From: Makoto Matsushita <matusita@jp.freebsd.org>
To: FreeBSD-gnats-submit@FreeBSD.ORG
Cc:  
Subject: Re: bin/32318: no userland tool available to test resolver
 facilities
Date: Tue, 27 Nov 2001 11:11:10 +0900

 Anyway how about putting this tool as a port?  It would be helpful for
 other users.
 
 anarcat> However, no tool is available to query the resolver (in the
 anarcat> sense of gethostbyname/addr() routines)
 anarcat> transparently. Host(1), dig(1), nslookup(1) all use the name
 anarcat> servers, and not the /etc/hosts files or NIS/YP.
 
 But only host(1) and its friend does check only DNS, these are the
 exceptions.  You can use other networking tools such as ping(8),
 telnet(1), and more (I don't know which tool fits for you).
 
 anarcat> Try to do a address to hostname lookup using a command line
 anarcat> tool for an address in /etc/hosts that will actually use
 anarcat> gethostbyname(3).
 
 It would be better that you use getaddrinfo(3) instead.  This tool
 only works with IPv4 address but FreeBSD knows what IPv6 is.
 
 -- -
 Makoto `MAR' Matsushita
Responsible-Changed-From-To: freebsd-bugs->cjc 
Responsible-Changed-By: cjc 
Responsible-Changed-When: Mon Nov 26 23:55:48 PST 2001 
Responsible-Changed-Why:  
I helped start it. I'll finish it. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32318 

From: Peter Pentchev <roam@ringlet.net>
To: Makoto Matsushita <matusita@jp.freebsd.org>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/32318: no userland tool available to test resolver facilities
Date: Tue, 27 Nov 2001 17:11:18 +0200

 On Mon, Nov 26, 2001 at 06:20:01PM -0800, Makoto Matsushita wrote:
 > The following reply was made to PR bin/32318; it has been noted by GNATS.
 > 
 > From: Makoto Matsushita <matusita@jp.freebsd.org>
 > To: FreeBSD-gnats-submit@FreeBSD.ORG
 > Cc:  
 > Subject: Re: bin/32318: no userland tool available to test resolver
 >  facilities
 > Date: Tue, 27 Nov 2001 11:11:10 +0900
 > 
 >  Anyway how about putting this tool as a port?  It would be helpful for
 >  other users.
 >  
 >  anarcat> However, no tool is available to query the resolver (in the
 >  anarcat> sense of gethostbyname/addr() routines)
 >  anarcat> transparently. Host(1), dig(1), nslookup(1) all use the name
 >  anarcat> servers, and not the /etc/hosts files or NIS/YP.
 >  
 >  But only host(1) and its friend does check only DNS, these are the
 >  exceptions.  You can use other networking tools such as ping(8),
 >  telnet(1), and more (I don't know which tool fits for you).
 >  
 >  anarcat> Try to do a address to hostname lookup using a command line
 >  anarcat> tool for an address in /etc/hosts that will actually use
 >  anarcat> gethostbyname(3).
 >  
 >  It would be better that you use getaddrinfo(3) instead.  This tool
 >  only works with IPv4 address but FreeBSD knows what IPv6 is.
 
 For the record, 'cd /usr/ports && make search key=resolv' lists, among
 others, the net/ghtool and the net/geta ports.  I know that ghtool does
 not do IPv6, but the geta description seems to imply that it does.
 
 G'luck,
 Peter
 
 -- 
 This sentence would be seven words long if it were six words shorter.

From: Makoto Matsushita <matusita@jp.freebsd.org>
To: roam@ringlet.net
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/32318: no userland tool available to test resolver
 facilities
Date: Wed, 28 Nov 2001 02:18:23 +0900

 roam> For the record, 'cd /usr/ports && make search key=resolv' lists, among
 roam> others, the net/ghtool and the net/geta ports.  I know that ghtool does
 roam> not do IPv6, but the geta description seems to imply that it does.
 
 I've installed geta and found that it works pretty well.
 
 galtvalion % cat /etc/nsswitch.conf
 hosts: files dns
 galtvalion % grep www.FreeBSD.org /etc/hosts
 127.0.0.3               www.FreeBSD.org
 galtvalion % cat /etc/nsswitch.conf
 hosts: files dns
 galtvalion % geta www.FreeBSD.org
 127.0.0.3
 
 Great :-)
 
 -- -
 Makoto `MAR' Matsushita

From: "Crist J. Clark" <cristjc@earthlink.net>
To: Peter Pentchev <roam@ringlet.net>
Cc: bug-followup@freebsd.org,
	Makoto Matsushita <matusita@jp.freebsd.org>
Subject: Re: bin/32318: no userland tool available to test resolver facilities
Date: Fri, 30 Nov 2001 03:51:56 -0800

 Are the existing ports that serve this function enough for you, Peter?
 Would you like to close up the PR?
 -- 
 Crist J. Clark                     |     cjclark@alum.mit.edu
                                    |     cjclark@jhu.edu
 http://people.freebsd.org/~cjc/    |     cjc@freebsd.org

From: Peter Pentchev <roam@ringlet.net>
To: cjclark@alum.mit.edu
Cc: bug-followup@freebsd.org,
	Makoto Matsushita <matusita@jp.freebsd.org>
Subject: Re: bin/32318: no userland tool available to test resolver facilities
Date: Fri, 30 Nov 2001 14:03:44 +0200

 On Fri, Nov 30, 2001 at 03:51:56AM -0800, Crist J. Clark wrote:
 > Are the existing ports that serve this function enough for you, Peter?
 > Would you like to close up the PR?
 
 I think net/geta works fine.  Closing this PR would be fine by me;
 what does the submitter - the Anarcat - think about it, though? :)
 
 G'luck,
 Peter
 
 -- 
 If wishes were fishes, the antecedent of this conditional would be true.

From: "Crist J. Clark" <cristjc@earthlink.net>
To: The Anarcat <anarcat@anarcat.dyndns.org>
Cc: Peter Pentchev <roam@ringlet.net>, bug-followup@freebsd.org
Subject: Re: bin/32318: no userland tool available to test resolver facilities
Date: Fri, 30 Nov 2001 04:09:02 -0800

 On Fri, Nov 30, 2001 at 04:00:02AM -0800, Crist J. Clark wrote:
 > The following reply was made to PR bin/32318; it has been noted by GNATS.
 > 
 > From: "Crist J. Clark" <cristjc@earthlink.net>
 > To: Peter Pentchev <roam@ringlet.net>
 > Cc: bug-followup@freebsd.org,
 > 	Makoto Matsushita <matusita@jp.freebsd.org>
 > Subject: Re: bin/32318: no userland tool available to test resolver facilities
 > Date: Fri, 30 Nov 2001 03:51:56 -0800
 > 
 >  Are the existing ports that serve this function enough for you, Peter?
 >  Would you like to close up the PR?
 
 Err... I mean The Anarcat, not Peter.
 -- 
 Crist J. Clark                     |     cjclark@alum.mit.edu
                                    |     cjclark@jhu.edu
 http://people.freebsd.org/~cjc/    |     cjc@freebsd.org

From: The Anarcat <anarcat@anarcat.dyndns.org>
To: cjclark@alum.mit.edu
Cc: Peter Pentchev <roam@ringlet.net>, bug-followup@freebsd.org
Subject: Re: bin/32318: no userland tool available to test resolver facilities
Date: Fri, 30 Nov 2001 07:35:30 -0500

 "Crist J. Clark" wrote:
 > 
 > On Fri, Nov 30, 2001 at 04:00:02AM -0800, Crist J. Clark wrote:
 > > The following reply was made to PR bin/32318; it has been noted by GNATS.
 > >
 > > From: "Crist J. Clark" <cristjc@earthlink.net>
 > > To: Peter Pentchev <roam@ringlet.net>
 > > Cc: bug-followup@freebsd.org,
 > >       Makoto Matsushita <matusita@jp.freebsd.org>
 > > Subject: Re: bin/32318: no userland tool available to test resolver facilities
 > > Date: Fri, 30 Nov 2001 03:51:56 -0800
 > >
 > >  Are the existing ports that serve this function enough for you, Peter?
 > >  Would you like to close up the PR?
 > 
 > Err... I mean The Anarcat, not Peter.
 > --
 > Crist J. Clark                     |     cjclark@alum.mit.edu
 >                                    |     cjclark@jhu.edu
 > http://people.freebsd.org/~cjc/    |     cjc@freebsd.org
 
 
 No. I don't think I have been clear enough. Ping(1) and friends are good
 to test one *part* of the functionality: classic address resolution. But
 they do not help in testing reverse address resolution, from what I can
 tell from net/geta/pkg-descr...
 
 I haven't tested geta, though. Give me time and I will.
 
 A.

From: Peter Pentchev <roam@ringlet.net>
To: The Anarcat <anarcat@anarcat.dyndns.org>
Cc: cjclark@alum.mit.edu, bug-followup@freebsd.org
Subject: Re: bin/32318: no userland tool available to test resolver facilities
Date: Fri, 30 Nov 2001 14:54:25 +0200

 On Fri, Nov 30, 2001 at 07:35:30AM -0500, The Anarcat wrote:
 > "Crist J. Clark" wrote:
 > > 
 > > On Fri, Nov 30, 2001 at 04:00:02AM -0800, Crist J. Clark wrote:
 > > > The following reply was made to PR bin/32318; it has been noted by GNATS.
 > > >
 > > > From: "Crist J. Clark" <cristjc@earthlink.net>
 > > > To: Peter Pentchev <roam@ringlet.net>
 > > > Cc: bug-followup@freebsd.org,
 > > >       Makoto Matsushita <matusita@jp.freebsd.org>
 > > > Subject: Re: bin/32318: no userland tool available to test resolver facilities
 > > > Date: Fri, 30 Nov 2001 03:51:56 -0800
 > > >
 > > >  Are the existing ports that serve this function enough for you, Peter?
 > > >  Would you like to close up the PR?
 > > 
 > > Err... I mean The Anarcat, not Peter.
 > > --
 > > Crist J. Clark                     |     cjclark@alum.mit.edu
 > >                                    |     cjclark@jhu.edu
 > > http://people.freebsd.org/~cjc/    |     cjc@freebsd.org
 > 
 > 
 > No. I don't think I have been clear enough. Ping(1) and friends are good
 > to test one *part* of the functionality: classic address resolution. But
 > they do not help in testing reverse address resolution, from what I can
 > tell from net/geta/pkg-descr...
 > 
 > I haven't tested geta, though. Give me time and I will.
 
 It works, though.
 
 [root@straylight:v0 ~]# fgrep 1.2.3.4 /etc/hosts
 1.2.3.4                 geta.test.nonexist
 [root@straylight:v0 ~]# geta geta.test.nonexist
 1.2.3.4
 [root@straylight:v0 ~]# geta -r 1.2.3.4
 1.2.3.4
 Reverse map:   geta.test.nonexist
 [root@straylight:v0 ~]#
 
 And no, I do not have either 'nonexist' or '4.in-addr.arpa'
 in any DNS map :)
 
 G'luck,
 Peter
 
 -- 
 Hey, out there - is it *you* reading me, or is it someone else?

From: The Anarcat <anarcat@anarcat.dyndns.org>
To: Peter Pentchev <roam@ringlet.net>
Cc: cjclark@alum.mit.edu, bug-followup@freebsd.org
Subject: Re: bin/32318: no userland tool available to test resolver facilities
Date: Sat, 1 Dec 2001 14:47:24 -0500

 --l76fUT7nc3MelDdI
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Fri Nov 30, 2001 at 02:54:25PM +0200, Peter Pentchev wrote:
 > On Fri, Nov 30, 2001 at 07:35:30AM -0500, The Anarcat wrote:
 > > "Crist J. Clark" wrote:
 > > >=20
 > > > On Fri, Nov 30, 2001 at 04:00:02AM -0800, Crist J. Clark wrote:
 > > > > The following reply was made to PR bin/32318; it has been noted by =
 GNATS.
 > > > >
 > > > > From: "Crist J. Clark" <cristjc@earthlink.net>
 > > > > To: Peter Pentchev <roam@ringlet.net>
 > > > > Cc: bug-followup@freebsd.org,
 > > > >       Makoto Matsushita <matusita@jp.freebsd.org>
 > > > > Subject: Re: bin/32318: no userland tool available to test resolver=
  facilities
 > > > > Date: Fri, 30 Nov 2001 03:51:56 -0800
 > > > >
 > > > >  Are the existing ports that serve this function enough for you, Pe=
 ter?
 > > > >  Would you like to close up the PR?
 > > >=20
 > > > Err... I mean The Anarcat, not Peter.
 > > > --
 > > > Crist J. Clark                     |     cjclark@alum.mit.edu
 > > >                                    |     cjclark@jhu.edu
 > > > http://people.freebsd.org/~cjc/    |     cjc@freebsd.org
 > >=20
 > >=20
 > > No. I don't think I have been clear enough. Ping(1) and friends are good
 > > to test one *part* of the functionality: classic address resolution. But
 > > they do not help in testing reverse address resolution, from what I can
 > > tell from net/geta/pkg-descr...
 > >=20
 > > I haven't tested geta, though. Give me time and I will.
 >=20
 > It works, though.
 >=20
 > [root@straylight:v0 ~]# fgrep 1.2.3.4 /etc/hosts
 > 1.2.3.4                 geta.test.nonexist
 > [root@straylight:v0 ~]# geta geta.test.nonexist
 > 1.2.3.4
 > [root@straylight:v0 ~]# geta -r 1.2.3.4
 > 1.2.3.4
 > Reverse map:   geta.test.nonexist
 > [root@straylight:v0 ~]#
 
 Darn.. I should have tested it. :)
 
 It would be nice of having such a tool in the base system, not in the
 ports.
 
 But I guess I won't win this one and I guess that "this pr can be
 closed" then. :)
 
 thanks.
 
 a.
 
 --l76fUT7nc3MelDdI
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.6 (FreeBSD)
 Comment: For info see http://www.gnupg.org
 
 iEYEARECAAYFAjwJM8sACgkQttcWHAnWiGdvnwCdHo1+/HeNuquwLsKD5igBrgrH
 g+kAmgLcpKoOpTuAtNWw3qNkObH9RCMp
 =5xSZ
 -----END PGP SIGNATURE-----
 
 --l76fUT7nc3MelDdI--
State-Changed-From-To: open->closed 
State-Changed-By: cjc 
State-Changed-When: Mon Aug 26 11:25:30 PDT 2002 
State-Changed-Why:  
There seem to be plenty of tools available for this with respect to 
the demand. Since this topic hasn't come up again for a while, close 
this up. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=32318 
>Unformatted:
