Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 05 Aug 2023 18:19:45 +0000
From:      0x1eef <0x1eef@protonmail.com>
To:        Steven Friedrich <freebsdlouisville@gmail.com>
Cc:        freebsd@vanderzwan.org, FreeBSD Questions Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: Using /etc/hosts, not dns
Message-ID:  <RbmQ19YYo7yFyVKAsrp0-Kwfx5UG1RsmX_UNr3cVtBXHbi5xzvf0y76XTZdUCariXCea6iTS9Vy7jo9awBebnwgnYYX5wUDCqxern8INSIE=@protonmail.com>
In-Reply-To: <6c840288-0446-122d-7d97-d6b02982e27c@Gmail.com>
References:  <846f37ec-c0b3-0b1a-6294-1da6a9260777@Gmail.com> <1ED24C4A-FABF-4096-970D-4017616FC124@vanderzwan.org> <ebb7199a-98bc-980e-a077-f7a7c7085b4e@Gmail.com> <F269F458-919D-42D4-BDE4-E7A56C74BB02@vanderzwan.org> <6c840288-0446-122d-7d97-d6b02982e27c@Gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> Correct, Linux still works.  After all these years and my extensive Unix
> experience, I am abandoning FreeBSD.  You have completely abandoned
> common sense.

I thought this might be an interesting bit of information to add to the
thread.=20

On OpenBSD, /etc/resolv.conf supports a 'lookup' keyword that FreeBSD
has not implemented (AFAICT).=20

>From the man page:

     lookup      This keyword is used by the library routines gethostbyname=
(3)
                 and gethostbyaddr(3).  It specifies which databases should=
 be
                 searched, and the order to do so.  The legal space-separat=
ed
                 values are:

                       bind  Query a domain name server.
                       file  Search for entries in /etc/hosts.

                 If the lookup keyword is not used in the system's resolv.c=
onf
                 file then the assumed order is bind file.  Furthermore, if
                 the system's resolv.conf file does not exist, then the onl=
y
                 database used is file.

But the 'host' command is the same as FreeBSD, and does not consult /etc/ho=
sts.
It should still be possible to write a small C program that uses gethostbyn=
ame(3),
and that should respect the lookup order. As long as resolv.conf has=20
'lookup file bind' it would consult /etc/hosts first and then consult=20
name servers second.

I wrote a proof of concept (I'm trying to learn C, so this was a good task=
=20
for me):

#include <netdb.h>
#include <stdio.h>
#include <sys/socket.h>

#define IPv4_FORMAT "%hhu.%hhu.%hhu.%hhu"

int
main(void) {
  struct hostent *ent;
  ent =3D gethostbyname2("read.amazon.com", AF_INET);
  if (h_errno =3D=3D NETDB_SUCCESS) {
    char *addr =3D ent->h_addr_list[0];
    fprintf(stdout, IPv4_FORMAT, addr[0], addr[1], addr[2], addr[3]);
    fprintf(stdout, "\n");
  } else {
    fprintf(stderr, "error: %s", hstrerror(h_errno));
  }

  return 0;
}

0x1eef




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