[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.37 and 1.37.2.2

version 1.37, 2003/06/02 09:17:34 version 1.37.2.2, 2004/08/19 22:37:30
Line 27 
Line 27 
  */   */
   
 static char *  static char *
 get_remote_hostname(int socket, int use_dns)  get_remote_hostname(int sock, int use_dns)
 {  {
         struct sockaddr_storage from;          struct sockaddr_storage from;
         int i;          int i;
Line 38 
Line 38 
         /* Get IP address of client. */          /* Get IP address of client. */
         fromlen = sizeof(from);          fromlen = sizeof(from);
         memset(&from, 0, sizeof(from));          memset(&from, 0, sizeof(from));
         if (getpeername(socket, (struct sockaddr *)&from, &fromlen) < 0) {          if (getpeername(sock, (struct sockaddr *)&from, &fromlen) < 0) {
                 debug("getpeername failed: %.100s", strerror(errno));                  debug("getpeername failed: %.100s", strerror(errno));
                 fatal_cleanup();                  cleanup_exit(255);
         }          }
   
           if (from.ss_family == AF_INET)
                   check_ip_options(sock, 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");
Line 50 
Line 53 
         if (!use_dns)          if (!use_dns)
                 return xstrdup(ntop);                  return xstrdup(ntop);
   
         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),
Line 132 
Line 132 
  */   */
 /* IPv4 only */  /* IPv4 only */
 static void  static void
 check_ip_options(int socket, char *ipaddr)  check_ip_options(int sock, char *ipaddr)
 {  {
         u_char options[200];          u_char options[200];
         char text[sizeof(options) * 3 + 1];          char text[sizeof(options) * 3 + 1];
Line 145 
Line 145 
         else          else
                 ipproto = IPPROTO_IP;                  ipproto = IPPROTO_IP;
         option_size = sizeof(options);          option_size = sizeof(options);
         if (getsockopt(socket, ipproto, IP_OPTIONS, options,          if (getsockopt(sock, 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 194 
Line 194 
  * The returned string must be freed.   * The returned string must be freed.
  */   */
 static char *  static char *
 get_socket_address(int socket, int remote, int flags)  get_socket_address(int sock, int remote, int flags)
 {  {
         struct sockaddr_storage addr;          struct sockaddr_storage addr;
         socklen_t addrlen;          socklen_t addrlen;
Line 205 
Line 205 
         memset(&addr, 0, sizeof(addr));          memset(&addr, 0, sizeof(addr));
   
         if (remote) {          if (remote) {
                 if (getpeername(socket, (struct sockaddr *)&addr, &addrlen)                  if (getpeername(sock, (struct sockaddr *)&addr, &addrlen)
                     < 0)                      < 0)
                         return NULL;                          return NULL;
         } else {          } else {
                 if (getsockname(socket, (struct sockaddr *)&addr, &addrlen)                  if (getsockname(sock, (struct sockaddr *)&addr, &addrlen)
                     < 0)                      < 0)
                         return NULL;                          return NULL;
         }          }
Line 223 
Line 223 
 }  }
   
 char *  char *
 get_peer_ipaddr(int socket)  get_peer_ipaddr(int sock)
 {  {
         char *p;          char *p;
   
         if ((p = get_socket_address(socket, 1, NI_NUMERICHOST)) != NULL)          if ((p = get_socket_address(sock, 1, NI_NUMERICHOST)) != NULL)
                 return p;                  return p;
         return xstrdup("UNKNOWN");          return xstrdup("UNKNOWN");
 }  }
   
 char *  char *
 get_local_ipaddr(int socket)  get_local_ipaddr(int sock)
 {  {
         char *p;          char *p;
   
         if ((p = get_socket_address(socket, 0, NI_NUMERICHOST)) != NULL)          if ((p = get_socket_address(sock, 0, NI_NUMERICHOST)) != NULL)
                 return p;                  return p;
         return xstrdup("UNKNOWN");          return xstrdup("UNKNOWN");
 }  }
   
 char *  char *
 get_local_name(int socket)  get_local_name(int sock)
 {  {
         return get_socket_address(socket, 0, NI_NAMEREQD);          return get_socket_address(sock, 0, NI_NAMEREQD);
 }  }
   
 /*  /*
Line 264 
Line 264 
                         canonical_host_ip =                          canonical_host_ip =
                             get_peer_ipaddr(packet_get_connection_in());                              get_peer_ipaddr(packet_get_connection_in());
                         if (canonical_host_ip == NULL)                          if (canonical_host_ip == NULL)
                                 fatal_cleanup();                                  cleanup_exit(255);
                 } else {                  } else {
                         /* If not on socket, return UNKNOWN. */                          /* If not on socket, return UNKNOWN. */
                         canonical_host_ip = xstrdup("UNKNOWN");                          canonical_host_ip = xstrdup("UNKNOWN");
Line 304 
Line 304 
         } else {          } else {
                 if (getpeername(sock, (struct sockaddr *)&from, &fromlen) < 0) {                  if (getpeername(sock, (struct sockaddr *)&from, &fromlen) < 0) {
                         debug("getpeername failed: %.100s", strerror(errno));                          debug("getpeername failed: %.100s", strerror(errno));
                         fatal_cleanup();                          cleanup_exit(255);
                 }                  }
         }          }
         /* Return port number. */          /* Return port number. */
Line 339 
Line 339 
 int  int
 get_remote_port(void)  get_remote_port(void)
 {  {
         return get_port(0);          static int port = -1;
   
           /* Cache to avoid getpeername() on a dead connection */
           if (port == -1)
                   port = get_port(0);
   
           return port;
 }  }
   
 int  int

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.37.2.2