I’m currently transitioning a legacy terminal application from Telnet to SSH and encountering issues with how SSH interprets escape sequences compared to Telnet. This is affecting how data is displayed and processed within our application.
Problem Description:
The core issue is that SSH does not seem to receive or interpret escape sequences in the same format as Telnet, which is critical for our application’s functionality. Despite numerous adjustments, the raw data received via SSH differs significantly from that received via Telnet.
Here are snippets of the raw data received from each protocol, highlighting the discrepancies:
Telnet Raw Data Example with code that was used to grab data from the server:
nchars = recv(sock, rcvbuf, RCVBUFSZ, 0);
x1b[1;61Hx1b[Kx1b[2;1Hx1b[K...
SSH Raw Data Example with code that was used to grab data from the server:
nbytes = ssh_channel_read(channel, buffer, bufferSize, 0);
x1B[4lx1B[mx1B(Bx1B[1mx1B[1mx1B[32;40mx1B[1mx1B[Hx1B[0K...
Due to the differences in this, I am unsure of how to move forward. I think I need to make a custom parser for the new raw data I am getting, but I am trying to exhaust every option before I move forward with that.
Here is the code that is processing each char:
(chrfnc[index].fp)(scr, ch);
Here’s a breakdown of what each component is intended to do:
chrfnc[index].fp: This is a function pointer. The array chrfnc contains elements, each with a field fp which is a pointer to a function. The index is presumably set based on the current character’s properties or the context provided by previously received data.
scr: This is passed as the first argument to the function pointed by fp. It represents the current state or context of the screen (or terminal session), allowing the function to modify the display or internal state based on the character processed.
ch: The character currently being processed, passed as the second argument to the function. This character could be part of a command sequence, plain text to be displayed, or a control character affecting the state of the terminal.
Questions:
-
Are there specific configurations or tweaks in libssh or the SSH setup that can ensure terminal output is processed identically (or received identically) to how Telnet does?
-
How can incoming data in SSH be adjusted or processed to more closely mimic the handling of escape sequences by Telnet?
What We’ve Tried:
1. Adjusting Terminal Settings: We have tried various terminal settings (e.g., vt100, xterm) in our SSH configuration to replicate Telnet’s behavior.
2. Ensuring Character Encoding Consistency: Both Telnet and SSH sessions are configured to use the same character encoding.
3. Logging and Comparing Data: We are logging raw input from both Telnet and SSH sessions for comparison.