misc/54189: DNS resolver should resolve hostnames with underscores

Jonathan Lennox lennox at cs.columbia.edu
Mon Jul 28 09:50:19 PDT 2003

The following reply was made to PR misc/54189; it has been noted by GNATS.

From: Jonathan Lennox <lennox at cs.columbia.edu>
To: sub_0 at netcabo.pt
Cc: freebsd-bugs at FreeBSD.org, freebsd-gnats-submit at FreeBSD.org
Subject: Re: misc/54189: DNS resolver should resolve hostnames with
Date: Mon, 28 Jul 2003 12:40:51 -0400

 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 at FreeBSD.org=
 , lennox at 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=
 > 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=
 on the same FreeBSD 4.8 machine (the Linux binary running under emulati=
 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]:
 dear=5Fraed.blogspot.com [gai]:
 The FreeBSD 'nslookup' and 'host' programs, which bypass these APIs and=
 DNS queries directly, can indeed resolve the hostname:
 conrail $ nslookup dear=5Fraed.blogspot.com
 Server:  sutton.cs.columbia.edu
 Non-authoritative answer:
 Name:    dear=5Fraed.blogspot.com
 conrail $ host dear=5Fraed.blogspot.com
 dear=5Fraed.blogspot.com has address
 Content-Type: text/plain
 Content-Disposition: inline;
 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]);
   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])));
     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));
   return 0;
 Content-Type: text/plain; charset=us-ascii
 Content-Description: .signature
 Content-Transfer-Encoding: 7bit
 Jonathan Lennox
 lennox at cs.columbia.edu

More information about the freebsd-bugs mailing list