if (pr->dynamic) { while (len--) { if (pr->port >= lenof(pr->hostname)) { if ((pr->dynamic >> 12) == 4) {  char data[8]; memset(data, 0, sizeof(data)); data[1] = 91;       sk_write(pr->s, data, 8); } pfd_close(pr->s); return 1; } pr->hostname[pr->port++] = *data++;   if ((pr->dynamic == 1 || (pr->dynamic >> 12) == 4) && pr->hostname[0] == 4) {  if (pr->dynamic == 1) pr->dynamic = 0x4000; if (pr->port < 2) continue; if (pr->hostname[1] != 1) {  char data[8]; memset(data, 0, sizeof(data)); data[1] = 91;       sk_write(pr->s, data, 8); pfd_close(pr->s); return 1; } if (pr->port < 8) continue;    if (pr->hostname[pr->port-1] != 0) continue;	         if (pr->hostname[4] == 0 && pr->hostname[5] == 0 && pr->hostname[6] == 0 && pr->hostname[7] != 0) {  int len; if (pr->dynamic == 0x4000) { pr->dynamic = 0x4001; continue; } pr->hostname[0] = 0;    pr->hostname[1] = 90;    sk_write(pr->s, pr->hostname, 8); pr->port = GET_16BIT_MSB_FIRST(pr->hostname+2); len = strlen(pr->hostname+8); memmove(pr->hostname, pr->hostname + 8 + len + 1, lenof(pr->hostname) - (8 + len + 1)); goto connect; } else {  pr->hostname[0] = 0;    pr->hostname[1] = 90;    sk_write(pr->s, pr->hostname, 8); pr->port = GET_16BIT_MSB_FIRST(pr->hostname+2); sprintf(pr->hostname, "%d.%d.%d.%d", (unsigned char)pr->hostname[4], (unsigned char)pr->hostname[5], (unsigned char)pr->hostname[6], (unsigned char)pr->hostname[7]); goto connect; } }  if ((pr->dynamic == 1 || (pr->dynamic >> 12) == 5) && pr->hostname[0] == 5) {  if (pr->dynamic == 1) pr->dynamic = 0x5000;  if (pr->dynamic == 0x5000) { int i, method; char data[2];  if (pr->port < 2) continue; if (pr->port < 2 + (unsigned char)pr->hostname[1]) continue;       method = 0xFF;      for (i = 0; i < (unsigned char)pr->hostname[1]; i++) if (pr->hostname[2+i] == 0) { method = 0; break; } data[0] = 5; data[1] = method; sk_write(pr->s, data, 2); pr->dynamic = 0x5001; pr->port = 0;       continue; }  if (pr->dynamic == 0x5001) { int atype, alen; if (pr->port < 6) continue; atype = (unsigned char)pr->hostname[3]; if (atype == 1)     alen = 4; if (atype == 4)     alen = 16; if (atype == 3)     alen = 1 + (unsigned char)pr->hostname[4]; if (pr->port < 6 + alen) continue; if (pr->hostname[1] != 1 || pr->hostname[2] != 0) { pr->hostname[1] = 1;    pr->hostname[2] = 0;    sk_write(pr->s, pr->hostname, pr->port); pfd_close(pr->s); return 1; }  pr->port = GET_16BIT_MSB_FIRST(pr->hostname+4+alen); if (atype == 1) { pr->hostname[1] = 0;    sk_write(pr->s, pr->hostname, alen + 6); sprintf(pr->hostname, "%d.%d.%d.%d", (unsigned char)pr->hostname[4], (unsigned char)pr->hostname[5], (unsigned char)pr->hostname[6], (unsigned char)pr->hostname[7]); goto connect; } else if (atype == 3) { pr->hostname[1] = 0;    sk_write(pr->s, pr->hostname, alen + 6); memmove(pr->hostname, pr->hostname + 5, alen-1); pr->hostname[alen-1] = '\0'; goto connect; } else {  pr->hostname[1] = 8;    sk_write(pr->s, pr->hostname, pr->port); pfd_close(pr->s); return 1; } } }   pfd_close(pr->s); return 1; } return 1;   connect:  pr->c = new_sock_channel(pr->backhandle, pr->s); if (pr->c == NULL) { pfd_close(pr->s); return 1; } else {  ssh_send_port_open(pr->c, pr->hostname, pr->port, "forwarding"); } pr->dynamic = 0;   sk_set_frozen(pr->s, 1);  if (len > 0) { pr->buffer = snewn(len, char); memcpy(pr->buffer, data, len); pr->buflen = len; } }
static int pfd_receive(Plug plug, int urgent, char *data, int len){    struct PFwdPrivate *pr = (struct PFwdPrivate *) plug;    if (pr->ready) {	if (sshfwd_write(pr->c, data, len) > 0) {	    pr->throttled = 1;	    sk_set_frozen(pr->s, 1);	}    }    return 1;}