ssh1_protocol_setup(ssh);
static int do_ssh_init(Ssh ssh, unsigned char c){    struct do_ssh_init_state {	int vslen;	char version[10];	char *vstring;	int vstrsize;	int i;	int proto1, proto2;    };    crState(do_ssh_init_state);    crBegin(ssh->do_ssh_init_crstate);    /* Search for the string "SSH-" in the input. */    s->i = 0;    while (1) {	static const int transS[] = { 1, 2, 2, 1 };	static const int transH[] = { 0, 0, 3, 0 };	static const int transminus[] = { 0, 0, 0, -1 };	if (c == 'S')	    s->i = transS[s->i];	else if (c == 'H')	    s->i = transH[s->i];	else if (c == '-')	    s->i = transminus[s->i];	else	    s->i = 0;	if (s->i < 0)	    break;	crReturn(1);		       /* get another character */    }    s->vstrsize = 16;    s->vstring = snewn(s->vstrsize, char);    strcpy(s->vstring, "SSH-");    s->vslen = 4;    s->i = 0;    while (1) {	crReturn(1);		       /* get another char */	if (s->vslen >= s->vstrsize - 1) {	    s->vstrsize += 16;	    s->vstring = sresize(s->vstring, s->vstrsize, char);	}	s->vstring[s->vslen++] = c;	if (s->i >= 0) {	    if (c == '-') {		s->version[s->i] = '\0';		s->i = -1;	    } else if (s->i < sizeof(s->version) - 1)		s->version[s->i++] = c;	} else if (c == '\012')	    break;    }    ssh->agentfwd_enabled = FALSE;    ssh->rdpkt2_state.incoming_sequence = 0;    s->vstring[s->vslen] = 0;    s->vstring[strcspn(s->vstring, "\r\n")] = '\0';/* remove EOL chars */    {	char *vlog;	vlog = snewn(20 + s->vslen, char);	sprintf(vlog, "Server version: %s", s->vstring);	logevent(vlog);	sfree(vlog);    }    ssh_detect_bugs(ssh, s->vstring);    /*     * Decide which SSH protocol version to support.     */    /* Anything strictly below "2.0" means protocol 1 is supported. */    s->proto1 = ssh_versioncmp(s->version, "2.0") < 0;    /* Anything greater or equal to "1.99" means protocol 2 is supported. */    s->proto2 = ssh_versioncmp(s->version, "1.99") >= 0;    if (ssh->cfg.sshprot == 0 && !s->proto1) {	bombout(("SSH protocol version 1 required by user but not provided by server"));	crStop(0);    }    if (ssh->cfg.sshprot == 3 && !s->proto2) {	bombout(("SSH protocol version 2 required by user but not provided by server"));	crStop(0);    }    if (s->proto2 && (ssh->cfg.sshprot >= 2 || !s->proto1)) {	/*	 * Use v2 protocol.	 */	char verstring[80], vlog[100];	sprintf(verstring, "SSH-2.0-%s", sshver);	SHA_Init(&ssh->exhashbase);	/*	 * Hash our version string and their version string.	 */	sha_string(&ssh->exhashbase, verstring, strlen(verstring));	sha_string(&ssh->exhashbase, s->vstring, strcspn(s->vstring, "\r\n"));	sprintf(vlog, "We claim version: %s", verstring);	logevent(vlog);	strcat(verstring, "\012");	logevent("Using SSH protocol version 2");	sk_write(ssh->s, verstring, strlen(verstring));	ssh->protocol = ssh2_protocol;	ssh->version = 2;	ssh->s_rdpkt = ssh2_rdpkt;    } else {	/*	 * Use v1 protocol.	 */	char verstring[80], vlog[100];	sprintf(verstring, "SSH-%s-%s",		(ssh_versioncmp(s->version, "1.5") <= 0 ? s->version : "1.5"),		sshver);	sprintf(vlog, "We claim version: %s", verstring);	logevent(vlog);	strcat(verstring, "\012");	logevent("Using SSH protocol version 1");	sk_write(ssh->s, verstring, strlen(verstring));	ssh->protocol = ssh1_protocol;	ssh->version = 1;	ssh->s_rdpkt = ssh1_rdpkt;    }    update_specials_menu(ssh->frontend);    ssh->state = SSH_STATE_BEFORE_SIZE;    sfree(s->vstring);    crFinish(0);}