Advanced Programming in the
UNIX Environment

by W. Richard Stevens
Addison-Wesley Professional Computing Series
0-201-56317-7 * Hardcover * 768 pages * ©1992
[Buy this book]

Chapter 18. A Modem Dialer

Introduction * History * Program Design * Data Files * Server Design * Server Source Code * Client Design * Client Source Code * Summary

Example Relevant Functions
18.1 calld.h
Header for Modem-Dialer Unified Service
See below
18.2 main.c
The modem server main function
Get options, initialize daemon, request-loop.
18.3 loop.c
The main server loop:
Lock modem, serve client dial requests, and
hand-back modem full-duplex descriptor
to client.
signal_intr (Stevens' lib),
log_sys, log_msg, log_quit (Stevens' lib),
serv_listen (Stevens' func),
strcpy, select, read,
serv_accept (Stevens' func),
client_add, client_del (Stevens' func),
lock_rel (Stevens' func),
request (Stevens' func),
send_err (Stevens' func),
18.4 cli_args
Process client arguments
strcmp, strcpy, sprintf,
getopt, optind, opterr,
18.5 client.c
Functions to manipulate the client array.
(Client bookkeeping in the modem server)
client_alloc, client_add,
client_del, client_sigchld
malloc, realloc,
err_sys, log_quit (Stevens' lib)
18.6 lock.c
Functions for managing client device locks
strcmp, strcpy, malloc, realloc,
err_sys, log_msg (Stevens' lib),
18.7 sysfile.c
Handle UUCP style Systems file
fopen, fgets, strtok,
log_sys, log_quit (Stevens' lib),
ftell, rewind, fseek
18.8 devfile.c
Handle UUCP style Devices file
fopen, fgets, strtok,
log_sys, log_quit (Stevens' lib),
rewind, strcmp, sprintf
18.9 dialfile.c
Handle UUCP style Dialers file
fopen, fgets, strtok,
log_sys, log_quit (Stevens' lib),
rewind, strcmp, sprintf
18.10 request
Client request function
sys_posn, sys_next, child_dial (Stevens' func),
DEBUG, is_locked, lock_set (Stevens' func),
dev_find (Stevens' func),
strcmp, sprintf, fork,
TELL_WAIT, TELL_CHILD (Stevens' lib),
WAIT_PARENT, log_sys (Stevens' lib),
18.11 sig_chld
The SIGCHLD signal handler
waitpid client_sigchld log_sys (Stevens' lib),
log_msg (Stevens' lib)
18.12 childdial.c
Client dialing function
Done in child process
DEBUG (Stevens' func),
tty_open, tty_dial, dial_find (Stevens' func),
send_fd, log_sys, writen (Stevens' lib),
strcmp, strlen
18.13 debug.c
Debugging functions:
va_start, va_end, vsprintf, strlen,
log_sys, writen (Stevens' lib),
18.14 tty_open
Open modem device or direct connect device,
set tty modes based on Devices entry.
strcmp, strcpy,
strcat, sprintf, open,
isatty, tcgetattr, tcsetattr,
cfsetispeed, cfsetospeed,
clr_fl (Stevens' lib)
18.15 tty_dial
Modem dialing function
expect_str, send_str (Stevens' func)
18.16 calld/sendstr.c
Send string to modem
DEBUG, DEBUG_NONL (Stevens' funcs),
read, write,
log_sys (Stevens' lib)
18.17 ctl_str
convert CTRL char to printable string
18.18 expect_str
Parse expect strings from modem.
strcmp, strncmp, strlen,
sprintf, signal, alarm, read,
log_quit, log_sys (Stevens' lib),
DEBUG (Stevens' func)
18.19 The Client: call.h
Client side Interface header file
See below
18.20 main.c
Client main program: asks the server
to dial and connect to the remote system
and then loops multiplexing on input
and output streams to/from remote.
getopt, optind, opterr,
call.c (Stevens' func.),
strcat, printf, atexit, exit,
tty_raw, err_sys (Stevens' lib),
loop (main client loop)
18.21 call
Client: Setup the call
request server to establish connection
and get back file descriptor to talk to
remote via the modem.
cli_conn (Stevens' func.),
strlen, writev,
err_sys, recv_fd (Stevens' lib)
18.22 loop
Client: main loop
Multiplex I/O to/from modem and to/from
user terminal (4 streams in total)
Implementation using poll(2).
setbuf, poll, read,
err_sys (Stevens' lib),
doescape (Stevens' func),
writen (Stevens' lib),
18.23 doescape
Handles escape characters from user
(requiring out-of-band special handling).
read, write,
err_sys, tty_reset, tty_raw (Stevens' lib),
getpid, kill,
take, put (Stevens' func)
18.24 take
Get a filename to copy (src, dest)
Using the escape mechanism, and then
Copy the file from remote to local
prompt_read (Stevens' func),
printf, fopen,
err_ret, err_sys (Stevens' lib),
putc, fflush, sprintf,
strlen, write,
ferror, fclose, read
18.25 take_put_args, prompt_read
User prompting, getting args
via the out-of-band escape mechanism.
tty_reset, tty_raw, err_sys (Stevens' lib),
strlen, write, read,
buf_args (Stevens' func),
18.26 put
Copy file from local to remote.
prompt_read (Stevens' func),
printf, fopen,
err_ret, err_sys (Stevens' lib),
putc, fflush, sprintf, strlen, write,
tcdrain, sleep, getc,
tty_termios (Stevens' lib),
tcflush, ferror, fclose

[Buy this book]