1 /***********************************************************************
5 * Code for dealing with pseudo-tty's for running pppd.
7 * Copyright (C) 2002 Roaring Penguin Software Inc.
9 * This software may be distributed under the terms of the GNU General
10 * Public License, Version 2, or (at your option) any later version.
14 ***********************************************************************/
16 static char const RCSID
[] =
17 "$Id: pty.c,v 1.1.48.1 2005/08/08 12:05:25 honor Exp $";
20 #include <sys/ioctl.h>
25 #include <linux/termios.h>
28 /**********************************************************************
31 * mfp -- pointer to master file descriptor
32 * sfp -- pointer to slave file descriptor
34 * 0 on success, -1 on failure
36 * Opens a PTY and sets line discipline to N_HDLC for ppp.
37 * Taken almost verbatim from Linux pppd code.
38 ***********************************************************************/
40 pty_get(int *mfp
, int *sfp
)
50 mfd
= open("/dev/ptmx", O_RDWR
);
53 if (ioctl(mfd
, TIOCGPTN
, &ptn
) >= 0) {
54 snprintf(pty_name
, sizeof(pty_name
), "/dev/pts/%d", ptn
);
56 if (ioctl(mfd
, TIOCSPTLCK
, &ptn
) < 0) {
57 /* warn("Couldn't unlock pty slave %s: %m", pty_name); */
59 if ((sfd
= open(pty_name
, O_RDWR
| O_NOCTTY
)) < 0) {
60 /* warn("Couldn't open pty slave %s: %m", pty_name); */
65 if (sfd
< 0 || mfd
< 0) {
66 if (sfd
>= 0) close(sfd
);
67 if (mfd
>= 0) close(mfd
);
73 if (tcgetattr(sfd
, &tios
) == 0) {
74 tios
.c_cflag
&= ~(CSIZE
| CSTOPB
| PARENB
);
75 tios
.c_cflag
|= CS8
| CREAD
| CLOCAL
;
76 tios
.c_iflag
= IGNPAR
;
79 tcsetattr(sfd
, TCSAFLUSH
, &tios
);
81 if (ioctl(sfd
, TIOCSETD
, &disc
) < 0) {
82 l2tp_set_errmsg("Unable to set line discipline to N_HDLC");
88 if (ioctl(mfd
, TIOCSETD
, &disc
) < 0) {
89 l2tp_set_errmsg("Unable to set line discipline to N_HDLC");