[asterisk-dev] [Code Review] Add getnameinfo() to ast_sockaddr_resolve()
Paul Belanger
pabelanger at digium.com
Tue May 3 16:04:37 CDT 2011
On 11-05-03 04:31 PM, Simon Perreault wrote:
> On 2011-05-03 16:23, Paul Belanger wrote:
>>> getaddrinfo("1050", ...) should fail.
>>
>> Yes, I believe this is the actual issue, it resolves to 0.0.4.26:5060
>
> You're right! Wow, I didn't know that this syntax was valid...
>
> Ok, now we're on the same wave length.
>
>> But as far as
>> I can tell, 1050 is _not_ a valid hostname on the OS.
>
> 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? "It converts a
socket address to a corresponding host and service, in a
protocol-independent manner." Add if we pass the NI_NAMEREQD flag, "then
an error is returned if the hostname cannot be determined".
Or am I missing something?
--
Paul Belanger
Digium, Inc. | Software Developer
twitter: pabelanger | IRC: pabelanger (Freenode)
Check us out at: http://digium.com & http://asterisk.org
More information about the asterisk-dev
mailing list