Next Previous Contents

4. Understanding the solution

4.1 Opening two connections

The most obvious way of building a wrapper is to launch a telnet session in the ``background'', to which the pppd would connect. But how can you do it so the telnet session be controlled by a tty in which the pppd also runs, with crossed output and input? The solution is to use the zsh coproc feature, with which you can have a concurrent processe whose input and output you can control with a pair of pipes. However, because pppd insists on having a tty, not a pair of pipes, we need a tty emulator for pppd, too.

The very same solution applies again, which is also the only portable one, that is, is telnet as a tty emulator. So we'll open a local telnet connection as a zsh coproc, in which we'll run the pppd.p We then launch a remote telnet connection as the "normal" zsh computation, with I/O crossed with the local connection, so that they talk to each other. But before we can connect the crossed I/O pipes, we must make sure both sessions are synchronized to the same PPP emulation state, rather than waiting for shell commands.

4.2 Synchronization

First, the mother process launches the local connection, starts a fwprc with local options, and waits for the local fwprca to send cookie. Then it launches the remote connection, starts a fwprc with remote options, and connects I/O. The local connection will wait for the remote connection to send its cookie. When both cookies are received, the handshake is achieved, and IP emulators are run on both sides.

Synchronization is achieved by exchanging obfuscated cookies whose probability of appearing unexpectedly are close to nothing. During a synchronization step, the waiting side flushes the output of the other side until it finds the expected cookie.


Next Previous Contents