termios vs. ioctl (SunOS 4.1.1)

termios vs. ioctl (SunOS 4.1.1)

Post by Mike St » Thu, 31 Dec 1992 00:14:26

I would like to know what the equivalent code using struct termios
would be for:

  struct sgttyb sg;
  ioctl(fd, TIOCGETP, &sg);
  sg.sg_flags = O_RAW;
  ioctl(fd, TIOCSETP, &sg);

The following fragment comes pretty close, but isn't exactly the same

  tcgetattr (fd, &termios);
  termios.c_iflag &= ~(BRKINT | ISTRIP | IMAXBEL);
  termios.c_oflag &= ~(PARENB | CSIZE);
  termios.c_oflag |= CS8;
  termios.c_iflag &= ~(ICRNL | IXON);
  termios.c_lflag &= ~(ISIG | ICANON | ECHO);
  tcsetattr (fd, TCSANOW, &termios);

Any suggestions would be most welcome (having zipped through various
bits of TFM several times...)

The "usual disclaimers" apply.    |
Mike Stok                         |

Meiko tel: (617) 890 7676         |


1. termios vs. linux/termios

Hi folks,

for a toy project of mine, I need to query the states of the modem lines
of the serial ports. I found that


does this on fd opened for a serial tty (e.g. /dev/ttyS0). However,

1) which header file would I have to include to get this? My "educated guess"
was that for that I would need to include "linux/termios.h", but it cludges
with "sys/ioctl" which I also need for the ioctl prototypes. Now, strange
enough, asm/termios.h (included by linux/termios.h) and bits/termios.h
(included by termios.h) both define a "struct termios", but a different one.
Is this "desired"

2) ? I currently switched to including "asm/ioctls.h" instead of
"linux/termios.h", though I feel a bit suspicious about this header. Looks kinna
like "internal use only" for me.

3) The above ioctl does not include any kind of "direction hints" that would
be useful for debugging purposes (see asm/ioctl.h). Is this desired?

4) Is there a more portable way of obtaining the states of the serial port?
(expecting the answer "no" ;-)

5) Is there any documentation about the ioctl's of the /dev/ttyS0 except the
kernel sources (drivers/char/serial.c)? Especially, I would need to know
whether the above ioctl is even "open" for public usage. If not, what would be
an alternative?


2. Secondary Audio (SAP) in video4linux

3. SunOS 5.6, Serial ports, ioctl(), and C vs. C++

4. Linux 2.4.19-pre5

5. SunOS 5.6 vs Solaris 2.6 vs Solaris 7 vs Solaris 8

6. INN with gcc, and sol 2.4?

7. termios or ioctl - Which one should I use?

8. journyx Time v2.2.1 released for AIX

9. conflicts in termios.h and ioctl.h

10. iBCS2, 1.1.72, and libc 4.6.27: BSD: termios ioctl xxxx unsupported

11. ioctl and termios

12. Termio(s?) under SunOS 4.1.3

13. Termios question: Semantics of VMIN/VTIME on Linux/SunOS ?