Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mimsy!aplcen!aplvax!jcn From: jcn@aplvax.UUCP (John C. Noble) Newsgroups: comp.bugs.4bsd,comp.unix.wizards Subject: By any other named Message-ID: <515@aplvax.UUCP> Date: Wed, 28-Jan-87 13:58:23 EST Article-I.D.: aplvax.515 Posted: Wed Jan 28 13:58:23 1987 Date-Received: Sun, 1-Feb-87 02:54:10 EST Reply-To: jcn@aplvax.UUCP (John C. Noble) Organization: John Hopkins Applied Physics Laboratory Lines: 46 Summary: gethostname() doesn't work if named is not present Xref: mnetor comp.bugs.4bsd:167 comp.unix.wizards:802 References: We have recently installed 4.3BSD on our Vax 11/780. We are running with the gethostnamadr.c in /usr/src/lib/libc/named. However, we are not running the nameserver daemon. In that case, gethostname() should use /etc/hosts to get host names. Inspection of gethostname() in gethostnamadr.c shows that if (hp == NULL && errno == ECONNREFUSED) hp = _gethtbyname(name); (_gethtbyname() uses /etc/hosts to resolve 'name'.) The variable hp should be NULL at this point if the nameserver is not present. However, I discovered that occasionally errno is set to ETIMEDOUT rather than ECONNREFUSED. In this case, /etc/hosts is not queried, and the gethostname() call fails. The variable errno is checked when hp == NULL since if the nameserver is present, and the name is not found by the nameserver, then hp will be NULL; but in this case we do not want to query /etc/hosts. When gethostname() failed, errno was set to ETIMEDOUT at the time the code segment in question was executed. According to INTRO(2), this means "A connect or send request failed because the connected party did not properly respond after a period of time". It is interesting to note that ECONNREFUSED is described as "No connection could be made because the target machine actively refused it". It seems to me that ETIMEDOUT is a passive refusal, while ECONNREFUSED is an active refusal. So, I think the proper "fix" is: if (hp == NULL && (errno == ECONNREFUSED || errno == ETIMEDOUT)) hp = _gethtbyname(name); This handles active and passive connect refusals from the nameserver. Should it be possible to receive ETIMEDOUT errors if the nameserver is not present? Note that we were received ECONNREFUSED errors most of the time; only occasionally did we receive ETIMEDOUT errors. Comments? -- John Noble JHU/APL jcn@aplvax