Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Jul 2003 12:40:51 -0400
From:      Jonathan Lennox <lennox@cs.columbia.edu>
To:        sub_0@netcabo.pt
Cc:        freebsd-gnats-submit@FreeBSD.org
Subject:   Re: misc/54189: DNS resolver should resolve hostnames with underscores
Message-ID:  <16165.21011.781126.341394@grandcentral.cs.columbia.edu>
In-Reply-To: <1058576063.1430.20.camel@suzy.unbreakable.homeunix.org>
References:  <1058576063.1430.20.camel@suzy.unbreakable.homeunix.org>

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

--p4dH/IeS7Q
Content-Type: text/plain; charset=iso-8859-1
Content-Description: message body text
Content-Transfer-Encoding: quoted-printable

On , July 19 2003, "M=E1rio Freitas" wrote to "freebsd-bugs@FreeBSD.org=
, lennox@cs.columbia.edu" saying:

> The problem you submitted is due to mozilla's gethostbyname() own(bad=
)
> implementation. FreeBSD's resolver can deal with underscores in
> hostnames without any problem at all. I think you should submit that
> problem to mozilla's bug tracking system(yes I succeded resolving tha=
t
> hostname in FreeBSD 4.8 and 5.1).

Not so, at least if you go through the gethostbyname() or getaddrinfo()=

APIs.  I've attached a small program that exercises both APIs, compiled=

it on both FreeBSD 4.8-RELEASE and on Red Hat Linux 7.1, and executed b=
oth
on the same FreeBSD 4.8 machine (the Linux binary running under emulati=
on):

conrail $ ./gethostbyname dear=5Fraed.blogspot.com
dear=5Fraed.blogspot.com: gethostbyname lookup failed: Unknown server e=
rror (3)
dear=5Fraed.blogspot.com: getaddrinfo lookup failed: Non-recoverable fa=
ilure in name resolution (4)
conrail $ ./gethostbyname-linux dear=5Fraed.blogspot.com
dear=5Fraed.blogspot.com [ghbn]: 216.34.7.189=20
dear=5Fraed.blogspot.com [gai]: 216.34.7.189 216.34.7.189 216.34.7.189=20=


The FreeBSD 'nslookup' and 'host' programs, which bypass these APIs and=
 do
DNS queries directly, can indeed resolve the hostname:

conrail $ nslookup dear=5Fraed.blogspot.com
Server:  sutton.cs.columbia.edu
Address:  128.59.22.38

Non-authoritative answer:
Name:    dear=5Fraed.blogspot.com
Address:  216.34.7.189
conrail $ host dear=5Fraed.blogspot.com
dear=5Fraed.blogspot.com has address 216.34.7.189


--p4dH/IeS7Q
Content-Type: text/plain
Content-Disposition: inline;
	filename="gethostbyname.c"
Content-Transfer-Encoding: 7bit

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>

#include <stdlib.h>

#include <netdb.h>

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

  struct addrinfo hints;

  if (argc < 2) {
    fprintf(stderr, "Usage: %s hostname [...]", argv[0]);
    exit(1);
  }

  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_INET;

  for (i = 1; i < argc; i++) {
    int ret;
    struct hostent *he;
    struct addrinfo *ai;

    he = gethostbyname(argv[i]);
    if (he == NULL) {
      printf("%s: gethostbyname lookup failed: %s (%d)\n", argv[i],
             hstrerror(h_errno), h_errno);
    }
    else {
      int j;

      printf("%s [ghbn]: ", argv[i]);
      for (j = 0; he->h_addr_list[j] != NULL; j++) {
        printf("%s ", inet_ntoa(*(struct in_addr*)(he->h_addr_list[j])));
      }
      printf("\n");
    }
    
    ret = getaddrinfo(argv[i], NULL, &hints, &ai);
    if (ret != 0) {
      printf("%s: getaddrinfo lookup failed: %s (%d)\n", argv[i],
             gai_strerror(ret), ret);
    }
    else {
      struct addrinfo* this_ai;

      printf("%s [gai]: ", argv[i]);
      for (this_ai = ai; this_ai != NULL; this_ai = this_ai->ai_next) {
        printf("%s ",
               inet_ntoa(((struct sockaddr_in*)(this_ai->ai_addr))->sin_addr));
      }
      printf("\n");

      freeaddrinfo(ai);
    }

  }
  return 0;
}

--p4dH/IeS7Q
Content-Type: text/plain; charset=us-ascii
Content-Description: .signature
Content-Transfer-Encoding: 7bit


-- 
Jonathan Lennox
lennox@cs.columbia.edu

--p4dH/IeS7Q--



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