tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: getaddrinfo(3) on numerical addresses
At Tue, 24 Oct 2017 20:56:49 +0200,
Edgar Fuß <ef%math.uni-bonn.de@localhost> wrote:
> > So, especially for a portable application, I would say it should be
> > handled at the application level: as already pointed out, setting
> > AI_NUMERICHOST should prevent the unintended name resolution in the
> > above example (I confirmed it with my test code). I believe that will
> > work for almost all variants of getaddrinfo() implementations that
> > way, whatever policy its developer has on what should happen for
> > 1.2.3.4 with AF_INET6 but not AI_NUMERICHOST.
> I guess that setting AI_NUMERICHOST will make getaddrinfo() fail if the argument is non-numeric.
> So if the desired application behaviour (i.e. what I consider useful in the case of check_ping) is:
> 1. If it's parsable as a numeric IPv4 address, treat it as v4, no DNS lookup
> 2. If it's parsable as a numeric IPv6 address, treat it as v6, no DNS lookup
> 3. Else, do a DNS lookup (where one can argue what to do if the name has both
> A and AAAA records)
> then no single invocation of getaddrinfo() will do, right?
If you specify AF_UNSPEC for hints.ai_family and not AI_NUMERICHOST
for ai_flags, it should work that way for BSD-variants' implementation
of getaddrinfo(). Try it with my test code just by commenting out
this line:
hints.ai_family = AF_INET6;
--
JINMEI, Tatuya
Home |
Main Index |
Thread Index |
Old Index