Hi,

On 09/07/2015 10:47 AM, Baptiste wrote:
>> It fails that way:
>>
>> socket(PF_INET,SOCK_DGRAM,17)                    = (0x4)
>> connect(4,{ AF_INET 8.8.8.8:53 },128)            ERR#22 'Invalid argument'
>>
>> 3rd argument for connect() looks wrong for ipv4:
>>
>> ERRORS
>>      The connect() system call fails if:
>>
>>      [EINVAL]           The namelen argument is not a valid length for the
>>                         address family.
>>
>>
> 
> Ok, excellent.
> I wonder how this could happen :)

It looks like this code is passing the size of a struct
sockaddr_storage to connect(), instead of the size corresponding to the
underlying socket family. Some OS are forgiving, other not so much :)

diff --git a/src/dns.c b/src/dns.c
index 4bc5448..f725ff4 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -819,7 +819,7 @@ int dns_init_resolvers(void)
                        }

                        /* "connect" the UDP socket to the name server IP */
-                       if (connect(fd, (struct
sockaddr*)&curnameserver->addr, sizeof(curnameserver->addr)) == -1) {
+                       if (connect(fd, (struct
sockaddr*)&curnameserver->addr, get_addr_len(&curnameserver->addr)) == -1) {
                                Alert("Starting [%s/%s] nameserver:
can't connect socket.\n", curr_resolvers->id,
                                                curnameserver->id);
                                close(fd);



Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to