[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: WARNING : libc6 Version: 2.0.7t-1 breaks resolv routines



Michael Stone wrote:
> 
> That is the correct behavior. The host program only queries DNS servers;
> it does not consult the local host table. You can try pinging a hostname
> in the host table to see if it resolves.
> 

Well let's try to close this issue once for all to everybody's relief.

First of all I would like to apologize for having flooded the group with
something
that appears to be a non problem to most of us.

The doubt has arisen since contrary to what the man page and your append
states,
host has a mixed behaviour which IMHO is not very clean.

If you do a "strace 127.0.0.1" you will see that the host command
command used in this way WILL take a look to your /etc/nsswitch.conf
file and if the latter has a hosts: files,dns line in it, will open your
/etc/hosts file, read from it and retrieve the corresponding name
WITHOUT EVER going to a DNS (can check also with IPTRAF or TCPDUMP if
you are an overly suspicious character 8->).

Conversely if you do a "strace localhost" with the same situation host
will totally ignore /etc/nsswitch and as you and the man page state,
attempt a DNS query.

This mixed behavior of the host command I discovered makes it an
unreliable debugging to tool.

If I need to debug DNS I will ONLY use dig or nslookup from now on.

If I want to exercise the way my system uses the gethostby*() routines
(which are
used by many programs), I have compiled a program built for that by a
friend of mine (address.c) which will behave CORRECTLY according to what
the /etc/nsswitch says ... 

This is the behavior I would have expected from "host" ...

Case closed.

Thank you to everyone for getting me to understand Unix a bit better 8->

PS The reason for which I like Unix against non-oss like Win95/WinNT is
that
   with sufficient knowledge and sweat you can always understand why
Unix
   behaves in a certain way .. I hate non deterministic looking OSs ...

PPS I cannot check now but I would bet  fiver that AIX host commands
behaves
    like I think it should ...

---
Robert J. Alexander <rja@raleigh.ibm.com>
AIX Certified System Administrator - Debian Linux addict - Win.\* victim
Via Sciangai, 53 - 00144 Rome, Italy
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <sys/types.h>
#include <unistd.h>

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

/*
  Simple little program to exercise name resolution via gethostby*()
  routines.

  Usage:
     addressof hostname|ipaddress

  schales, August 1998 - IBM

  used as a better "host" command. Will honour /etc/nsswitch.conf
  and read from /etc/hosts when needed.

*/

static int resolve(char *);

int
main(int argc, char **argv)
{
     int rc, i;

     rc = EXIT_SUCCESS;

     if(argc != 1){
	  for(i=1;i<argc;i++){
	       if(resolve(argv[i]) != 0)
		    rc = EXIT_FAILURE;
	  }
     }
     else {
	  fprintf(stderr, "Usage: %s hostspec [hostspec [hostspec...]]\n",
		  argv[0]);
	  fputs("\n\twhere `hostspec' is either a hostname or an IPv4 address.\n\n",
		stderr);
     }

     return rc;
}

static int
resolve(char *hostspec)
{
     struct hostent *he;
     unsigned long addr;
     int i;

     if((addr = inet_addr(hostspec)) != (unsigned long)-1)
	  he = gethostbyaddr((char *)&addr, 4, AF_INET);
     else
	  he = gethostbyname(hostspec);

     if(!he){
	  printf("%s: No information.\n", hostspec);
	  return -1;
     }

     printf("Name: %s\n", he->h_name);

     if(he->h_aliases[0]){
	  if(he->h_addr_list[1]){
	       puts("Aliases:");
	       for(i=0;he->h_aliases[i];i++)
		    printf("\t%s\n", he->h_aliases[i]);
	  }
	  else {
	       printf("Alias: %s\n", he->h_aliases[0]);
	  }
     }

     if(he->h_addr_list[0]){
	  struct in_addr ia;
	  if(he->h_addr_list[1]){
	       puts("Addresses:");
	       for(i=0;he->h_addr_list[i];i++){
		    memcpy((void *)&ia.s_addr, he->h_addr_list[i], 4);
		    printf("\t%s\n", inet_ntoa(ia));
	       }
	  }
	  else {
	       memcpy((void *)&ia.s_addr, he->h_addr_list[0], 4);
	       printf("Address: %s\n", inet_ntoa(ia));
	  }
     }
     else {
	  puts("No address records found.");
     }

     return 0;
}

Reply to: