summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@cvs.openbsd.org>2005-11-03 13:38:30 +0000
committerDarren Tucker <dtucker@cvs.openbsd.org>2005-11-03 13:38:30 +0000
commit9b125c52cc2189871cd44ae647d5d7420416561b (patch)
tree4f70a9948a5ad0d0f748bd814011f23ef6130cb0
parent9d47f02deb1678a80669616ca5666b0e3fbf1c17 (diff)
Cache reverse lookups with and without DNS separately; ok markus@
-rw-r--r--usr.bin/ssh/canohost.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/usr.bin/ssh/canohost.c b/usr.bin/ssh/canohost.c
index 2c3375014f9..f55301e72fa 100644
--- a/usr.bin/ssh/canohost.c
+++ b/usr.bin/ssh/canohost.c
@@ -12,7 +12,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: canohost.c,v 1.46 2005/10/30 08:29:29 dtucker Exp $");
+RCSID("$OpenBSD: canohost.c,v 1.47 2005/11/03 13:38:29 dtucker Exp $");
#include "packet.h"
#include "xmalloc.h"
@@ -166,26 +166,27 @@ check_ip_options(int sock, char *ipaddr)
const char *
get_canonical_hostname(int use_dns)
{
+ char *host;
static char *canonical_host_name = NULL;
- static int use_dns_done = 0;
+ static char *remote_ip = NULL;
/* Check if we have previously retrieved name with same option. */
- if (canonical_host_name != NULL) {
- if (use_dns_done != use_dns)
- xfree(canonical_host_name);
- else
- return canonical_host_name;
- }
+ if (use_dns && canonical_host_name != NULL)
+ return canonical_host_name;
+ if (!use_dns && remote_ip != NULL)
+ return remote_ip;
/* Get the real hostname if socket; otherwise return UNKNOWN. */
if (packet_connection_is_on_socket())
- canonical_host_name = get_remote_hostname(
- packet_get_connection_in(), use_dns);
+ host = get_remote_hostname(packet_get_connection_in(), use_dns);
else
- canonical_host_name = xstrdup("UNKNOWN");
+ host = "UNKNOWN";
- use_dns_done = use_dns;
- return canonical_host_name;
+ if (use_dns)
+ canonical_host_name = host;
+ else
+ remote_ip = host;
+ return host;
}
/*