2

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

Marcel Hernandez
  • 1,371
  • 13
  • 22
  • Those looks like standard [VT100 control codes](http://www.termsys.demon.co.uk/vtansi.htm). You have to check and parse them yourself. Or ask the client to do its own command line editing (which wont work with the Windows telnet client). – Some programmer dude Feb 05 '13 at 13:39
  • So, is the program that displays the data aware of escape sequences? If it weren't, what you're describing is exactly what I would expect to happen ... – unwind Feb 05 '13 at 13:40

1 Answers1

1

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:

new_term_settings = slave_orig_term_settings;
cfmakeraw(&new_term_settings);
tcsetattr(0, TCSANOW, &new_term_settings);

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.

Marcel Hernandez
  • 1,371
  • 13
  • 22