Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netdb/dns: fix dns wrong response ID error #9534

Merged
merged 1 commit into from Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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