pty handling

pty handling

Post by Manousaridis Aggel » Tue, 24 Apr 2001 23:05:06



I am developing a programm that sniffs a serial port.
My idea was to create e pty pair, bound my application to the master side,
and to my serial device (/dev/ttySX), and copy data from one side to another
and vice-versa (while doing some editing on the fly).
Up until now, I had a success, i am able to connect using pppd (the device is
an NT, which acts like a modem - async PPP).

the problem I am facing now is this.
an application connects to the slave side ( open(/dev/ttyXX ), does some
reads/writes and closes.
when the application closes, my read() call on the master side fails with
Input/Output error, which is a bad thing (TM) because my infinite read/write
loop floods the other side.

Apparently during the close() call on the slave side, something happens to the
master side also. What system call shall i use to avoid this?

I open the master side with:

fd = open(dev, O_RDWR);

and then call the following code:

int set_ptymaster(int fd)
{
 struct termios setme;

 if ( tcgetattr(fd,&setme)<0 )
        return -1;

 setme.c_iflag = 0;
 setme.c_oflag = 0;
 setme.c_cflag &= ~(CSIZE | PARENB | CSTOPB);
 setme.c_cflag |= CS8 | CREAD | HUPCL;
 setme.c_lflag &= ~(ICANON | ECHO | ECHONL);
 setme.c_cc[VTIME] = 0;
 setme.c_cc[VMIN] = 1;

 return tcsetattr(fd,TCSANOW,&setme);

Quote:}

--
Aggelos Manousarides
 
 
 

1. pty handling

I am developing a programm that sniffs a serial port.
My idea was to create e pty pair, bound my application to the master side,
and to my serial device (/dev/ttySX), and copy data from one side to another
and vice-versa (while doing some editing on the fly).
Up until now, I had a success, i am able to connect using pppd (the device is
an NT, which acts like a modem - async PPP).

the problem I am facing now is this.
an application connects to the slave side ( open(/dev/ttyXX ), does some
reads/writes and closes.
when the application closes, my read() call on the master side fails with
Input/Output error, which is a bad thing (TM) because my infinite read/write
loop floods the other side.

Apparently during the close() call on the slave side, something happens to the
master side also. What system call shall i use to avoid this?

I open the master side with:

fd = open(dev, O_RDWR);

and then call the following code:

int set_ptymaster(int fd)
{
 struct termios setme;

 if ( tcgetattr(fd,&setme)<0 )
        return -1;

 setme.c_iflag = 0;
 setme.c_oflag = 0;
 setme.c_cflag &= ~(CSIZE | PARENB | CSTOPB);
 setme.c_cflag |= CS8 | CREAD | HUPCL;
 setme.c_lflag &= ~(ICANON | ECHO | ECHONL);
 setme.c_cc[VTIME] = 0;
 setme.c_cc[VMIN] = 1;

 return tcsetattr(fd,TCSANOW,&setme);

PS: I have read the FAQ section about terminal handling, but I could find
something related, neither in the "What is a pty" question

--
Aggelos Manousarides

2. Statistics show there's *no* SuSE and Red Hat users on this world!

3. UNIX pty handling

4. Cannot Login User

5. Bug in PTY handling

6. total installed memory from kstat

7. How do I get pty's to handle BS correctly in AIX 1.2 ?

8. Error Message: Kernel panic: VFS Unable to mount root fs on 08:01

9. PTY Limit/New PTY Creation

10. Q: Handling large mail loads....how to distribute mail handling??

11. expect problem: out of pty's

12. MAKEDEV/KERNEL > 64 ptys

13. Increasing pty without reboot