pty.c in 4.1BSD ?

Steve Dyer sdyer at bbncca.ARPA
Fri Mar 23 11:52:59 AEST 1984


The pty driver is a hack to allow a user-mode process to present a TTY
interface to another program.  It was used by the old ARPAnet NCP Telnet
protocol, and most recently by the 4.1BSD/BBN TCP/IP Telnet protocols.

The model is as follows:

___________      _________________
| Network | <--> | Telnet Server | <---> /dev/ptcN  :c:l:i:s:t:s /dev/ptyN <--> SH
-----------      -----------------

Essentially, the telnet server reads characters from the network, and
writes them to the PTY controller (here, /dev/ptcN.) This action is
analogous to a DH or DZ interrupt routine, in that it puts characters on
the terminal's input queue (here, the PTY "slave", /dev/ptyN).  The user
program (here, SH) will then receive them, by reading from its standard
input.  In the same way, when the user program writes to its standard
output (also open on /dev/ptyN), the telnet server will be able to read
those characters from the corresponding pty controller device, and then
write them onto the network connection.  This is roughly analogous to the
"output interrupt" processing of a DH or DZ.  The key is that this "server" 
can do anything it likes to the characters it reads or writes on the
controller.  Here, it is essentially a pass-thru (excepting the minor Telnet
negotiations and protocol) serving merely to hook up a network connection
to the UNIX model of a TTY.  The PTY "slave" looks exactly like any TTY to
the process which has it open, and indeed, one would usually enter such
pseudo-TTY's into the /etc/ttys file.  Virtual carrier is set when the
corresponding controller device is opened.

You could, instead, use the PTY's for anything you like, not necessarily
a network.  I once wrote a special filter for someone who had a DG "Dasher"
terminal which went wild when it was sent ^H characters.  We set her shell
to read from a pseudo-TTY, and the process reading and writing on the
controller mapped the characters appropriately.
-- 
/Steve Dyer
{decvax,linus,ima}!bbncca!sdyer
sdyer at bbncca.ARPA



More information about the Comp.unix mailing list