[BACK]Return to canohost.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/canohost.c between version 1.27 and 1.27.2.2

version 1.27, 2001/06/23 15:12:17 version 1.27.2.2, 2002/06/22 07:23:17
Line 27 
Line 27 
  */   */
   
 static char *  static char *
 get_remote_hostname(int socket, int reverse_mapping_check)  get_remote_hostname(int socket, int verify_reverse_mapping)
 {  {
         struct sockaddr_storage from;          struct sockaddr_storage from;
         int i;          int i;
Line 42 
Line 42 
                 debug("getpeername failed: %.100s", strerror(errno));                  debug("getpeername failed: %.100s", strerror(errno));
                 fatal_cleanup();                  fatal_cleanup();
         }          }
         if (from.ss_family == AF_INET)  
                 check_ip_options(socket, ntop);  
   
         if (getnameinfo((struct sockaddr *)&from, fromlen, ntop, sizeof(ntop),          if (getnameinfo((struct sockaddr *)&from, fromlen, ntop, sizeof(ntop),
              NULL, 0, NI_NUMERICHOST) != 0)              NULL, 0, NI_NUMERICHOST) != 0)
                 fatal("get_remote_hostname: getnameinfo NI_NUMERICHOST failed");                  fatal("get_remote_hostname: getnameinfo NI_NUMERICHOST failed");
   
           if (from.ss_family == AF_INET)
                   check_ip_options(socket, ntop);
   
         debug3("Trying to reverse map address %.100s.", ntop);          debug3("Trying to reverse map address %.100s.", ntop);
         /* Map the IP address to a host name. */          /* Map the IP address to a host name. */
         if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name),          if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name),
              NULL, 0, NI_NAMEREQD) != 0) {              NULL, 0, NI_NAMEREQD) != 0) {
                 /* Host name not found.  Use ip address. */                  /* Host name not found.  Use ip address. */
                 log("Could not reverse map address %.100s.", ntop);                  log("Could not reverse map address %.100s.", ntop);
                 return xstrdup(ntop);                  return xstrdup(ntop);
Line 68 
Line 69 
                 if (isupper(name[i]))                  if (isupper(name[i]))
                         name[i] = tolower(name[i]);                          name[i] = tolower(name[i]);
   
         if (!reverse_mapping_check)          if (!verify_reverse_mapping)
                 return xstrdup(name);                  return xstrdup(name);
         /*          /*
          * Map it back to an IP address and check that the given           * Map it back to an IP address and check that the given
Line 132 
Line 133 
         else          else
                 ipproto = IPPROTO_IP;                  ipproto = IPPROTO_IP;
         option_size = sizeof(options);          option_size = sizeof(options);
         if (getsockopt(socket, ipproto, IP_OPTIONS, (void *)options,          if (getsockopt(socket, ipproto, IP_OPTIONS, options,
             &option_size) >= 0 && option_size != 0) {              &option_size) >= 0 && option_size != 0) {
                 text[0] = '\0';                  text[0] = '\0';
                 for (i = 0; i < option_size; i++)                  for (i = 0; i < option_size; i++)
Line 152 
Line 153 
  */   */
   
 const char *  const char *
 get_canonical_hostname(int reverse_mapping_check)  get_canonical_hostname(int verify_reverse_mapping)
 {  {
         static char *canonical_host_name = NULL;          static char *canonical_host_name = NULL;
         static int reverse_mapping_checked = 0;          static int verify_reverse_mapping_done = 0;
   
         /* Check if we have previously retrieved name with same option. */          /* Check if we have previously retrieved name with same option. */
         if (canonical_host_name != NULL) {          if (canonical_host_name != NULL) {
                 if (reverse_mapping_checked != reverse_mapping_check)                  if (verify_reverse_mapping_done != verify_reverse_mapping)
                         xfree(canonical_host_name);                          xfree(canonical_host_name);
                 else                  else
                         return canonical_host_name;                          return canonical_host_name;
Line 168 
Line 169 
         /* Get the real hostname if socket; otherwise return UNKNOWN. */          /* Get the real hostname if socket; otherwise return UNKNOWN. */
         if (packet_connection_is_on_socket())          if (packet_connection_is_on_socket())
                 canonical_host_name = get_remote_hostname(                  canonical_host_name = get_remote_hostname(
                     packet_get_connection_in(), reverse_mapping_check);                      packet_get_connection_in(), verify_reverse_mapping);
         else          else
                 canonical_host_name = xstrdup("UNKNOWN");                  canonical_host_name = xstrdup("UNKNOWN");
   
         reverse_mapping_checked = reverse_mapping_check;          verify_reverse_mapping_done = verify_reverse_mapping;
         return canonical_host_name;          return canonical_host_name;
 }  }
   
Line 208 
Line 209 
         }          }
         /* Get the address in ascii. */          /* Get the address in ascii. */
         if (getnameinfo((struct sockaddr *)&addr, addrlen, ntop, sizeof(ntop),          if (getnameinfo((struct sockaddr *)&addr, addrlen, ntop, sizeof(ntop),
              NULL, 0, flags) != 0) {              NULL, 0, flags) != 0) {
                 error("get_socket_ipaddr: getnameinfo %d failed", flags);                  error("get_socket_ipaddr: getnameinfo %d failed", flags);
                 return NULL;                  return NULL;
         }          }
Line 239 
Line 240 
  */   */
   
 const char *  const char *
 get_remote_ipaddr()  get_remote_ipaddr(void)
 {  {
         static char *canonical_host_ip = NULL;          static char *canonical_host_ip = NULL;
   
Line 259 
Line 260 
 }  }
   
 const char *  const char *
 get_remote_name_or_ip(u_int utmp_len, int reverse_mapping_check)  get_remote_name_or_ip(u_int utmp_len, int verify_reverse_mapping)
 {  {
         static const char *remote = "";          static const char *remote = "";
         if (utmp_len > 0)          if (utmp_len > 0)
                 remote = get_canonical_hostname(reverse_mapping_check);                  remote = get_canonical_hostname(verify_reverse_mapping);
         if (utmp_len == 0 || strlen(remote) > utmp_len)          if (utmp_len == 0 || strlen(remote) > utmp_len)
                 remote = get_remote_ipaddr();                  remote = get_remote_ipaddr();
         return remote;          return remote;
Line 294 
Line 295 
         }          }
         /* Return port number. */          /* Return port number. */
         if (getnameinfo((struct sockaddr *)&from, fromlen, NULL, 0,          if (getnameinfo((struct sockaddr *)&from, fromlen, NULL, 0,
              strport, sizeof(strport), NI_NUMERICSERV) != 0)              strport, sizeof(strport), NI_NUMERICSERV) != 0)
                 fatal("get_sock_port: getnameinfo NI_NUMERICSERV failed");                  fatal("get_sock_port: getnameinfo NI_NUMERICSERV failed");
         return atoi(strport);          return atoi(strport);
 }  }
Line 322 
Line 323 
 }  }
   
 int  int
 get_remote_port()  get_remote_port(void)
 {  {
         return get_port(0);          return get_port(0);
 }  }
   
 int  int
 get_local_port()  get_local_port(void)
 {  {
         return get_port(1);          return get_port(1);
 }  }

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.27.2.2