getaddrinfo(): when providing hints, make sure we use addrconfig/v4mapped.

if no hints were specified, getaddrinfo() will assume ai_flags as
AI_ADDRCONFIG | AI_V4MAPPED, which only reports useful results based
on what system supports. For instance AI_ADDRCONFIG will only return
IPv4 if IPv4 address exists, likewise IPv6 will only be returned if
IPv6 address is configured, avoiding these to be tried and error for
most local networks where such address could not be used. AI_V4MAPPED
will map IPv4 address over IPv6 if no IPv4 was found.
This commit is contained in:
Gustavo Sverzut Barbieri 2016-10-22 09:41:26 -02:00
parent 71efc8ee9d
commit 9ab8f6636a
3 changed files with 7 additions and 0 deletions

View File

@ -3546,6 +3546,7 @@ _efl_net_ip_resolve_and_connect(const char *host, const char *port, int type, in
.ai_socktype = type,
.ai_protocol = protocol,
.ai_family = AF_UNSPEC,
.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED,
};
Eina_Error ret = EFL_NET_DIALER_ERROR_COULDNT_CONNECT;
int r;
@ -3732,6 +3733,7 @@ _efl_net_ip_connect_async_run_socks4(Efl_Net_Ip_Connect_Async_Data *d, const cha
.ai_socktype = d->type,
.ai_protocol = d->protocol,
.ai_family = AF_INET,
.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED,
};
int r;
@ -3819,6 +3821,7 @@ _efl_net_ip_connect_async_run_socks4a(Efl_Net_Ip_Connect_Async_Data *d, const ch
.ai_socktype = d->type,
.ai_protocol = d->protocol,
.ai_family = AF_INET,
.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED,
};
int r;
@ -4321,6 +4324,7 @@ _efl_net_ip_connect_async_run_socks5(Efl_Net_Ip_Connect_Async_Data *d, const cha
.ai_socktype = d->type,
.ai_protocol = d->protocol,
.ai_family = AF_UNSPEC,
.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED,
};
Efl_Net_Socks5_Request_Command cmd;
int r;
@ -4466,6 +4470,7 @@ _efl_net_ip_connect_async_run_socks5h(Efl_Net_Ip_Connect_Async_Data *d, const ch
.ai_socktype = d->type,
.ai_protocol = d->protocol,
.ai_family = AF_UNSPEC,
.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED,
};
if (strchr(host, ':')) hints.ai_family = AF_INET6;

View File

@ -160,6 +160,7 @@ _efl_net_server_tcp_efl_net_server_serve(Eo *o, Efl_Net_Server_Tcp_Data *pd, con
.ai_socktype = SOCK_STREAM,
.ai_protocol = IPPROTO_TCP,
.ai_family = AF_UNSPEC,
.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED,
};
EINA_SAFETY_ON_NULL_RETURN_VAL(address, EINVAL);

View File

@ -164,6 +164,7 @@ _efl_net_server_udp_efl_net_server_serve(Eo *o, Efl_Net_Server_Udp_Data *pd, con
.ai_socktype = SOCK_DGRAM,
.ai_protocol = IPPROTO_UDP,
.ai_family = AF_UNSPEC,
.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED,
};
EINA_SAFETY_ON_NULL_RETURN_VAL(address, EINVAL);