This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 693898d566 netdb/dns: fix dns wrong response ID error
693898d566 is described below

commit 693898d566838d7bfa61c0e58191c21b25921e42
Author: wangchen <wangche...@xiaomi.com>
AuthorDate: Wed Jun 14 09:55:08 2023 +0800

    netdb/dns: fix dns wrong response ID error
    
    In every dns query, we use the new socket to avoid receiving last response 
ID
    
    Signed-off-by: wangchen <wangche...@xiaomi.com>
---
 libs/libc/netdb/lib_dnsquery.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/libs/libc/netdb/lib_dnsquery.c b/libs/libc/netdb/lib_dnsquery.c
index 6b160380e7..5a9e0cd51f 100644
--- a/libs/libc/netdb/lib_dnsquery.c
+++ b/libs/libc/netdb/lib_dnsquery.c
@@ -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.
@@ -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);
@@ -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);
@@ -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)
@@ -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)
@@ -679,7 +690,6 @@ static int dns_query_callback(FAR void *arg, FAR struct 
sockaddr *addr,
         }
     }
 
-  close(sd);
   return 0;
 }
 

Reply via email to