diff --git a/session.h b/session.h
index 128214be1efed886d63dd136b3a5a001b8e3bf33..20a90a45c4ab510651ad31b0037bf6bbe7143e46 100644
--- a/session.h
+++ b/session.h
@@ -211,6 +211,9 @@ struct serversession {
 	/* The numeric address they connected from, used for logging */
 	char * addrstring;
 
+	/* The resolved remote address, used for lastlog etc */
+	char *remotehost;
+
 #ifdef __uClinux__
 	pid_t server_pid;
 #endif
diff --git a/svr-chansession.c b/svr-chansession.c
index 782e97fa63a4562288fb7912cdba49aa10842d79..5ecc57fc6078f32b95a732a0a085cd340a2cfe90 100644
--- a/svr-chansession.c
+++ b/svr-chansession.c
@@ -253,12 +253,9 @@ static int newchansess(struct Channel *channel) {
 
 static struct logininfo* 
 chansess_login_alloc(struct ChanSess *chansess) {
-	char *remotehost;
 	struct logininfo * li;
-	get_socket_address(ses.sock_in, NULL, NULL, &remotehost, NULL, 1);
 	li = login_alloc_entry(chansess->pid, ses.authstate.username,
-			remotehost, chansess->tty);
-	m_free(remotehost);	
+			svr_ses.remotehost, chansess->tty);
 	return li;
 }
 
diff --git a/svr-session.c b/svr-session.c
index a5099069e1e57153347e342fb11fa0aa8f2580e4..da49e1aaa68bf17e6dee6c7c7e1526c767f36ba0 100644
--- a/svr-session.c
+++ b/svr-session.c
@@ -101,6 +101,9 @@ void svr_session(int sock, int childpipe) {
 	m_free(host);
 	m_free(port);
 
+	get_socket_address(ses.sock_in, NULL, NULL, 
+			&svr_ses.remotehost, NULL, 1);
+
 	/* set up messages etc */
 	ses.remoteclosed = svr_remoteclosed;