[asterisk-dev] [Code Review] Add getnameinfo() to ast_sockaddr_resolve ()

Tilghman Lesher tilghman at meg.abyt.es
Thu May 5 12:51:33 CDT 2011


On Thursday 05 May 2011 11:56:15 Simon Perreault wrote:
> On 2011-05-05 12:25, Tilghman Lesher wrote:
> > On Wednesday 04 May 2011 08:12:50 Simon Perreault wrote:
> >> I don't think it is useful to disambiguate between an IP address and
> >> a host name.
> > 
> > If you don't, then this entire thread is moot.  We have to be able to
> > disambiguate between those two, because some peer names can be
> > confused with IP addresses (in a nonstandard format), but host names
> > should be distinct from IP addresses.
> 
> - It is not useful to disambiguate between a host name and an IP
> address. Why: Because their grammars allow us to distinguish them. That
> is what getaddrinfo() does internally.

That's not true, though.  Some IP addresses in non-dotted format can be 
confused with hostnames.  That's the problem, and it's what you're failing
to address.  On another note, I have no idea why non-dotted formats are
allowed to be IP addresses, but it's legacy, so we have to deal with it.

> > Consider that "1" should be
> > evaluated first as a possible peer name, secondly as a hostname, and
> > only finally as an IP address (because this third possibility will
> > always return a positive result).
> 
> I think this order is wrong. It should be
> 
> 1. peer name
> 2. IP address
> 3. host name
> 
> Otherwise you will end up querying the DNS for IP address literals. That
> would be very wrong.

But IP addresses in non-dotted format will NEVER fail.  That is very wrong, 
as well.

> Now, it turns out that getaddrinfo() does 2 and 3, in that order. So we
> just need to do, in pseudocode:

That's exactly the problem.  If you give it an all-numeric input, then it
will resolve to an IPv4 address.  We need to specify extra grammar to
ensure that cannot happen.

-- 
Tilghman



More information about the asterisk-dev mailing list