[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.26 and 1.26.2.2

version 1.26, 2001/04/18 14:15:00 version 1.26.2.2, 2002/03/09 00:20:44
Line 19 
Line 19 
 #include "log.h"  #include "log.h"
 #include "canohost.h"  #include "canohost.h"
   
 void    check_ip_options(int socket, char *ipaddr);  static void check_ip_options(int, char *);
   
 /*  /*
  * Return the canonical name of the host at the other end of the socket. The   * Return the canonical name of the host at the other end of the socket. The
  * caller should free the returned string with xfree.   * caller should free the returned string with xfree.
  */   */
   
 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 46 
Line 46 
                 check_ip_options(socket, ntop);                  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");
   
         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 68 
                 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 118 
Line 118 
  * exit here if we detect any IP options.   * exit here if we detect any IP options.
  */   */
 /* IPv4 only */  /* IPv4 only */
 void  static void
 check_ip_options(int socket, char *ipaddr)  check_ip_options(int socket, char *ipaddr)
 {  {
         u_char options[200];          u_char options[200];
Line 132 
Line 132 
         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 152 
  */   */
   
 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 168 
         /* 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 180 
Line 180 
  * Returns the remote IP-address of socket as a string.  The returned   * Returns the remote IP-address of socket as a string.  The returned
  * string must be freed.   * string must be freed.
  */   */
 char *  static char *
 get_socket_address(int socket, int remote, int flags)  get_socket_address(int socket, int remote, int flags)
 {  {
         struct sockaddr_storage addr;          struct sockaddr_storage addr;
Line 208 
Line 208 
         }          }
         /* 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 239 
  */   */
   
 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 259 
 }  }
   
 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 271 
Line 271 
   
 /* Returns the local/remote port for the socket. */  /* Returns the local/remote port for the socket. */
   
 int  static int
 get_sock_port(int sock, int local)  get_sock_port(int sock, int local)
 {  {
         struct sockaddr_storage from;          struct sockaddr_storage from;
Line 294 
Line 294 
         }          }
         /* 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);
 }  }
   
 /* Returns remote/local port number for the current connection. */  /* Returns remote/local port number for the current connection. */
   
 int  static int
 get_port(int local)  get_port(int local)
 {  {
         /*          /*
Line 322 
Line 322 
 }  }
   
 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.26  
changed lines
  Added in v.1.26.2.2