asyn-ares: In Dual Stack, prefer IPV4 address for connection. 82/299582/1 tizen_5.5_tv submit/tizen_5.5_tv/20231011.070046
authorAnjali Nijhara <a.nijhara@samsung.com>
Tue, 3 Oct 2023 08:21:36 +0000 (13:51 +0530)
committerAnjali Nijhara <a.nijhara@samsung.com>
Thu, 5 Oct 2023 08:19:49 +0000 (13:49 +0530)
Change-Id: Ide6210578ca2b4631e2807d1c0ee770fed043d27

lib/asyn-ares.c

index 527f98d..c846c4f 100644 (file)
@@ -476,17 +476,35 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
 static void compound_results(struct ResolverResults *res,
                              Curl_addrinfo *ai)
 {
-  Curl_addrinfo *ai_tail;
   if(!ai)
     return;
-  ai_tail = ai;
+  /* Add the new results to the list of old results. */
+#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
+  if(res->temp_ai && res->temp_ai->ai_family == PF_INET) {
+      /* We have some results already and we need
+       * to make sure that IPv4 entries always
+       *  go to the head of the list to try to
+       *  connect with IPV4 family first */
+      struct Curl_addrinfo *temp_ai_tail = res->temp_ai;
 
-  while(ai_tail->ai_next)
-    ai_tail = ai_tail->ai_next;
+      while(temp_ai_tail->ai_next)
+          temp_ai_tail = temp_ai_tail->ai_next;
 
-  /* Add the new results to the list of old results. */
-  ai_tail->ai_next = res->temp_ai;
-  res->temp_ai = ai;
+      temp_ai_tail->ai_next = ai;
+  }
+  else
+#endif /* CURLRES_IPV6 */
+  {
+      struct Curl_addrinfo *ai_tail = ai;
+      ai_tail = ai;
+
+      while(ai_tail->ai_next)
+          ai_tail = ai_tail->ai_next;
+
+      /* Add the new results to the list of old results. */
+      ai_tail->ai_next = res->temp_ai;
+      res->temp_ai = ai;
+  }
 }
 
 /*