deps/libssh-0.6.3/src/misc.c
int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2) {
  const char *banner;
  const char *openssh;

  if (server) {
      banner = session->clientbanner;
  } else {
      banner = session->serverbanner;
  }

  if (banner == NULL) {
      ssh_set_error(session, SSH_FATAL, "Invalid banner");
      return -1;
  }

  /*
   * Typical banners e.g. are:
   *
   * SSH-1.5-openSSH_5.4
   * SSH-1.99-openSSH_3.0
   *
   * SSH-2.0-something
   * 012345678901234567890
   */
  if (strlen(banner) < 6 ||
      strncmp(banner, "SSH-", 4) != 0) {
    ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
    return -1;
  }

  SSH_LOG(SSH_LOG_RARE, "Analyzing banner: %s", banner);

  switch(banner[4]) {
    case '1':
      *ssh1 = 1;
      if (strlen(banner) > 6) {
          if (banner[6] == '9') {
            *ssh2 = 1;
          } else {
            *ssh2 = 0;
          }
      }
      break;
    case '2':
      *ssh1 = 0;
      *ssh2 = 1;
      break;
    default:
      ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
      return -1;
  }

  openssh = strstr(banner, "OpenSSH");
  if (openssh != NULL) {
      int major, minor;

      /*
       * The banner is typical:
       * OpenSSH_5.4
       * 012345678901234567890
       */
      if (strlen(openssh) > 9) {
          major = strtol(openssh + 8, (char **) NULL, 10);
          minor = strtol(openssh + 10, (char **) NULL, 10);
          session->openssh = SSH_VERSION_INT(major, minor, 0);
          SSH_LOG(SSH_LOG_RARE,
                  "We are talking to an OpenSSH client version: %d.%d (%x)",
                  major, minor, session->openssh);
      }
  }


  return 0;
}
/**
 * @internal
 *
 * @brief Analyze the SSH banner to find out if we have a SSHv1 or SSHv2
 * server.
 *
 * @param  session      The session to analyze the banner from.
 * @param  server       0 means we are a client, 1 a server.
 * @param  ssh1         The variable which is set if it is a SSHv1 server.
 * @param  ssh2         The variable which is set if it is a SSHv2 server.
 *
 * @return 0 on success, < 0 on error.
 *
 * @see ssh_get_banner()
 */
@internal
@brief Analyze the SSH banner to find out if we have a SSHv1 or SSHv2
server.

@param  session      The session to analyze the banner from.
@param  server       0 means we are a client, 1 a server.
@param  ssh1         The variable which is set if it is a SSHv1 server.
@param  ssh2         The variable which is set if it is a SSHv2 server.

@return 0 on success, < 0 on error.


@internal @brief Analyze the SSH banner to find out if we have a SSHv1 or SSHv2 server . @param session The session to analyze the banner from . @param server 0 means we are a client 1 a server . @param ssh1 The variable which is set if it is a SSHv1 server . @param ssh2 The variable which is set if it is a SSHv2 server . @return 0 on success < 0 on error .
int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2) {
  const char *banner;
  const char *openssh;
  if (server) {
      banner = session->clientbanner;
  } else {
      banner = session->serverbanner;
  }
  if (banner == NULL) {
      ssh_set_error(session, SSH_FATAL, "Invalid banner");
      return -1;
  }
  if (strlen(banner) < 6 ||
      strncmp(banner, "SSH-", 4) != 0) {
    ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
    return -1;
  }
  SSH_LOG(SSH_LOG_RARE, "Analyzing banner: %s", banner);
  switch(banner[4]) {
    case '1':
      *ssh1 = 1;
      if (strlen(banner) > 6) {
          if (banner[6] == '9') {
            *ssh2 = 1;
          } else {
            *ssh2 = 0;
          }
      }
      break;
    case '2':
      *ssh1 = 0;
      *ssh2 = 1;
      break;
    default:
      ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
      return -1;
  }
  openssh = strstr(banner, "OpenSSH");
  if (openssh != NULL) {
      int major, minor;
      if (strlen(openssh) > 9) {
          major = strtol(openssh + 8, (char **) NULL, 10);
          minor = strtol(openssh + 10, (char **) NULL, 10);
          session->openssh = SSH_VERSION_INT(major, minor, 0);
          SSH_LOG(SSH_LOG_RARE,
                  "We are talking to an OpenSSH client version: %d.%d (%x)",
                  major, minor, session->openssh);
      }
  }
  return 0;
}
int ssh_analyze_banner ( ssh_session session , int server , int * ssh1 , int * ssh2 ) { const char * banner ; const char * openssh ; if ( server ) { banner = session -> clientbanner ; } else { banner = session -> serverbanner ; } if ( banner == NULL ) { ssh_set_error ( session , SSH_FATAL , " " ) ; return -1 ; } if ( strlen ( banner ) < 6 || strncmp ( banner , " " , 4 ) != 0 ) { ssh_set_error ( session , SSH_FATAL , " " , banner ) ; return -1 ; } SSH_LOG ( SSH_LOG_RARE , " " , banner ) ; switch ( banner [ 4 ] ) { case ' ' : * ssh1 = 1 ; if ( strlen ( banner ) > 6 ) { if ( banner [ 6 ] == ' ' ) { * ssh2 = 1 ; } else { * ssh2 = 0 ; } } break ; case ' ' : * ssh1 = 0 ; * ssh2 = 1 ; break ; default : ssh_set_error ( session , SSH_FATAL , " " , banner ) ; return -1 ; } openssh = strstr ( banner , " " ) ; if ( openssh != NULL ) { int major , minor ; if ( strlen ( openssh ) > 9 ) { major = strtol ( openssh + 8 , ( char * * ) NULL , 10 ) ; minor = strtol ( openssh + 10 , ( char * * ) NULL , 10 ) ; session -> openssh = SSH_VERSION_INT ( major , minor , 0 ) ; SSH_LOG ( SSH_LOG_RARE , " " , major , minor , session -> openssh ) ; } } return 0 ; }
@internal
 @brief Analyze the SSH banner to find out if we have a SSHv1 or SSHv2
 server.
@internal @brief Analyze the SSH banner to find out if we have a SSHv1 or SSHv2 server .
/*
   * Typical banners e.g. are:
   *
   * SSH-1.5-openSSH_5.4
   * SSH-1.99-openSSH_3.0
   *
   * SSH-2.0-something
   * 012345678901234567890
   */ /*
       * The banner is typical:
       * OpenSSH_5.4
       * 012345678901234567890
       */