Re: LibPQ doesn't say host=* translates to localhost

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, PostgreSQL Bug List <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: LibPQ doesn't say host=* translates to localhost
Date: 2024-06-30 09:52:59
Message-ID: CA+bJJby53rMtH_4EQeKxXuedFedTgHQSH64+ik=_mCuai9J5mA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, 28 Jun 2024 at 18:56, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> > ping '*'
> > ping: *: Name or service not known
> > This is Ubuntu.
> Yeah, I see the same on a couple different Red Hat versions. Very
> interesting, since it implies that ping is using something other than
> getaddrinfo(3) to resolve the hostname. I'm not quite interested
> enough to go find out what, though.

Same in Debian, as expected.

But it picked my curiosity, so I did an ltrace:

$ sudo ltrace ping '*' |& fgrep addrinfo
getaddrinfo("*", nil, 0x7ffde84578c0, 0x7ffde84578a8) = -2

And did this little perl experiment....
>>> addrinfo.pl
use strict;
use Socket qw(:addrinfo);

sub U($) { $_[0] // 'undef'; }
sub M($) {
my $h = shift;
join ';', map { "$_=>".U($h->{$_}) } sort keys %$h;
}

sub pai {
my ($host, $service, $hints)=(at)_;
printf "gai(%s,%s,{%s})\n",
$host, U $service, M $hints;
my ($err, @addr) = getaddrinfo($host, $service, $hints);
printf " err=%s\n", $err//'UNDEF';
while(my ($i, $v)=each @addr) {
printf " a[%d]={%s},addr=%s\n",
$i, M $v,
unpack("h*",$v->{addr});
}
}

pai('*',undef,{});
pai('*',undef,{family=>Socket::AF_INET});
pai('*',5432, {family=>Socket::AF_INET});
<<<
Which gives:
>>>
$ perl -w addrinfo.pl
gai(*,undef,{})
err=Name or service not known
gai(*,undef,{family=>2})
err=Name or service not known
gai(*,5432,{family=>2})
err=
a[0]={addr=>8;canonname=>undef;family=>2;protocol=>6;socktype=>1},addr=20005183f70000100000000000000000
a[1]={addr=>8;canonname=>undef;family=>2;protocol=>17;socktype=>2},addr=20005183f70000100000000000000000
a[2]={addr=>8;canonname=>undef;family=>2;protocol=>0;socktype=>3},addr=20005183f70000100000000000000000
<<<
I am not sure how to follow, or if perl uses glibc, and have to go
AFK, and I am not sure if it relates, but getaddrinfo may be doing
strange things.

Francisco Olarte.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message David Rowley 2024-07-01 00:12:48 Re: BUG #18484: "Cannot enlarge string buffer" during parallel execution of prepared statement/partitioning
Previous Message Laurenz Albe 2024-06-29 19:10:33 Re: BUG #18500: Detaching a partition with an index manually attached to the parent's index triggers Assert