]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - man2/ioctl_tty.2
Many pages: Use \[ti] instead of \(ti
[thirdparty/man-pages.git] / man2 / ioctl_tty.2
index 04fa9f9b3438f858c0a1280895b8800d743d9e69..8d2f08242f0d1b700b44b8de4a8a3f795c275652 100644 (file)
@@ -1,17 +1,25 @@
+'\" t
 .\" Copyright 2002 Walter Harms <walter.harms@informatik.uni-oldenburg.de>
 .\" and Andries Brouwer <aeb@cwi.nl>.
 .\"
-.\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
-.\" Distributed under GPL
-.\" %%%LICENSE_END
+.\" SPDX-License-Identifier: GPL-1.0-or-later
 .\"
-.TH IOCTL_TTY 2 2020-06-09 "Linux" "Linux Programmer's Manual"
+.TH ioctl_tty 2 (date) "Linux man-pages (unreleased)"
 .SH NAME
 ioctl_tty \- ioctls for terminals and serial lines
+.SH LIBRARY
+Standard C library
+.RI ( libc ", " \-lc )
 .SH SYNOPSIS
-.B "#include <termios.h>"
+.nf
+.B #include <sys/ioctl.h>
+.BR "#include <asm/termbits.h>" "   /* Definition of " "struct termios" ,
+.BR    "                               struct termios2" ", and"
+.BR    "                               Bnnn" ", " BOTHER ", " CBAUD ", " CLOCAL ,
+.BR    "                               TC*" { FLUSH , ON , OFF "} and other constants */"
 .PP
 .BI "int ioctl(int " fd ", int " cmd ", ...);"
+.fi
 .SH DESCRIPTION
 The
 .BR ioctl (2)
@@ -22,56 +30,114 @@ or
 .IR arg .
 .PP
 Use of
-.I ioctl
+.BR ioctl ()
 makes for nonportable programs.
 Use the POSIX interface described in
 .BR termios (3)
 whenever possible.
+.PP
+Please note that
+.B struct termios
+from
+.I <asm/termbits.h>
+is different and incompatible with
+.B struct termios
+from
+.IR <termios.h> .
+These ioctl calls require
+.B struct termios
+from
+.IR <asm/termbits.h> .
 .SS Get and set terminal attributes
 .TP
-.BI "TCGETS    struct termios *" argp
+.B TCGETS
+Argument:
+.BI "struct termios\~*" argp
+.IP
 Equivalent to
 .IR "tcgetattr(fd, argp)" .
-.br
+.IP
 Get the current serial port settings.
 .TP
-.BI "TCSETS    const struct termios *" argp
+.B TCSETS
+Argument:
+.BI "const struct termios\~*" argp
+.IP
 Equivalent to
 .IR "tcsetattr(fd, TCSANOW, argp)" .
-.br
+.IP
 Set the current serial port settings.
 .TP
-.BI "TCSETSW   const struct termios *" argp
+.B TCSETSW
+Argument:
+.BI "const struct termios\~*" argp
+.IP
 Equivalent to
 .IR "tcsetattr(fd, TCSADRAIN, argp)" .
-.br
+.IP
 Allow the output buffer to drain, and
 set the current serial port settings.
 .TP
-.BI "TCSETSF   const struct termios *" argp
+.B TCSETSF
+Argument:
+.BI "const struct termios\~*" argp
+.IP
 Equivalent to
 .IR "tcsetattr(fd, TCSAFLUSH, argp)" .
-.br
+.IP
 Allow the output buffer to drain, discard pending input, and
 set the current serial port settings.
 .PP
+The following four ioctls, added in Linux 2.6.20,
+.\" commit 64bb6c5e1ddcd47c951740485026ef08975ee2e6
+.\" commit 592ee3a5e5e2a981ef2829a0380093006d045661
+are just like
+.BR TCGETS ,
+.BR TCSETS ,
+.BR TCSETSW ,
+.BR TCSETSF ,
+except that they take a
+.I "struct termios2\~*"
+instead of a
+.IR "struct termios\~*" .
+If the structure member
+.B c_cflag
+contains the flag
+.BR BOTHER ,
+then the baud rate is stored in the structure members
+.B c_ispeed
+and
+.B c_ospeed
+as integer values.
+These ioctls are not supported on all architectures.
+.RS
+.TS
+lb l.
+TCGETS2        \fBstruct termios2 *\fPargp
+TCSETS2        \fBconst struct termios2 *\fPargp
+TCSETSW2       \fBconst struct termios2 *\fPargp
+TCSETSF2       \fBconst struct termios2 *\fPargp
+.TE
+.RE
+.PP
 The following four ioctls are just like
 .BR TCGETS ,
 .BR TCSETS ,
 .BR TCSETSW ,
 .BR TCSETSF ,
 except that they take a
-.I "struct termio\ *"
+.I "struct termio\~*"
 instead of a
-.IR "struct termios\ *" .
-.IP
-.BI "TCGETA    struct termio *" argp
-.IP
-.BI "TCSETA    const struct termio *" argp
-.IP
-.BI "TCSETAW   const struct termio *" argp
-.IP
-.BI "TCSETAF   const struct termio *" argp
+.IR "struct termios\~*" .
+.RS
+.TS
+lb l.
+TCGETA \fBstruct termio *\fPargp
+TCSETA \fBconst struct termio *\fPargp
+TCSETAW        \fBconst struct termio *\fPargp
+TCSETAF        \fBconst struct termio *\fPargp
+.TE
+.RE
 .SS Locking the termios structure
 The
 .I termios
@@ -81,31 +147,40 @@ The lock is itself a
 structure, with nonzero bits or fields indicating a
 locked value.
 .TP
-.BI "TIOCGLCKTRMIOS    struct termios *" argp
+.B TIOCGLCKTRMIOS
+Argument:
+.BI "struct termios\~*" argp
+.IP
 Gets the locking status of the
 .I termios
 structure of the terminal.
 .TP
-.BI "TIOCSLCKTRMIOS    const struct termios *" argp
+.B TIOCSLCKTRMIOS
+Argument:
+.BI "const struct termios\~*" argp
+.IP
 Sets the locking status of the
 .I termios
 structure of the terminal.
 Only a process with the
-.BR CAP_SYS_ADMIN
+.B CAP_SYS_ADMIN
 capability can do this.
 .SS Get and set window size
 Window sizes are kept in the kernel, but not used by the kernel
 (except in the case of virtual consoles, where the kernel will
 update the window size when the size of the virtual console changes,
 for example, by loading a new font).
-.PP
-The following constants and structure are defined in
-.IR <sys/ioctl.h> .
 .TP
-.BI "TIOCGWINSZ        struct winsize *" argp
+.B TIOCGWINSZ
+Argument:
+.BI "struct winsize\~*" argp
+.IP
 Get window size.
 .TP
-.BI "TIOCSWINSZ        const struct winsize *" argp
+.B TIOCSWINSZ
+Argument:
+.BI "const struct winsize\~*" argp
+.IP
 Set window size.
 .PP
 The struct used by these ioctls is defined as
@@ -127,10 +202,13 @@ signal is sent to the
 foreground process group.
 .SS Sending a break
 .TP
-.BI "TCSBRK    int " arg
+.B TCSBRK
+Argument:
+.BI "int " arg
+.IP
 Equivalent to
 .IR "tcsendbreak(fd, arg)" .
-.br
+.IP
 If the terminal is using asynchronous serial data transmission, and
 .I arg
 is zero, then send a break (a stream of zero bits) for between
@@ -142,7 +220,7 @@ When
 .I arg
 is nonzero, nobody knows what will happen.
 .IP
-(SVr4, UnixWare, Solaris, Linux treat
+(SVr4, UnixWare, Solaris, and Linux treat
 .I "tcsendbreak(fd,arg)"
 with nonzero
 .I arg
@@ -160,25 +238,37 @@ DG/UX and AIX treat
 HP-UX ignores
 .IR arg .)
 .TP
-.BI "TCSBRKP   int " arg
+.B TCSBRKP
+Argument:
+.BI "int " arg
+.IP
 So-called "POSIX version" of
 .BR TCSBRK .
 It treats nonzero
 .I arg
-as a timeinterval measured in deciseconds, and does nothing
+as a time interval measured in deciseconds, and does nothing
 when the driver does not support breaks.
 .TP
-.B "TIOCSBRK   void"
+.B TIOCSBRK
+Argument:
+.B void
+.IP
 Turn break on, that is, start sending zero bits.
 .TP
-.B "TIOCCBRK   void"
+.B TIOCCBRK
+Argument:
+.B void
+.IP
 Turn break off, that is, stop sending zero bits.
 .SS Software flow control
 .TP
-.BI "TCXONC    int " arg
+.B TCXONC
+Argument:
+.BI "int " arg
+.IP
 Equivalent to
 .IR "tcflow(fd, arg)" .
-.br
+.IP
 See
 .BR tcflow (3)
 for the argument values
@@ -188,43 +278,78 @@ for the argument values
 .BR TCION .
 .SS Buffer count and flushing
 .TP
-.BI "FIONREAD  int *" argp
+.B FIONREAD
+Argument:
+.BI "int\~*" argp
+.IP
 Get the number of bytes in the input buffer.
 .TP
-.BI "TIOCINQ   int *" argp
+.B TIOCINQ
+Argument:
+.BI "int\~*" argp
+.IP
 Same as
 .BR FIONREAD .
 .TP
-.BI "TIOCOUTQ  int *" argp
+.B TIOCOUTQ
+Argument:
+.BI "int\~*" argp
+.IP
 Get the number of bytes in the output buffer.
 .TP
-.BI "TCFLSH    int " arg
+.B TCFLSH
+Argument:
+.BI "int " arg
+.IP
 Equivalent to
 .IR "tcflush(fd, arg)" .
-.br
+.IP
 See
 .BR tcflush (3)
 for the argument values
 .BR TCIFLUSH ,
 .BR TCOFLUSH ,
 .BR TCIOFLUSH .
+.TP
+.B TIOCSERGETLSR
+Argument:
+.BI "int\~*" argp
+.IP
+Get line status register.
+Status register has
+.B TIOCSER_TEMT
+bit set when
+output buffer is empty and also hardware transmitter is physically empty.
+.IP
+Does not have to be supported by all serial tty drivers.
+.IP
+.BR tcdrain (3)
+does not wait and returns immediately when
+.B TIOCSER_TEMT
+bit is set.
 .SS Faking input
 .TP
-.BI "TIOCSTI   const char *" argp
+.B TIOCSTI
+Argument:
+.BI "const char\~*" argp
+.IP
 Insert the given byte in the input queue.
 .SS Redirecting console output
 .TP
-.B "TIOCCONS   void"
+.B TIOCCONS
+Argument:
+.B void
+.IP
 Redirect output that would have gone to
 .I /dev/console
 or
 .I /dev/tty0
 to the given terminal.
 If that was a pseudoterminal master, send it to the slave.
-In Linux before version 2.6.10,
+Before Linux 2.6.10,
 anybody can do this as long as the output was not redirected yet;
-since version 2.6.10, only a process with the
-.BR CAP_SYS_ADMIN
+since Linux 2.6.10, only a process with the
+.B CAP_SYS_ADMIN
 capability may do this.
 If output was redirected already, then
 .B EBUSY
@@ -237,7 +362,10 @@ or
 .IR /dev/tty0 .
 .SS Controlling terminal
 .TP
-.BI "TIOCSCTTY int " arg
+.B TIOCSCTTY
+Argument:
+.BI "int " arg
+.IP
 Make the given terminal the controlling terminal of the calling process.
 The calling process must be a session leader and not have a
 controlling terminal already.
@@ -249,13 +377,16 @@ If this terminal is already the controlling terminal
 of a different session group, then the ioctl fails with
 .BR EPERM ,
 unless the caller has the
-.BR CAP_SYS_ADMIN
+.B CAP_SYS_ADMIN
 capability and
 .I arg
 equals 1, in which case the terminal is stolen, and all processes that had
 it as controlling terminal lose it.
 .TP
-.B "TIOCNOTTY  void"
+.B TIOCNOTTY
+Argument:
+.B void
+.IP
 If the given terminal was the controlling terminal of the calling process,
 give up this controlling terminal.
 If the process was session leader,
@@ -267,19 +398,31 @@ to the foreground process group
 and all processes in the current session lose their controlling terminal.
 .SS Process group and session ID
 .TP
-.BI "TIOCGPGRP pid_t *" argp
+.B TIOCGPGRP
+Argument:
+.BI "pid_t\~*" argp
+.IP
 When successful, equivalent to
 .IR "*argp = tcgetpgrp(fd)" .
-.br
+.IP
 Get the process group ID of the foreground process group on this terminal.
 .TP
-.BI "TIOCSPGRP const pid_t *" argp
+.B TIOCSPGRP
+Argument:
+.BI "const pid_t\~*" argp
+.IP
 Equivalent to
 .IR "tcsetpgrp(fd, *argp)" .
-.br
+.IP
 Set the foreground process group ID of this terminal.
 .TP
-.BI "TIOCGSID  pid_t *" argp
+.B TIOCGSID
+Argument:
+.BI "pid_t\~*" argp
+.IP
+When successful, equivalent to
+.IR "*argp = tcgetsid(fd)" .
+.IP
 Get the session ID of the given terminal.
 This fails with the error
 .B ENOTTY
@@ -288,7 +431,10 @@ and not our controlling terminal.
 Strange.
 .SS Exclusive mode
 .TP
-.B "TIOCEXCL   void"
+.B TIOCEXCL
+Argument:
+.B void
+.IP
 Put the terminal into exclusive mode.
 No further
 .BR open (2)
@@ -296,10 +442,13 @@ operations on the terminal are permitted.
 (They fail with
 .BR EBUSY ,
 except for a process with the
-.BR CAP_SYS_ADMIN
+.B CAP_SYS_ADMIN
 capability.)
 .TP
-.BI "TIOCGEXCL int *" argp
+.B TIOCGEXCL
+Argument:
+.BI "int\~*" argp
+.IP
 (since Linux 3.8)
 If the terminal is currently in exclusive mode,
 place a nonzero value in the location pointed to by
@@ -307,18 +456,30 @@ place a nonzero value in the location pointed to by
 otherwise, place zero in
 .IR *argp .
 .TP
-.B "TIOCNXCL   void"
+.B TIOCNXCL
+Argument:
+.B void
+.IP
 Disable exclusive mode.
 .SS Line discipline
 .TP
-.BI "TIOCGETD  int *" argp
+.B TIOCGETD
+Argument:
+.BI "int\~*" argp
+.IP
 Get the line discipline of the terminal.
 .TP
-.BI "TIOCSETD  const int *" argp
+.B TIOCSETD
+Argument:
+.BI "const int\~*" argp
+.IP
 Set the line discipline of the terminal.
 .SS Pseudoterminal ioctls
 .TP
-.BI "TIOCPKT   const int *" argp
+.B TIOCPKT
+Argument:
+.BI "const int\~*" argp
+.IP
 Enable (when
 .RI * argp
 is nonzero) or disable packet mode.
@@ -328,21 +489,36 @@ otherwise).
 In packet mode, each subsequent
 .BR read (2)
 will return a packet that either contains a single nonzero control byte,
-or has a single byte containing zero (\(aq\0\(aq) followed by data
+or has a single byte containing zero (\[aq]\e0\[aq]) followed by data
 written on the slave side of the pseudoterminal.
 If the first byte is not
 .B TIOCPKT_DATA
 (0), it is an OR of one
 or more of the following bits:
 .IP
-.nf
-TIOCPKT_FLUSHREAD   The read queue for the terminal is flushed.
-TIOCPKT_FLUSHWRITE  The write queue for the terminal is flushed.
-TIOCPKT_STOP        Output to the terminal is stopped.
-TIOCPKT_START       Output to the terminal is restarted.
-TIOCPKT_DOSTOP      The start and stop characters are \fB^S\fP/\fB^Q\fP.
-TIOCPKT_NOSTOP      The start and stop characters are not \fB^S\fP/\fB^Q\fP.
-.fi
+.ad l
+.TS
+lb l.
+TIOCPKT_FLUSHREAD      T{
+The read queue for the terminal is flushed.
+T}
+TIOCPKT_FLUSHWRITE     T{
+The write queue for the terminal is flushed.
+T}
+TIOCPKT_STOP   T{
+Output to the terminal is stopped.
+T}
+TIOCPKT_START  T{
+Output to the terminal is restarted.
+T}
+TIOCPKT_DOSTOP T{
+The start and stop characters are \fB\(haS\fP/\fB\(haQ\fP.
+T}
+TIOCPKT_NOSTOP T{
+The start and stop characters are not \fB\(haS\fP/\fB\(haQ\fP.
+T}
+.TE
+.ad
 .IP
 While packet mode is in use, the presence
 of control status information to be read
@@ -359,29 +535,41 @@ This mode is used by
 and
 .BR rlogind (8)
 to implement a remote-echoed,
-locally \fB^S\fP/\fB^Q\fP flow-controlled remote login.
+locally \fB\(haS\fP/\fB\(haQ\fP flow-controlled remote login.
 .TP
-.BI "TIOCGPKT  const int *" argp
+.B TIOCGPKT
+Argument:
+.BI "const int\~*" argp
+.IP
 (since Linux 3.8)
 Return the current packet mode setting in the integer pointed to by
 .IR argp .
 .TP
-.BI "TIOCSPTLCK        int *" argp
+.B TIOCSPTLCK
+Argument:
+.BI "int\~*" argp
+.IP
 Set (if
-.IR *argp
+.I *argp
 is nonzero) or remove (if
-.IR *argp
+.I *argp
 is zero) the lock on the pseudoterminal slave device.
 (See also
 .BR unlockpt (3).)
 .TP
-.BI "TIOCGPTLCK        int *" argp
+.B TIOCGPTLCK
+Argument:
+.BI "int\~*" argp
+.IP
 (since Linux 3.8)
 Place the current lock state of the pseudoterminal slave device
 in the location pointed to by
 .IR argp .
 .TP
-.BI "TIOCGPTPEER       int " flags
+.B TIOCGPTPEER
+Argument:
+.BI "int " flags
+.IP
 .\" commit 54ebbfb1603415d9953c150535850d30609ef077
 (since Linux 4.13)
 Given a file descriptor in
@@ -411,39 +599,56 @@ The BSD ioctls
 .BR TIOCSTOP ,
 .BR TIOCSTART ,
 .BR TIOCUCNTL ,
+and
 .B TIOCREMOTE
 have not been implemented under Linux.
 .SS Modem control
 .TP
-.BI "TIOCMGET  int *" argp
+.B TIOCMGET
+Argument:
+.BI "int\~*" argp
+.IP
 Get the status of modem bits.
 .TP
-.BI "TIOCMSET  const int *" argp
+.B TIOCMSET
+Argument:
+.BI "const int\~*" argp
+.IP
 Set the status of modem bits.
 .TP
-.BI "TIOCMBIC  const int *" argp
+.B TIOCMBIC
+Argument:
+.BI "const int\~*" argp
+.IP
 Clear the indicated modem bits.
 .TP
-.BI "TIOCMBIS  const int *" argp
+.B TIOCMBIS
+Argument:
+.BI "const int\~*" argp
+.IP
 Set the indicated modem bits.
 .PP
 The following bits are used by the above ioctls:
 .PP
-.nf
-TIOCM_LE        DSR (data set ready/line enable)
-TIOCM_DTR       DTR (data terminal ready)
-TIOCM_RTS       RTS (request to send)
-TIOCM_ST        Secondary TXD (transmit)
-TIOCM_SR        Secondary RXD (receive)
-TIOCM_CTS       CTS (clear to send)
-TIOCM_CAR       DCD (data carrier detect)
-TIOCM_CD         see TIOCM_CAR
-TIOCM_RNG       RNG (ring)
-TIOCM_RI         see TIOCM_RNG
-TIOCM_DSR       DSR (data set ready)
-.fi
-.TP
-.BI "TIOCMIWAIT        int " arg
+.TS
+lb l.
+TIOCM_LE       DSR (data set ready/line enable)
+TIOCM_DTR      DTR (data terminal ready)
+TIOCM_RTS      RTS (request to send)
+TIOCM_ST       Secondary TXD (transmit)
+TIOCM_SR       Secondary RXD (receive)
+TIOCM_CTS      CTS (clear to send)
+TIOCM_CAR      DCD (data carrier detect)
+TIOCM_CD       see TIOCM_CAR
+TIOCM_RNG      RNG (ring)
+TIOCM_RI       see TIOCM_RNG
+TIOCM_DSR      DSR (data set ready)
+.TE
+.TP
+.B TIOCMIWAIT
+Argument:
+.BI "int " arg
+.IP
 Wait for any of the 4 modem bits (DCD, RI, DSR, CTS) to change.
 The bits of interest are specified as a bit mask in
 .IR arg ,
@@ -457,7 +662,10 @@ The caller should use
 .B TIOCGICOUNT
 to see which bit has changed.
 .TP
-.BI "TIOCGICOUNT       struct serial_icounter_struct *" argp
+.B TIOCGICOUNT
+Argument:
+.BI "struct serial_icounter_struct\~*" argp
+.IP
 Get counts of input serial line interrupts (DCD, RI, DSR, CTS).
 The counts are written to the
 .I serial_icounter_struct
@@ -468,13 +676,19 @@ Note: both 1->0 and 0->1 transitions are counted, except for
 RI, where only 0->1 transitions are counted.
 .SS Marking a line as local
 .TP
-.BI "TIOCGSOFTCAR      int *" argp
+.B TIOCGSOFTCAR
+Argument:
+.BI "int\~*" argp
+.IP
 ("Get software carrier flag")
 Get the status of the CLOCAL flag in the c_cflag field of the
 .I termios
 structure.
 .TP
-.BI "TIOCSSOFTCAR      const int *" argp
+.B TIOCSSOFTCAR
+Argument:
+.BI "const int\~*" argp
+.IP
 ("Set software carrier flag")
 Set the CLOCAL flag in the
 .I termios
@@ -504,7 +718,10 @@ ioctl, see
 .SS Kernel debugging
 .B "#include <linux/tty.h>"
 .TP
-.BI "TIOCTTYGSTRUCT    struct tty_struct *" argp
+.B TIOCTTYGSTRUCT
+Argument:
+.BI "struct tty_struct\~*" argp
+.IP
 Get the
 .I tty_struct
 corresponding to
@@ -534,7 +751,7 @@ The
 system call returns 0 on success.
 On error, it returns \-1 and sets
 .I errno
-appropriately.
+to indicate the error.
 .SH ERRORS
 .TP
 .B EINVAL
@@ -552,10 +769,12 @@ Insufficient permission.
 .SH EXAMPLES
 Check the condition of DTR on the serial port.
 .PP
+.\" SRC BEGIN (tiocmget.c)
 .EX
-#include <termios.h>
 #include <fcntl.h>
+#include <stdio.h>
 #include <sys/ioctl.h>
+#include <unistd.h>
 
 int
 main(void)
@@ -571,8 +790,110 @@ main(void)
     close(fd);
 }
 .EE
+.\" SRC END
+.PP
+Get or set arbitrary baudrate on the serial port.
+.PP
+.\" SRC BEGIN (tcgets.c)
+.EX
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <asm/termbits.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+int
+main(int argc, char *argv[])
+{
+#if !defined BOTHER
+    fprintf(stderr, "BOTHER is unsupported\en");
+    /* Program may fallback to TCGETS/TCSETS with Bnnn constants */
+    exit(EXIT_FAILURE);
+#else
+    /* Declare tio structure, its type depends on supported ioctl */
+# if defined TCGETS2
+    struct termios2 tio;
+# else
+    struct termios tio;
+# endif
+    int fd, rc;
+
+    if (argc != 2 && argc != 3 && argc != 4) {
+        fprintf(stderr, "Usage: %s device [output [input] ]\en", argv[0]);
+        exit(EXIT_FAILURE);
+    }
+
+    fd = open(argv[1], O_RDWR | O_NONBLOCK | O_NOCTTY);
+    if (fd < 0) {
+        perror("open");
+        exit(EXIT_FAILURE);
+    }
+
+    /* Get the current serial port settings via supported ioctl */
+# if defined TCGETS2
+    rc = ioctl(fd, TCGETS2, &tio);
+# else
+    rc = ioctl(fd, TCGETS, &tio);
+# endif
+    if (rc) {
+        perror("TCGETS");
+        close(fd);
+        exit(EXIT_FAILURE);
+    }
+
+    /* Change baud rate when more arguments were provided */
+    if (argc == 3 || argc == 4) {
+        /* Clear the current output baud rate and fill a new value */
+        tio.c_cflag &= \[ti]CBAUD;
+        tio.c_cflag |= BOTHER;
+        tio.c_ospeed = atoi(argv[2]);
+
+        /* Clear the current input baud rate and fill a new value */
+        tio.c_cflag &= \[ti](CBAUD << IBSHIFT);
+        tio.c_cflag |= BOTHER << IBSHIFT;
+        /* When 4th argument is not provided reuse output baud rate */
+        tio.c_ispeed = (argc == 4) ? atoi(argv[3]) : atoi(argv[2]);
+
+        /* Set new serial port settings via supported ioctl */
+# if defined TCSETS2
+        rc = ioctl(fd, TCSETS2, &tio);
+# else
+        rc = ioctl(fd, TCSETS, &tio);
+# endif
+        if (rc) {
+            perror("TCSETS");
+            close(fd);
+            exit(EXIT_FAILURE);
+        }
+
+        /* And get new values which were really configured */
+# if defined TCGETS2
+        rc = ioctl(fd, TCGETS2, &tio);
+# else
+        rc = ioctl(fd, TCGETS, &tio);
+# endif
+        if (rc) {
+            perror("TCGETS");
+            close(fd);
+            exit(EXIT_FAILURE);
+        }
+    }
+
+    close(fd);
+
+    printf("output baud rate: %u\en", tio.c_ospeed);
+    printf("input baud rate: %u\en", tio.c_ispeed);
+
+    exit(EXIT_SUCCESS);
+#endif
+}
+.EE
+.\" SRC END
 .SH SEE ALSO
-.BR ldattach (1),
+.BR ldattach (8),
 .BR ioctl (2),
 .BR ioctl_console (2),
 .BR termios (3),
@@ -587,7 +908,6 @@ main(void)
 .\" TIOCSERGWILD               int *
 .\" TIOCSERSWILD               const int *
 .\" TIOCSERGSTRUCT             struct async_struct *
-.\" TIOCSERGETLSR              int *
 .\" TIOCSERGETMULTI            struct serial_multiport_struct *
 .\" TIOCSERSETMULTI            const struct serial_multiport_struct *
 .\" TIOCGSERIAL, TIOCSSERIAL (see above)