mgahagan / rpms / openssh

Forked from rpms/openssh 6 years ago
Clone
0a3f4e1
diff --git a/canohost.c b/canohost.c
0a3f4e1
index 97ce58c..1f9320a 100644
0a3f4e1
--- a/canohost.c
0a3f4e1
+++ b/canohost.c
0a3f4e1
@@ -338,6 +338,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
+
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
+
0a3f4e1
 /*
0a3f4e1
  * Returns the IP-address of the remote host as a string.  The returned
0a3f4e1
  * string must not be freed.
0a3f4e1
@@ -347,17 +362,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
 
0a3f4e1
diff --git a/canohost.h b/canohost.h
0a3f4e1
index 4c8636f..4079953 100644
0a3f4e1
--- a/canohost.h
0a3f4e1
+++ b/canohost.h
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
 
0a3f4e1
diff --git a/sshconnect.c b/sshconnect.c
0a3f4e1
index e636f33..451a58b 100644
0a3f4e1
--- a/sshconnect.c
0a3f4e1
+++ b/sshconnect.c
0a3f4e1
@@ -62,6 +62,7 @@
0a3f4e1
 #include "monitor_fdpass.h"
0a3f4e1
 #include "ssh2.h"
0a3f4e1
 #include "version.h"
0a3f4e1
+#include "canohost.h"
0a3f4e1
 
0a3f4e1
 char *client_version_string = NULL;
0a3f4e1
 char *server_version_string = NULL;
0a3f4e1
@@ -170,6 +171,7 @@ ssh_proxy_fdpass_connect(const char *host, u_short port,
0a3f4e1
 
0a3f4e1
 	/* Set the connection file descriptors. */
0a3f4e1
 	packet_set_connection(sock, sock);
0a3f4e1
+	set_remote_ipaddr();
0a3f4e1
 
0a3f4e1
 	return 0;
0a3f4e1
 }
0a3f4e1
@@ -492,6 +494,7 @@ ssh_connect_direct(const char *host, struct addrinfo *aitop,
0a3f4e1
 
0a3f4e1
 	/* Set the connection. */
0a3f4e1
 	packet_set_connection(sock, sock);
0a3f4e1
+	set_remote_ipaddr();
0a3f4e1
 
0a3f4e1
 	return 0;
0a3f4e1
 }