This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gethostbyname2_r buggy?


Recently I've been tracking the reason why nscd has failed on some
type of hosts and discovered that it was caused by failure of
gethostbyname2_r() (called from addhstbyname() in nscd/hstcache.c).
This function fails returning -1 when resolved host is a recursive
CNAME, e.g:

[root@ns1 named]# host test1
test1.ceti.com.pl is a nickname for test2.ceti.com.pl
test2.ceti.com.pl is a nickname for test3.ceti.com.pl
test3.ceti.com.pl has address 195.116.211.2

I'm attaching sample program which I've used to test various hosts.
The above hostname is present in DNS, so you can check yourself.
I'd try to find the bug myself but the multiple recursive references
and #defines in the getXXbyYY_r functions scared me a bit :) If you
give me a clue where the actual resolving code is, I could make some
progress.

-- 
Pawel Krawczyk, CETI internet, Krakow. http://ceti.pl/~kravietz/
#include <assert.h>
#include <errno.h>
#include <error.h>
#include <netdb.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <arpa/inet.h>

#include "dbg_log.h"

/* Get implementation for some internal functions.  */
#include "../resolv/mapv4v6addr.h"



void main(void)
{
  /* Search for the entry matching the key.  Please note that we don't
     look again in the table whether the dataset is now available.  We
     simply insert it.  It does not matter if it is in there twice.  The
     pruning function only will look at the timestamp.  */
  int buflen = 256;
  char *buffer;
  struct hostent resultbuf;
  struct hostent *hst;
  int ret = 0;
  char key[]="test1.ceti.com.pl";

	do
    {
      errno = 0;
      buflen += 256;
      buffer = alloca (buflen);
	  ret = gethostbyname2_r (key, AF_INET, &resultbuf, buffer, buflen,
					  &hst, &h_errno);
    } while (ret != 0 && h_errno == NETDB_INTERNAL && errno == ERANGE);

}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]