Send server SSH version immediately after accepting connection to prevent client timeout

parent f8e10fbf
......@@ -477,17 +477,32 @@ int main(int argc, char *argv[]) {
pthread_mutex_lock(&tunnel_mutex);
active_tunnel->local_sock = accepted_sock;
// Send server version immediately to prevent SSH client timeout
const char *server_version = "SSH-2.0-OpenSSH_10.0p2 Debian-8\r\n";
size_t version_len = strlen(server_version);
if (config.debug) {
printf("[DEBUG - Tunnel] Sending server version immediately to SSH client\n");
fflush(stdout);
}
ssize_t sent = send(accepted_sock, server_version, version_len, 0);
if (sent > 0) {
if (config.debug) {
printf("[DEBUG] Sent %zd bytes of server version to SSH client\n", sent);
fflush(stdout);
}
}
// Send any buffered data to the SSH client immediately
if (active_tunnel->incoming_buffer && active_tunnel->incoming_buffer->used > 0) {
if (config.debug) {
printf("[DEBUG - Tunnel] Sending %zu bytes of buffered server response to SSH client\n", active_tunnel->incoming_buffer->used);
fflush(stdout);
}
ssize_t sent = send(accepted_sock, active_tunnel->incoming_buffer->buffer, active_tunnel->incoming_buffer->used, 0);
if (sent > 0) {
frame_buffer_consume(active_tunnel->incoming_buffer, sent);
ssize_t sent2 = send(accepted_sock, active_tunnel->incoming_buffer->buffer, active_tunnel->incoming_buffer->used, 0);
if (sent2 > 0) {
frame_buffer_consume(active_tunnel->incoming_buffer, sent2);
if (config.debug) {
printf("[DEBUG] Sent %zd bytes of buffered server response to SSH client\n", sent);
printf("[DEBUG] Sent %zd bytes of buffered server response to SSH client\n", sent2);
fflush(stdout);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment