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

Simon Perreault simon.perreault at viagenie.ca
Tue May 3 17:53:48 CDT 2011


Le 03/05/2011 5:04 PM, Paul Belanger a écrit :
>> Right, it's not a valid *hostname*. But it's a valid *IP address*. You
>> see, from the point of view of getaddrinfo(), there is no difference
>> between the string "0.0.4.26" and the string "1050". Both are valid, and
>> both designate the same 32-bit IPv4 address. It is exactly as if the
>> user had written Dial(SIP/0.0.4.26) instead. So because this syntax is
>> actually valid, I don't think there is anything to fix here.
>>
>> An idea: we could apply a check (regex?) on the host name and warn if it
>> "strange", e.g. only digits.
>>
> Right, but isn't that what getnameinfo() is used for?

Not sure what you mean here...

> "It converts a
> socket address to a corresponding host and service, in a
> protocol-independent manner."

This is right. It's the reverse of getaddrinfo().

getaddrinfo(): name --> address(es)
getnameinfo(): name <-- address

Note that name can be either a host name (e.g. "example.com") or an 
address literal (e.g. "192.0.2.1", or in this case "1050").

> Add if we pass the NI_NAMEREQD flag, "then
> an error is returned if the hostname cannot be determined".

getnameinfo() first checks for a host name corresponding to the given 
address. It usually looks in the DNS for the corresponding PTR record as 
well as in /etc/hosts. If there is no corresponding name, then it will 
return an address literal, i.e. the string representation of the address.

What NI_NAMEREQD does is prevent getnameinfo() from returning an address 
literal. It returns an error if there is no corresponding name.

So if I use Dial(SIP/192.0.2.1), and there's no name associated with 
this address, I still want this to work. Having a name associated with 
an address is not a prerequisite for SIP to work.

Or am I misunderstanding your proposed fix?

Simon



More information about the asterisk-dev mailing list