Design notes on TCPtty

Design Notes On TCPtty

These notes are for the benefit of future hackers and maintainers. The following sections are both functional and narrative, read from beginning to end.

History

TCPtty was initially conceived while I was using the Palm OS Emulator (POSE). POSE 3.2 and higher has a feature to map serial I/O to a TCP socket instead of one of the host's serial ports. I was doing network development for Palm OS and thus had to setup a PPP server for POSE to communicate with. Without using the Serial over TCP feature I had to connect a null modem cable between two serial ports and run a PPP server off of one of them. If you wanted to run 5 Emulator sessions at the same time then you better have a lot of serial ports.

I decided that I wanted to run PPP over TCP. Thus I created TCPtty as a means to spawn a copy of pppd(or any program) everytime a new connection came in and remap pppd's stdin/stdout/stderr to the slave side of a pseudo terminal (pty) pair, while the master side communicated with the TCP socket.

Remapping a program's stdin/stdout/stderr to a pseudo terminal is nothing new and examples of how to do this can be found in Advanced Programming in the Unix Environment by Stevens. Specifically one should read Chapter 19. The source file "ptyfuncs.c" is based on his sample code.

A similar program that does not allow multiple simulateneous connections is Socket by Juergen Nickelsen.

Buffer size and Transmission interval?

There is a default transmission interval of 4 milliseconds and a default transmission buffer size of 16 bytes. The interval and buffer size are there for a very good reason. As mentioned above I wrote TCPtty to connect a pppd server to POSE. POSE (as of this writing) does not regulate the speed with which it delivers data to the emulated Palm when using Serial over TCP. Thus the emulated Palm's serial receive buffers are easily overrun by a TCP socket on a 100MB/s network. To correct for this problem it was necessary to only transmit data every so often and to only transmit a relatively small amount of data. For my development environment I found that transmitting 16 bytes of data every 4 ms allowed the emulated Palm to not be overrun.

Internationalization

Internationalization is handled using GNU gettext (see the file ABOUT_NLS in the source distribution). This places some minor constraints on the code.

Strings that must be subject to translation should be wrapped with GT_() or N_() -- the former in function arguments, the latter in static initializers and other non-function-argument contexts.

I have not performed any translations for the program. That is something I hope to do later.

Lessons learned

Write once, compile everywhere, debug everywhere

To date TCPtty has only been tested on Redhat Linux 7.1 and FreeBSD 4.3. It appears to work on both. The testing process for a new distribution can be tedious. In the future I may develop a Java version of this utility.

Credits

Special thanks go to Eric Raymond, Richard Stevens (rest in peace), and others who provided solid examples of how to write portable code and how to package an open source project for distribution. Where possible these individuals have been acknowledged in the source. Other significant contributors to the code have included Dave Bodenstab (report.c code and --syslog).

Conclusion

This is the first release of TCPtty and it will likely undergo severe revision as I am sure people will find plenty of bugs and better ways to do things.

Stuart C. Eichert <tcptty@copera.com>
all rights reserved
copyright © copera 1999-2008