Skip to content

Commit

Permalink
netdb/dns: fix dns wrong response ID error
Browse files Browse the repository at this point in the history
In every dns query, we use the new socket to avoid receiving last response ID

Signed-off-by: wangchen <wangchen41@xiaomi.com>
  • Loading branch information
wangchen61698 authored and xiaoxiang781216 committed Jun 14, 2023
1 parent 9b5746c commit 693898d
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions libs/libc/netdb/lib_dnsquery.c
Expand Up @@ -586,13 +586,7 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
int next = 0;
int retries;
int ret;

int sd = dns_bind(addr->sa_family);
if (sd < 0)
{
query->result = sd;
return 0;
}
int sd;

/* Loop while receive timeout errors occur and there are remaining
* retries.
Expand All @@ -603,6 +597,13 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
#ifdef CONFIG_NET_IPv6
/* Send the IPv6 query */

sd = dns_bind(addr->sa_family);
if (sd < 0)
{
query->result = sd;
return 0;
}

ret = dns_send_query(sd, query->hostname,
(FAR union dns_addr_u *)addr,
DNS_RECTYPE_AAAA, &qinfo);
Expand All @@ -627,11 +628,20 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
query->result = ret;
}
}

close(sd);
#endif

#ifdef CONFIG_NET_IPv4
/* Send the IPv4 query */

sd = dns_bind(addr->sa_family);
if (sd < 0)
{
query->result = sd;
return 0;
}

ret = dns_send_query(sd, query->hostname,
(FAR union dns_addr_u *)addr,
DNS_RECTYPE_A, &qinfo);
Expand All @@ -656,6 +666,8 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
query->result = ret;
}
}

close(sd);
#endif /* CONFIG_NET_IPv4 */

if (next > 0)
Expand All @@ -670,7 +682,6 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
*/

*query->naddr = next;
close(sd);
return 1;
}
else if (query->result != -EAGAIN)
Expand All @@ -679,7 +690,6 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
}
}

close(sd);
return 0;
}

Expand Down

0 comments on commit 693898d

Please sign in to comment.