Subject: Re: getaddrinfo - too many recvmsg calls

From: Eric Dumazet <[email-masked]>
Date: Mon, 20 Jul 2009 09:55:20 +0200

Rémi Denis-Courmont a écrit :
> On Monday 20 July 2009 10:05:56 ext Zsolt SZALAI wrote:
>> The sanitycheck is now really simple, just a
>>     addrinfo hints = { 0, AF_INET, 0, 0, 0, NULL, NULL, NULL };
>>     int result = getaddrinfo(ipAddress, NULL, &hints, &addresses);
>> call.
> 
> What the heck is this supposed to do?
> This piece of code tries to resolve <ipAddress> as numerical IPv4 address *or* 
> a DNS hostname.
> 
> If you want to check that a string is a valid IP address, call inet_pton(). If 
> you want to check that an IP address is assigned to the system, create a 
> socket and bind to that address.
> 

Yes, but beware of ip_nonlocal_bind option (/proc/sys/net/ipv4/ip_nonlocal_bind).

If set to one, bind() will not tell you if address is assigned to the system.