Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Nov 2001 18:00:38 -0500 (EST)
From:      The Anarcat <anarcat@anarcat.dyndns.org>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/32318: no userland tool available to test resolver facilities
Message-ID:  <20011126230038.0DE1120ACB@shall.anarcat.dyndns.org>

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

>Number:         32318
>Category:       bin
>Synopsis:       no userland tool available to test resolver facilities
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 26 15:10:01 PST 2001
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:

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




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