PPP Tools

Contents:

Dial-Up IP
The PPP Daemon
chat

This appendix is a reference for dip, pppd, and chat. These tools are used to create dial-up IP connections for the Point-to-Point Protocol (PPP). dip and chat are both scripting languages. Creating a script that initializes the modem, dials the remote server, logs in, and configures the remote server is the biggest task in configuring a PPP connection. "Configuring the Interface " provides examples and tutorial information about all three of the programs covered here. This appendix provides a reference to the programs.

Dial-Up IP

dip is a scripting tool designed specifically for creating SLIP and PPP connections.[156]

[156]Serial Line IP (SLIP) predates PPP. Today most serial connections are PPP, which is what this appendix emphasizes.

The syntax of the dip command is:

dip [options] [scriptfile]

The dip command is invoked with an option set, a script file specified, or both. When scriptfile is specified, dip executes the commands contained in the script file to create a point-to-point connection. Examples of scripts and dip are shown in "Configuring the Interface ". The options valid with script files are:

The other dip command-line options are:

diplogin and diplogini are used only on servers and are not used with a script file. The script file is used on the PPP clients when dip is configured to dial into a remote server. The script file contains the instructions used to do this.

The dip Script File

The script file is made up of comments, labels, variables, and commands. Any line that begins with a sharp sign (#) is a comment. A label is a line that contains only a string ending in a colon. Labels are used to divide the script into separate procedures. For example, the section of the script that dials the remote host might begin with the label:

Dial-in:

A variable stores a value. A variable name is a string that begins with a dollar sign ($). You might, for example, create a variable to hold a loop counter and give it the name $loopcntr. It is possible to create your own variables, but this is rarely done. The variables that are used in most scripts are the special variables defined by dip. Table A-1 lists the special variables and the value that each holds.

Table A-1. dip special variables

Variable Value stored
$errlvl The return code of the last command
$locip The IP address of the local host
$local The fully qualified domain name of the local host
$rmtip The IP address of the remote host
$remote The fully qualified domain name of the remote host
$mtu The maximum transmission unit in bytes
$modem The modem type; currently this must be HAYES
$port The name of the serial device, e.g., cua0
$speed The transmission speed of the port

The final component of the script file is the command list. There are many script commands. Because this appendix is a reference, we cover them all. However, most scripts are built using only a few of these commands. See the sample scripts in "Configuring the Interface " and at the end of this section for realistic dip scripts. The complete list of script commands is:

In the next section we put some of these commands to work in a realistic script.

A sample dip script

This script is based on the PPP sample from "Configuring the Interface ". Labels and error detection have been added to create a more robust script.

# Select configuration settings 
 setup: 
 # Ask PPP to provide the addresses 
 get $local 0.0.0.0 
 # Select the port 
 port cua1 
 # Set the port speed 
 speed 57600 
 # Create a loop counter 
 get $loopcntr 0 # Dial the remote server 
 dialin: 
 # Reset the modem and clear the input buffer 
 reset 
 flush 
 # Dial the PPP server and check the modem response 
 dial *70,301-555-1234 
 # If BUSY, dial again 
 if $errlvl == 3 goto redial 
 # If some other error, abort 
 if $errlvl != 1 goto dial-error 
 # Otherwise rest loop counter 
 get $loopcntr 0 
 # Give the server 2 seconds to get ready 
 sleep 2 # Login to the remote server 
 login: 
 # Send a carriage-return to wake up the server 
 send \r 
 # Wait for the Username> prompt and send the username 
 wait name> 20 
 if $errlvl != 0 goto try-again 
 send kristin\r 
 # Wait for the Password> prompt and send the password 
 wait word> 10 
 if $errlvl != 0 goto server-failure 
 password 
 # Wait for the PPP server's command-line prompt 
 wait > 20 
 if $errlvl != 0 goto server-failure 
 # Send the command required by the PPP server 
 send ppp enabled\r # Success! We're on-line 
 connected: 
 # Set the interface to PPP mode 
 mode PPP 
 # Exit the script 
 exit # Error processing routines # Try dialing 3 times. Wait 5 seconds between attempts 
 redial: 
 inc $loopcntr 
 if $loopcntr > 3 goto busy-failure 
 sleep 5 
 goto dialin # Try a second carriage return 
 try-again: 
 inc $loopcntr 
 if $loopcntr > 1 goto server-failure 
 goto login 
 dial-error: 
 print Dial up of $remote failed. 
 quit server-failure: 
 print $remote failed to respond. 
 quit busy-failure: 
 print $remote is busy. Try again later.
 quit

This script provides a realistic example of the commands used in most scripts. However, you may encounter a particularly tough scripting problem. If you do, the abundance of scripting commands available with dip should be able to handle it. If dip can't do the job, try expect. See Exploring Expect by Don Libes (Anonymous) for a full description of the expect scripting language.