]> andersk Git - openssh.git/blobdiff - canohost.c
- (tim) [configure.ac] Add AC_REVISION. Add sys/time.h to lastlog.h test
[openssh.git] / canohost.c
index 66867c10bf33d703441ce3c3a97969da1bacb7e3..6ca60e6b448780adf3efb82a61230b207832a0ec 100644 (file)
@@ -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.48 2005/12/28 22:46:06 stevesk Exp $");
 
 #include "packet.h"
 #include "xmalloc.h"
@@ -102,7 +102,7 @@ get_remote_hostname(int sock, int use_dns)
        hints.ai_socktype = SOCK_STREAM;
        if (getaddrinfo(name, NULL, &hints, &aitop) != 0) {
                logit("reverse mapping checking getaddrinfo for %.700s "
-                   "failed - POSSIBLE BREAKIN ATTEMPT!", name);
+                   "failed - POSSIBLE BREAK-IN ATTEMPT!", name);
                return xstrdup(ntop);
        }
        /* Look for the address from the list of addresses. */
@@ -117,7 +117,7 @@ get_remote_hostname(int sock, int use_dns)
        if (!ai) {
                /* Address not found for the host name. */
                logit("Address %.100s maps to %.600s, but this does not "
-                   "map back to the address - POSSIBLE BREAKIN ATTEMPT!",
+                   "map back to the address - POSSIBLE BREAK-IN ATTEMPT!",
                    ntop, name);
                return xstrdup(ntop);
        }
@@ -198,26 +198,27 @@ ipv64_normalise_mapped(struct sockaddr_storage *addr, socklen_t *len)
 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;
 }
 
 /*
This page took 0.038376 seconds and 4 git commands to generate.