summaryrefslogtreecommitdiff
path: root/canohost.c
diff options
context:
space:
mode:
Diffstat (limited to 'canohost.c')
-rw-r--r--canohost.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/canohost.c b/canohost.c
index 66867c10b..bd7f830de 100644
--- a/canohost.c
+++ b/canohost.c
@@ -12,7 +12,7 @@
12 */ 12 */
13 13
14#include "includes.h" 14#include "includes.h"
15RCSID("$OpenBSD: canohost.c,v 1.46 2005/10/30 08:29:29 dtucker Exp $"); 15RCSID("$OpenBSD: canohost.c,v 1.47 2005/11/03 13:38:29 dtucker Exp $");
16 16
17#include "packet.h" 17#include "packet.h"
18#include "xmalloc.h" 18#include "xmalloc.h"
@@ -198,26 +198,27 @@ ipv64_normalise_mapped(struct sockaddr_storage *addr, socklen_t *len)
198const char * 198const char *
199get_canonical_hostname(int use_dns) 199get_canonical_hostname(int use_dns)
200{ 200{
201 char *host;
201 static char *canonical_host_name = NULL; 202 static char *canonical_host_name = NULL;
202 static int use_dns_done = 0; 203 static char *remote_ip = NULL;
203 204
204 /* Check if we have previously retrieved name with same option. */ 205 /* Check if we have previously retrieved name with same option. */
205 if (canonical_host_name != NULL) { 206 if (use_dns && canonical_host_name != NULL)
206 if (use_dns_done != use_dns) 207 return canonical_host_name;
207 xfree(canonical_host_name); 208 if (!use_dns && remote_ip != NULL)
208 else 209 return remote_ip;
209 return canonical_host_name;
210 }
211 210
212 /* Get the real hostname if socket; otherwise return UNKNOWN. */ 211 /* Get the real hostname if socket; otherwise return UNKNOWN. */
213 if (packet_connection_is_on_socket()) 212 if (packet_connection_is_on_socket())
214 canonical_host_name = get_remote_hostname( 213 host = get_remote_hostname(packet_get_connection_in(), use_dns);
215 packet_get_connection_in(), use_dns);
216 else 214 else
217 canonical_host_name = xstrdup("UNKNOWN"); 215 host = "UNKNOWN";
218 216
219 use_dns_done = use_dns; 217 if (use_dns)
220 return canonical_host_name; 218 canonical_host_name = host;
219 else
220 remote_ip = host;
221 return host;
221} 222}
222 223
223/* 224/*