132f8f8
diff -up openssh-6.8p1/canohost.c.set_remote_ipaddr openssh-6.8p1/canohost.c
132f8f8
--- openssh-6.8p1/canohost.c.set_remote_ipaddr	2015-03-18 12:40:03.702925550 +0100
132f8f8
+++ openssh-6.8p1/canohost.c	2015-03-18 12:40:03.749925432 +0100
132f8f8
@@ -349,6 +349,21 @@ clear_cached_addr(void)
0a3f4e1
 	cached_port = -1;
0a3f4e1
 }
0a3f4e1
 
0a3f4e1
+void set_remote_ipaddr(void) {
0a3f4e1
+	if (canonical_host_ip != NULL)
0a3f4e1
+		free(canonical_host_ip);
0a3f4e1
+
054365b
+	if (active_state != NULL && packet_connection_is_on_socket()) {
0a3f4e1
+		canonical_host_ip =
0a3f4e1
+		    get_peer_ipaddr(packet_get_connection_in());
0a3f4e1
+		if (canonical_host_ip == NULL)
0a3f4e1
+			cleanup_exit(255);
0a3f4e1
+	} else {
0a3f4e1
+		/* If not on socket, return UNKNOWN. */
0a3f4e1
+		canonical_host_ip = xstrdup("UNKNOWN");
0a3f4e1
+	}
0a3f4e1
+}
0a3f4e1
+
0a3f4e1
 /*
0a3f4e1
  * Returns the IP-address of the remote host as a string.  The returned
0a3f4e1
  * string must not be freed.
132f8f8
@@ -358,17 +373,9 @@ const char *
0a3f4e1
 get_remote_ipaddr(void)
0a3f4e1
 {
0a3f4e1
 	/* Check whether we have cached the ipaddr. */
0a3f4e1
-	if (canonical_host_ip == NULL) {
0a3f4e1
-		if (packet_connection_is_on_socket()) {
0a3f4e1
-			canonical_host_ip =
0a3f4e1
-			    get_peer_ipaddr(packet_get_connection_in());
0a3f4e1
-			if (canonical_host_ip == NULL)
0a3f4e1
-				cleanup_exit(255);
0a3f4e1
-		} else {
0a3f4e1
-			/* If not on socket, return UNKNOWN. */
0a3f4e1
-			canonical_host_ip = xstrdup("UNKNOWN");
0a3f4e1
-		}
0a3f4e1
-	}
0a3f4e1
+	if (canonical_host_ip == NULL)
0a3f4e1
+		set_remote_ipaddr();
0a3f4e1
+
0a3f4e1
 	return canonical_host_ip;
0a3f4e1
 }
0a3f4e1
 
132f8f8
diff -up openssh-6.8p1/canohost.h.set_remote_ipaddr openssh-6.8p1/canohost.h
132f8f8
--- openssh-6.8p1/canohost.h.set_remote_ipaddr	2015-03-17 06:49:20.000000000 +0100
132f8f8
+++ openssh-6.8p1/canohost.h	2015-03-18 12:40:03.749925432 +0100
0a3f4e1
@@ -13,6 +13,7 @@
0a3f4e1
  */
0a3f4e1
 
0a3f4e1
 const char	*get_canonical_hostname(int);
0a3f4e1
+void		 set_remote_ipaddr(void);
0a3f4e1
 const char	*get_remote_ipaddr(void);
0a3f4e1
 const char	*get_remote_name_or_ip(u_int, int);
0a3f4e1
 
132f8f8
diff -up openssh-6.8p1/sshconnect.c.set_remote_ipaddr openssh-6.8p1/sshconnect.c
132f8f8
--- openssh-6.8p1/sshconnect.c.set_remote_ipaddr	2015-03-17 06:49:20.000000000 +0100
132f8f8
+++ openssh-6.8p1/sshconnect.c	2015-03-18 12:40:58.096788804 +0100
132f8f8
@@ -65,6 +65,7 @@
132f8f8
 #include "authfile.h"
132f8f8
 #include "ssherr.h"
13073f8
 #include "authfd.h"
0a3f4e1
+#include "canohost.h"
0a3f4e1
 
0a3f4e1
 char *client_version_string = NULL;
0a3f4e1
 char *server_version_string = NULL;
132f8f8
@@ -174,6 +175,7 @@ ssh_proxy_fdpass_connect(const char *hos
0a3f4e1
 
0a3f4e1
 	/* Set the connection file descriptors. */
0a3f4e1
 	packet_set_connection(sock, sock);
0a3f4e1
+	set_remote_ipaddr();
0a3f4e1
 
0a3f4e1
 	return 0;
0a3f4e1
 }
132f8f8
@@ -496,6 +498,7 @@ ssh_connect_direct(const char *host, str
0a3f4e1
 
0a3f4e1
 	/* Set the connection. */
0a3f4e1
 	packet_set_connection(sock, sock);
0a3f4e1
+	set_remote_ipaddr();
0a3f4e1
 
0a3f4e1
 	return 0;
0a3f4e1
 }