From b92ebe53f3fc7b4a4355724a22690fdef4f1bf2f Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Tue, 19 Apr 2022 12:49:28 +0200
Subject: [PATCH 1/3] connect: store "conn_remote_port" in the info struct

To make it available after the connection ended.
diff --git a/lib/connect.c b/lib/connect.c
index e65d24d..0f122ce 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -611,6 +611,7 @@ void Curl_persistconninfo(struct connectdata *conn)
   conn->data->info.conn_scheme = conn->handler->scheme;
   conn->data->info.conn_protocol = conn->handler->protocol;
   conn->data->info.conn_primary_port = conn->primary_port;
+  conn->data->info.conn_remote_port = conn->remote_port;
   conn->data->info.conn_local_port = conn->local_port;
 }
 
diff --git a/lib/urldata.h b/lib/urldata.h
index 11d7a33..a71ce08 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1145,7 +1145,11 @@ struct PureInfo {
      reused, in the connection cache. */
 
   char conn_primary_ip[MAX_IPADR_LEN];
-  long conn_primary_port;
+  int conn_primary_port; /* this is the destination port to the connection,
+                            which might have been a proxy */
+  int conn_remote_port;  /* this is the "remote port", which is the port
+                            number of the used URL, independent of proxy or
+                            not */
   char conn_local_ip[MAX_IPADR_LEN];
   long conn_local_port;
   const char *conn_scheme;
