From 7529e2b39eedd48c31a061d0e03e7b8d5c851199 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 9 Mar 2017 14:57:03 +1100 Subject: [PATCH 1/2] On linux if this is not the first connect() call for a udp socket, connect(AF_UNSPEC) first --- src/dns.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/dns.c b/src/dns.c index 15ff335..b74da01 100644 --- a/src/dns.c +++ b/src/dns.c @@ -6596,6 +6596,11 @@ int dns_so_check(struct dns_socket *so) { case DNS_SO_UDP_INIT: so->state++; case DNS_SO_UDP_CONN: +#if __linux + /* work-around for https://github.com/wahern/dns/issues/19 */ + if (so->stat.udp.sent.count) + connect(so->udp, &(struct sockaddr){.sa_family = AF_UNSPEC}, sizeof(struct sockaddr)); +#endif if (0 != connect(so->udp, (struct sockaddr *)&so->remote, dns_sa_len(&so->remote))) goto soerr; From d7f703257dfedaa438b44e056dcad0a153030889 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 9 Mar 2017 15:41:43 +1100 Subject: [PATCH 2/2] If there are socket errors then proceed to next nameserver --- src/dns.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dns.c b/src/dns.c index b74da01..3f91897 100644 --- a/src/dns.c +++ b/src/dns.c @@ -7542,8 +7542,11 @@ static int dns_res_exec(struct dns_resolver *R) { if (dns_so_elapsed(&R->so) >= dns_resconf_timeout(R->resconf)) dgoto(R->sp, DNS_R_FOREACH_A); - if ((error = dns_so_check(&R->so))) + error = dns_so_check(&R->so); + if (error == EAGAIN) goto error; + if (error) + dgoto(R->sp, DNS_R_FOREACH_A); if (!dns_p_setptr(&F->answer, dns_so_fetch(&R->so, &error))) goto error;