From 61cfbecc7458edd4cc2d538d0a361648131a2c93 Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Tue, 7 Oct 2008 21:56:56 +0000
Subject: [PATCH] - Fixed CURLINFO_PRIMARY_IP: When libcurl created a
 connection to host A then   the app re-used the handle to do a connection to
 host B and then again   re-used the handle to host A, it would not update the
 info with host A's IP   address (due to the connection being re-used) but it
 would instead report   the info from host B.

---
 CHANGES       | 7 +++++++
 RELEASE-NOTES | 1 +
 lib/url.c     | 6 ++++++
 3 files changed, 14 insertions(+)

diff --git a/CHANGES b/CHANGES
index db6b182fcc..3b15134f10 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,13 @@
 
                                   Changelog
 
+Daniel Stenberg (7 Oct 2008)
+- Fixed CURLINFO_PRIMARY_IP: When libcurl created a connection to host A then
+  the app re-used the handle to do a connection to host B and then again
+  re-used the handle to host A, it would not update the info with host A's IP
+  address (due to the connection being re-used) but it would instead report
+  the info from host B.
+
 Yang Tse (7 Oct 2008)
 - Added --enable-optimize configure option to enable and disable compiler
   optimizations to allow decoupled setting from --enable-debug.
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index 35a68c6508..6ee0746734 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -32,6 +32,7 @@ This release includes the following bugfixes:
  o CURLINFO_REDIRECT_URL didn't work with the multi interface
  o CURLOPT_RANGE now works for SFTP downloads
  o FTP SIZE response 550 now causes CURLE_REMOTE_FILE_NOT_FOUND
+ o CURLINFO_PRIMARY_IP fixed for persistent connection re-use cases
 
 This release includes the following known bugs:
 
diff --git a/lib/url.c b/lib/url.c
index bb09d2fd33..17b34c68ed 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -4238,6 +4238,12 @@ static CURLcode create_conn(struct SessionHandle *data,
     infof(data, "Re-using existing connection! (#%ld) with host %s\n",
           conn->connectindex,
           conn->proxy.name?conn->proxy.dispname:conn->host.dispname);
+    /* copy this IP address to the common buffer for the easy handle so that
+       the address can actually survice the removal of this connection. strcpy
+       is safe since the target buffer is big enough to hold the largest
+       possible IP address */
+    strcpy(data->info.ip, conn->ip_addr_str);
+
   }
   else {
     /*
-- 
GitLab