develooper Front page | perl.perl5.porters | Postings from August 2019

From:
James E Keenan via RT
Date:
August 22, 2019 01:07
Subject:

Message ID:
rt-4.0.24-5909-1566436004-1286.134379-15-0@perl.org
On Wed, 21 Aug 2019 15:45:37 GMT, laurence.rochfort@oracle.com wrote:
> This is a bug report for perl from laurence.rochfort@oracle.com,
> generated with the help of perlbug 1.39 running under perl 5.16.3.
> 
> The function Net∷Domain∷hostfqdn() provides different results from
> hostname -f
> 
> Obvervations:
> 
> 1) It doesn't respect hosts/DNS resolution ordering in nsswitch.conf
> and resolv.conf
> 2) Whether there's a shortname or FQDN in /etc/hostname alters the
> result
> 3) It looks to behave as if it assumes FQDNs should end in ".com" and
> will append .com if the hostname doesn't end with .com
>  4) It uses the search directive in /etc/resolv.conf as if it were a
> domain directive
> 5) It sometimes returns the shortname
> 
> 
> Example:
> 
> $ cat /etc/hostname
> spacewalk-27
> 
> $ cat /etc/hosts
> 127.0.0.1   spacewalk-27 spacewalk-27.vagrant.test
> 127.0.0.1   localhost localhost.localdomain localhost4
> localhost4.localdomain4
> ::1         localhost localhost.localdomain localhost6
> localhost6.localdomain6
> 
> x.x.x.x     spacewalk-27 spacewalk-27.vagrant.test
> 
> $ cat /etc/resolv.conf
> ; generated by /usr/sbin/dhclient-script
> search uk.oracle.com vagrant.test
> nameserver x.x.x.x
> 
> $ grep hosts /etc/nsswitch.conf
> #hosts:     db files nisplus nis dns
> hosts:      files dns myhostname
> 
> $ hostname -f
> spacewalk-27.vagrant.test
> 
> $ perl -le 'use Socket; use POSIX; print
> ((gethostbyname((POSIX::uname)[1]))[0])'
> spacewalk-27.vagrant.test
> 
> $ perl -le 'use Net::Domain (); print Net::Domain::hostfqdn'
> spacewalk-27.vagrant.test.com
> 
> 
> 
> 
> For reference:
> 
> man 1 hostname:
> "
>        The  function  gethostname(2)  is used to get the
>        hostname.  When the hostname -a, -d, -f or -i  is
>        called will gethostbyname(3) be called.  The dif‐
>        ference in gethostname(2) and gethostbyname(3) is
>        that  gethostbyname(3)  is  network  aware, so it
>        consults /etc/nsswitch.conf and /etc/host.conf to
>        decide  whether to read information in /etc/host‐
>        name or /etc/hosts
> 
> The recommended method of setting the FQDN is  to
> make the hostname be an alias for the fully qual‐
> ified name using /etc/hosts,  DNS,  or  NIS.  For
> example,  if the hostname was "ursula", one might
> have a line in /etc/hosts which reads
> 
> 127.0.1.1    ursula.example.com ursula
> 
> Technically: The FQDN is the name  getaddrinfo(3)
> returns  for  the  host name returned by gethost‐
> name(2).  The DNS domain name is the  part  after
> the first dot.
> 
> Therefore  it depends on the configuration of the
> resolver (usually in /etc/host.conf) how you  can
> change  it.  Usually  the  hosts  file  is parsed
> before DNS or NIS, so it is most common to change
> the FQDN in /etc/hosts.
> "
> 
> man 5 resolv.conf:
> "
>        domain Local domain name.
>               Most  queries  for names within this domain
>               can use short names relative to  the  local
>               domain.   If set to '.', the root domain is
>               considered.  If no domain entry is present,
>               the  domain  is  determined  from the local
>               hostname returned  by  gethostname(2);  the
>               domain part is taken to be everything after
>               the first '.'.  Finally,  if  the  hostname
>               does  not  contain  a domain part, the root
>               domain is assumed.
> 
> search Search list for host-name lookup.
> "

Thank you for this report.  Net::Domain is part of the libnet distribution which, while it is shipped with the Perl 5 core distribution, is maintained upstream on CPAN.

Could you please file this report in libnet's issue tracker by sending email to:

bug-libnet@rt.cpan.org

Thank you very much.
-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=134379



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About