Installation guide

Example D–2 demonstrates how a DIGITAL UNIX application interacts
with a modem for outgoing calls. Error checking of the return values of the
system calls is purposely omitted to simplify the example.
Example D–2: Modem Control for Outgoing Calls (DIGITAL UNIX)
int fd, flags;
struct termios tty_termios;
1
fd = open(ttyname,O_RDWR | O_NONBLOCK); 2
tcgetattr(fd,&tty_termios); 3
if ((tty_termios.c_cflag & CLOCAL) == 0) {
tty_termios.c_cflag |= CLOCAL;
4
tcsetattr(fd,TCSANOW,&tty_termios);
}
flags = fcntl(fd, F_GETFL)
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK)
5
.
.
.
/*
* dial phone number and negotiate with modem.
*/
.
.
.
tty_termios.c_cflag &= ~CLOCAL;
6
tcsetattr(fd,&tty_termios); 7
alarm(40); 8
read(fd,buffer,count); 9
alarm(0); 10
1 Contains information about the serial line that can be inspected and
altered using the POSIX tcgetattr() and tcsetattr() library
routines.
2 Opens the terminal line. The CLOCAL flag is usually set by default,
allowing you to ignore modem status lines. Use O_NONBLOCK in case
CLOCAL is not set.
3 Gets current line attributes.
4 Sets CLOCAL, if it is not set. The line must be in local mode in order
to talk to the modem.
5 Turns off O_NONBLOCK; in local mode the application does not need
it.
6 Puts the line into modem mode by turning off CLOCAL. The next I/O
operation to the line will block until carrier is present.
7 Watches for modem signals.
8 Sets a timer so the application does not wait forever.
D–2 Differences Between DIGITAL UNIX and ULTRIX Terminal Modem Control