I’m borrowing a short C code that establishes a telnet session using a child-parent scheme and handles the communication between both processes through a pseudo terminal device.
The code runs pretty fine but with one major flaw, the telnet process doesn’t execute most escape sequences, printing them instead (ESC prints ^[[, arrows ^[[A ^[[B ^[[C ^[[D, etc.).
I’ve already done quite a bit of research now but I couldn’t find any good resources explaining how should you treat or pass the user input so the end process gets to interpret special codes appropriately, thus achieving a truly interactive session.
The base code: http://dl.dropbox.com/u/15117414/pty.c
I solved the problem and now I’m finally able to share the answer to my question.
The file descriptor which has to be turned to raw mode is the standard input of the parent process, not the slave end of the pseudo terminal device:
This way the parent process passes all user input untouched to the child, who already knows how to deal with those special characters and parses them accordingly.