Skip to content

Commit a41f68d

Browse files
zhhyu7xiaoxiang781216
authored andcommitted
dns: fix dns failed when ipv4/6 dual stack enable
The ipv6 address filled the cache, and the ipv4 address did not have a place to store it, causing the resolution to fail. so if IPV6 has already filled the buffer, rewrite ipv4 DNS results from half of the buffer. Signed-off-by: zhanghongyu <[email protected]>
1 parent 4f25c28 commit a41f68d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

libs/libc/netdb/lib_dnsquery.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,11 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
712712
{
713713
/* Obtain the IPv4 response */
714714

715+
if (next >= *query->naddr)
716+
{
717+
next = *query->naddr / 2;
718+
}
719+
715720
ret = dns_recv_response(sd, &query->addr[next],
716721
*query->naddr - next, &qdata->qinfo,
717722
&query->ttl, qdata->buffer);

libs/libc/netdb/lib_gethostentbynamer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,16 +502,16 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent_s *host,
502502

503503
naddr = (buflen - (namelen + 1)) / sizeof(union dns_addr_u);
504504
DEBUGASSERT(naddr >= 1);
505+
506+
/* We can read more than maximum, limit here. */
507+
508+
naddr = MIN(naddr, CONFIG_NETDB_MAX_IPADDR);
505509
ret = lib_dns_query(name, (FAR union dns_addr_u *)ptr, &naddr);
506510
if (ret < 0)
507511
{
508512
return ret;
509513
}
510514

511-
/* We can read more than maximum, limit here. */
512-
513-
naddr = MIN(naddr, CONFIG_NETDB_MAX_IPADDR);
514-
515515
for (i = 0; i < naddr; i++)
516516
{
517517
#ifdef CONFIG_NET_IPv4

0 commit comments

Comments
 (0)