*BSD News Article 21780


Return to BSD News archive

Xref: sserve comp.os.386bsd.development:1274 comp.os.386bsd.bugs:1532 comp.os.386bsd.questions:5565
Newsgroups: comp.os.386bsd.development,comp.os.386bsd.bugs,comp.os.386bsd.questions
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!agate!howland.reston.ans.net!pipex!sunic!uts!iesd!herring
From: herring@iesd.auc.dk (B. Erickson Herring)
Subject: I want to discuss hostname resolution (+bug report)
Message-ID: <HERRING.93Oct1095726@loke.iesd.auc.dk>
Sender: news@iesd.auc.dk (UseNet News)
Organization: Mathematics and Computer Science, Aalborg University
Date: 01 Oct 1993 08:57:25 GMT
Lines: 98

Hi *BSDers,

My NetBSD-0.9 machine is irritating me.  It refuses to resolve
`locahost' when the file /etc/resolv.conf exists.  That is, it _never_
looks in /etc/hosts unless res_search() sets `errno' to ECONNREFUSED
in gethostbyname().  This problem must have been noticed by others, as
I cannot believe that everyone has `localhost.your.domain.here' in
their nameserver.

I am going to post this in the hopes that I can find out who is "in
charge" of this portion of libc.  If noone is in charge, I will "fix"
this in libc in a pleasing and propogatable manner, and maybe even add
a feature or two (see below).

If this post _doesn't_ elicit any response, I'll mail to the
maintainers listed at the end of the INSTALL_NOTES document from
NetBSD and whoever will listen from the FreeBSD effort (the behavior
is inherited from Net-2).


Now, to name resolution --

The documentation is both very clear and very obscure on this point.
The documentation in /usr/share/doc/smm/11.named says:

	``The gethostbyname() library call can detect if named is
	running.  If it is determined that named is not running it
	will look in /etc/hosts to resolve an address.

	This option was added to allow ifconfig(8C) to configure the
	machines local interfaces and to enable a system manager to
	access the network while the system is in single user mode.
	It is advisable to put the local machines interface addresses
	and a couple of machine names and address in /etc/hosts so the
	system manager can rcp files from another machine when the
	system is in single user mode.  The format of /etc/host has
	not changed. See hosts(5) for more information.''

which is very clear.  /etc/hosts is always consulted if named is not
running on the local machine.  But then, suddenly, the author(s) begin
talking about options in the sense of "you can disable this at compile
time/runtime":

	Since the process of reading /etc/hosts is slow, it is not
	advised to use this option when the system is in multi user
	mode.

which is extremely unclear, since there does not seem to be such an
option.

Name resolution policy is set in gethostbyname.  I include a snippet
from gethostbyname() in /usr/src/lib/libc/net/gethostnamadr.c (C++
style comments are mine):

	/*
	 * disallow names consisting only of digits/dots, unless
	 * they end in a dot.
	 */
	if (isdigit(name[0]))
// fake up a hostent with the numeric address and return it
          .
          .
          .
// else, query your DNS
	if ((n = res_search(name, C_IN, T_A, buf.buf, sizeof(buf))) < 0) {
// if DNS is not running or refuses to answer, look in /etc/hosts
// note that this is an error condition and has nothing to do with
// whether your DNS can find/resolve said name
		if (errno == ECONNREFUSED)
			return (_gethtbyname(name));
		else
// else, HOST NOT FOUND.  Bummer.


So, short of editing the source and recompiling, there is no way to
alter this behavior.  Ergo, the docs (11.named) are wrong/vague/not
complete or this is a bug.

I vote for the latter.

What _I_ want is to be able to implement resolution policy myself,
dynamically, much as one can with sysv (ooh, no, not the
at&t...err...novell word!!!) -- there is a file which specifies which
services to consult for resolution information.  That way, I can tell
my machine to first ask the DNS, then look in /etc/hosts, and finally
ask YP.  Or whatever.

Whaddaya'll think?

Erick

--
-----
Erick Herring           |  Computation is the art of carefully throwing
H Data, Aalborg         |  away information [and] Life is the art of
UNIX Consulting         |  carefully throwing away opportunities, an 
SysAdmin & Programming  |  interesting coincidental parallel.
herring@iesd.auc.dk     |  - Guy L. Steele Jr.