]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/ioctl_tty.2
Various pages: EXAMPLES: sort includes alphabetically
[thirdparty/man-pages.git] / man2 / ioctl_tty.2
1 .\" Copyright 2002 Walter Harms <walter.harms@informatik.uni-oldenburg.de>
2 .\" and Andries Brouwer <aeb@cwi.nl>.
3 .\"
4 .\" SPDX-License-Identifier: GPL-1.0-or-later
5 .\"
6 .TH IOCTL_TTY 2 2021-08-27 "Linux" "Linux Programmer's Manual"
7 .SH NAME
8 ioctl_tty \- ioctls for terminals and serial lines
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ", " \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <sys/ioctl.h>
15 .BR "#include <asm/termbits.h>" " /* Definition of " "struct termios" ,
16 .BR " struct termios2" ", and"
17 .BR " Bnnn" ", " BOTHER ", " CBAUD ", " CLOCAL ,
18 .BR " TC*" { FLUSH , ON , OFF "} and other constants */"
19 .PP
20 .BI "int ioctl(int " fd ", int " cmd ", ...);"
21 .fi
22 .SH DESCRIPTION
23 The
24 .BR ioctl (2)
25 call for terminals and serial ports accepts many possible command arguments.
26 Most require a third argument, of varying type, here called
27 .I argp
28 or
29 .IR arg .
30 .PP
31 Use of
32 .BR ioctl ()
33 makes for nonportable programs.
34 Use the POSIX interface described in
35 .BR termios (3)
36 whenever possible.
37 .PP
38 Please note that
39 .B struct termios
40 from
41 .I <asm/termbits.h>
42 is different and incompatible with
43 .B struct termios
44 from
45 .IR <termios.h> .
46 These ioctl calls require
47 .B struct termios
48 from
49 .IR <asm/termbits.h> .
50 .SS Get and set terminal attributes
51 .TP
52 .B TCGETS
53 Argument:
54 .BI "struct termios\~*" argp
55 .IP
56 Equivalent to
57 .IR "tcgetattr(fd, argp)" .
58 .IP
59 Get the current serial port settings.
60 .TP
61 .B TCSETS
62 Argument:
63 .BI "const struct termios\~*" argp
64 .IP
65 Equivalent to
66 .IR "tcsetattr(fd, TCSANOW, argp)" .
67 .IP
68 Set the current serial port settings.
69 .TP
70 .B TCSETSW
71 Argument:
72 .BI "const struct termios\~*" argp
73 .IP
74 Equivalent to
75 .IR "tcsetattr(fd, TCSADRAIN, argp)" .
76 .IP
77 Allow the output buffer to drain, and
78 set the current serial port settings.
79 .TP
80 .B TCSETSF
81 Argument:
82 .BI "const struct termios\~*" argp
83 .IP
84 Equivalent to
85 .IR "tcsetattr(fd, TCSAFLUSH, argp)" .
86 .IP
87 Allow the output buffer to drain, discard pending input, and
88 set the current serial port settings.
89 .PP
90 The following four ioctls, added in Linux 2.6.20,
91 .\" commit 64bb6c5e1ddcd47c951740485026ef08975ee2e6
92 .\" commit 592ee3a5e5e2a981ef2829a0380093006d045661
93 are just like
94 .BR TCGETS ,
95 .BR TCSETS ,
96 .BR TCSETSW ,
97 .BR TCSETSF ,
98 except that they take a
99 .I "struct termios2\~*"
100 instead of a
101 .IR "struct termios\~*" .
102 If the structure member
103 .B c_cflag
104 contains the flag
105 .BR BOTHER ,
106 then the baud rate is stored in the structure members
107 .B c_ispeed
108 and
109 .B c_ospeed
110 as integer values.
111 These ioctls are not supported on all architectures.
112 .RS
113 .TS
114 lb l.
115 TCGETS2 \fBstruct termios2 *\fPargp
116 TCSETS2 \fBconst struct termios2 *\fPargp
117 TCSETSW2 \fBconst struct termios2 *\fPargp
118 TCSETSF2 \fBconst struct termios2 *\fPargp
119 .TE
120 .RE
121 .PP
122 The following four ioctls are just like
123 .BR TCGETS ,
124 .BR TCSETS ,
125 .BR TCSETSW ,
126 .BR TCSETSF ,
127 except that they take a
128 .I "struct termio\~*"
129 instead of a
130 .IR "struct termios\~*" .
131 .RS
132 .TS
133 lb l.
134 TCGETA \fBstruct termio *\fPargp
135 TCSETA \fBconst struct termio *\fPargp
136 TCSETAW \fBconst struct termio *\fPargp
137 TCSETAF \fBconst struct termio *\fPargp
138 .TE
139 .RE
140 .SS Locking the termios structure
141 The
142 .I termios
143 structure of a terminal can be locked.
144 The lock is itself a
145 .I termios
146 structure, with nonzero bits or fields indicating a
147 locked value.
148 .TP
149 .B TIOCGLCKTRMIOS
150 Argument:
151 .BI "struct termios\~*" argp
152 .IP
153 Gets the locking status of the
154 .I termios
155 structure of the terminal.
156 .TP
157 .B TIOCSLCKTRMIOS
158 Argument:
159 .BI "const struct termios\~*" argp
160 .IP
161 Sets the locking status of the
162 .I termios
163 structure of the terminal.
164 Only a process with the
165 .B CAP_SYS_ADMIN
166 capability can do this.
167 .SS Get and set window size
168 Window sizes are kept in the kernel, but not used by the kernel
169 (except in the case of virtual consoles, where the kernel will
170 update the window size when the size of the virtual console changes,
171 for example, by loading a new font).
172 .TP
173 .B TIOCGWINSZ
174 Argument:
175 .BI "struct winsize\~*" argp
176 .IP
177 Get window size.
178 .TP
179 .B TIOCSWINSZ
180 Argument:
181 .BI "const struct winsize\~*" argp
182 .IP
183 Set window size.
184 .PP
185 The struct used by these ioctls is defined as
186 .PP
187 .in +4n
188 .EX
189 struct winsize {
190 unsigned short ws_row;
191 unsigned short ws_col;
192 unsigned short ws_xpixel; /* unused */
193 unsigned short ws_ypixel; /* unused */
194 };
195 .EE
196 .in
197 .PP
198 When the window size changes, a
199 .B SIGWINCH
200 signal is sent to the
201 foreground process group.
202 .SS Sending a break
203 .TP
204 .B TCSBRK
205 Argument:
206 .BI "int " arg
207 .IP
208 Equivalent to
209 .IR "tcsendbreak(fd, arg)" .
210 .IP
211 If the terminal is using asynchronous serial data transmission, and
212 .I arg
213 is zero, then send a break (a stream of zero bits) for between
214 0.25 and 0.5 seconds.
215 If the terminal is not using asynchronous
216 serial data transmission, then either a break is sent, or the function
217 returns without doing anything.
218 When
219 .I arg
220 is nonzero, nobody knows what will happen.
221 .IP
222 (SVr4, UnixWare, Solaris, and Linux treat
223 .I "tcsendbreak(fd,arg)"
224 with nonzero
225 .I arg
226 like
227 .IR "tcdrain(fd)" .
228 SunOS treats
229 .I arg
230 as a multiplier, and sends a stream of bits
231 .I arg
232 times as long as done for zero
233 .IR arg .
234 DG/UX and AIX treat
235 .I arg
236 (when nonzero) as a time interval measured in milliseconds.
237 HP-UX ignores
238 .IR arg .)
239 .TP
240 .B TCSBRKP
241 Argument:
242 .BI "int " arg
243 .IP
244 So-called "POSIX version" of
245 .BR TCSBRK .
246 It treats nonzero
247 .I arg
248 as a time interval measured in deciseconds, and does nothing
249 when the driver does not support breaks.
250 .TP
251 .B TIOCSBRK
252 Argument:
253 .B void
254 .IP
255 Turn break on, that is, start sending zero bits.
256 .TP
257 .B TIOCCBRK
258 Argument:
259 .B void
260 .IP
261 Turn break off, that is, stop sending zero bits.
262 .SS Software flow control
263 .TP
264 .B TCXONC
265 Argument:
266 .BI "int " arg
267 .IP
268 Equivalent to
269 .IR "tcflow(fd, arg)" .
270 .IP
271 See
272 .BR tcflow (3)
273 for the argument values
274 .BR TCOOFF ,
275 .BR TCOON ,
276 .BR TCIOFF ,
277 .BR TCION .
278 .SS Buffer count and flushing
279 .TP
280 .B FIONREAD
281 Argument:
282 .BI "int\~*" argp
283 .IP
284 Get the number of bytes in the input buffer.
285 .TP
286 .B TIOCINQ
287 Argument:
288 .BI "int\~*" argp
289 .IP
290 Same as
291 .BR FIONREAD .
292 .TP
293 .B TIOCOUTQ
294 Argument:
295 .BI "int\~*" argp
296 .IP
297 Get the number of bytes in the output buffer.
298 .TP
299 .B TCFLSH
300 Argument:
301 .BI "int " arg
302 .IP
303 Equivalent to
304 .IR "tcflush(fd, arg)" .
305 .IP
306 See
307 .BR tcflush (3)
308 for the argument values
309 .BR TCIFLUSH ,
310 .BR TCOFLUSH ,
311 .BR TCIOFLUSH .
312 .SS Faking input
313 .TP
314 .B TIOCSTI
315 Argument:
316 .BI "const char\~*" argp
317 .IP
318 Insert the given byte in the input queue.
319 .SS Redirecting console output
320 .TP
321 .B TIOCCONS
322 Argument:
323 .B void
324 .IP
325 Redirect output that would have gone to
326 .I /dev/console
327 or
328 .I /dev/tty0
329 to the given terminal.
330 If that was a pseudoterminal master, send it to the slave.
331 In Linux before version 2.6.10,
332 anybody can do this as long as the output was not redirected yet;
333 since version 2.6.10, only a process with the
334 .B CAP_SYS_ADMIN
335 capability may do this.
336 If output was redirected already, then
337 .B EBUSY
338 is returned,
339 but redirection can be stopped by using this ioctl with
340 .I fd
341 pointing at
342 .I /dev/console
343 or
344 .IR /dev/tty0 .
345 .SS Controlling terminal
346 .TP
347 .B TIOCSCTTY
348 Argument:
349 .BI "int " arg
350 .IP
351 Make the given terminal the controlling terminal of the calling process.
352 The calling process must be a session leader and not have a
353 controlling terminal already.
354 For this case,
355 .I arg
356 should be specified as zero.
357 .IP
358 If this terminal is already the controlling terminal
359 of a different session group, then the ioctl fails with
360 .BR EPERM ,
361 unless the caller has the
362 .B CAP_SYS_ADMIN
363 capability and
364 .I arg
365 equals 1, in which case the terminal is stolen, and all processes that had
366 it as controlling terminal lose it.
367 .TP
368 .B TIOCNOTTY
369 Argument:
370 .B void
371 .IP
372 If the given terminal was the controlling terminal of the calling process,
373 give up this controlling terminal.
374 If the process was session leader,
375 then send
376 .B SIGHUP
377 and
378 .B SIGCONT
379 to the foreground process group
380 and all processes in the current session lose their controlling terminal.
381 .SS Process group and session ID
382 .TP
383 .B TIOCGPGRP
384 Argument:
385 .BI "pid_t\~*" argp
386 .IP
387 When successful, equivalent to
388 .IR "*argp = tcgetpgrp(fd)" .
389 .IP
390 Get the process group ID of the foreground process group on this terminal.
391 .TP
392 .B TIOCSPGRP
393 Argument:
394 .BI "const pid_t\~*" argp
395 .IP
396 Equivalent to
397 .IR "tcsetpgrp(fd, *argp)" .
398 .IP
399 Set the foreground process group ID of this terminal.
400 .TP
401 .B TIOCGSID
402 Argument:
403 .BI "pid_t\~*" argp
404 .IP
405 When successful, equivalent to
406 .IR "*argp = tcgetsid(fd)" .
407 .IP
408 Get the session ID of the given terminal.
409 This fails with the error
410 .B ENOTTY
411 if the terminal is not a master pseudoterminal
412 and not our controlling terminal.
413 Strange.
414 .SS Exclusive mode
415 .TP
416 .B TIOCEXCL
417 Argument:
418 .B void
419 .IP
420 Put the terminal into exclusive mode.
421 No further
422 .BR open (2)
423 operations on the terminal are permitted.
424 (They fail with
425 .BR EBUSY ,
426 except for a process with the
427 .B CAP_SYS_ADMIN
428 capability.)
429 .TP
430 .B TIOCGEXCL
431 Argument:
432 .BI "int\~*" argp
433 .IP
434 (since Linux 3.8)
435 If the terminal is currently in exclusive mode,
436 place a nonzero value in the location pointed to by
437 .IR argp ;
438 otherwise, place zero in
439 .IR *argp .
440 .TP
441 .B TIOCNXCL
442 Argument:
443 .B void
444 .IP
445 Disable exclusive mode.
446 .SS Line discipline
447 .TP
448 .B TIOCGETD
449 Argument:
450 .BI "int\~*" argp
451 .IP
452 Get the line discipline of the terminal.
453 .TP
454 .B TIOCSETD
455 Argument:
456 .BI "const int\~*" argp
457 .IP
458 Set the line discipline of the terminal.
459 .SS Pseudoterminal ioctls
460 .TP
461 .B TIOCPKT
462 Argument:
463 .BI "const int\~*" argp
464 .IP
465 Enable (when
466 .RI * argp
467 is nonzero) or disable packet mode.
468 Can be applied to the master side of a pseudoterminal only (and will return
469 .B ENOTTY
470 otherwise).
471 In packet mode, each subsequent
472 .BR read (2)
473 will return a packet that either contains a single nonzero control byte,
474 or has a single byte containing zero (\(aq\e0\(aq) followed by data
475 written on the slave side of the pseudoterminal.
476 If the first byte is not
477 .B TIOCPKT_DATA
478 (0), it is an OR of one
479 or more of the following bits:
480 .IP
481 .ad l
482 .TS
483 lb l.
484 TIOCPKT_FLUSHREAD T{
485 The read queue for the terminal is flushed.
486 T}
487 TIOCPKT_FLUSHWRITE T{
488 The write queue for the terminal is flushed.
489 T}
490 TIOCPKT_STOP T{
491 Output to the terminal is stopped.
492 T}
493 TIOCPKT_START T{
494 Output to the terminal is restarted.
495 T}
496 TIOCPKT_DOSTOP T{
497 The start and stop characters are \fB\(haS\fP/\fB\(haQ\fP.
498 T}
499 TIOCPKT_NOSTOP T{
500 The start and stop characters are not \fB\(haS\fP/\fB\(haQ\fP.
501 T}
502 .TE
503 .ad
504 .IP
505 While packet mode is in use, the presence
506 of control status information to be read
507 from the master side may be detected by a
508 .BR select (2)
509 for exceptional conditions or a
510 .BR poll (2)
511 for the
512 .B POLLPRI
513 event.
514 .IP
515 This mode is used by
516 .BR rlogin (1)
517 and
518 .BR rlogind (8)
519 to implement a remote-echoed,
520 locally \fB\(haS\fP/\fB\(haQ\fP flow-controlled remote login.
521 .TP
522 .B TIOCGPKT
523 Argument:
524 .BI "const int\~*" argp
525 .IP
526 (since Linux 3.8)
527 Return the current packet mode setting in the integer pointed to by
528 .IR argp .
529 .TP
530 .B TIOCSPTLCK
531 Argument:
532 .BI "int\~*" argp
533 .IP
534 Set (if
535 .I *argp
536 is nonzero) or remove (if
537 .I *argp
538 is zero) the lock on the pseudoterminal slave device.
539 (See also
540 .BR unlockpt (3).)
541 .TP
542 .B TIOCGPTLCK
543 Argument:
544 .BI "int\~*" argp
545 .IP
546 (since Linux 3.8)
547 Place the current lock state of the pseudoterminal slave device
548 in the location pointed to by
549 .IR argp .
550 .TP
551 .B TIOCGPTPEER
552 Argument:
553 .BI "int " flags
554 .IP
555 .\" commit 54ebbfb1603415d9953c150535850d30609ef077
556 (since Linux 4.13)
557 Given a file descriptor in
558 .I fd
559 that refers to a pseudoterminal master,
560 open (with the given
561 .BR open (2)-style
562 .IR flags )
563 and return a new file descriptor that refers to the peer
564 pseudoterminal slave device.
565 This operation can be performed
566 regardless of whether the pathname of the slave device
567 is accessible through the calling process's mount namespace.
568 .IP
569 Security-conscious programs interacting with namespaces may wish to use this
570 operation rather than
571 .BR open (2)
572 with the pathname returned by
573 .BR ptsname (3),
574 and similar library functions that have insecure APIs.
575 (For example, confusion can occur in some cases using
576 .BR ptsname (3)
577 with a pathname where a devpts filesystem
578 has been mounted in a different mount namespace.)
579 .PP
580 The BSD ioctls
581 .BR TIOCSTOP ,
582 .BR TIOCSTART ,
583 .BR TIOCUCNTL ,
584 and
585 .B TIOCREMOTE
586 have not been implemented under Linux.
587 .SS Modem control
588 .TP
589 .B TIOCMGET
590 Argument:
591 .BI "int\~*" argp
592 .IP
593 Get the status of modem bits.
594 .TP
595 .B TIOCMSET
596 Argument:
597 .BI "const int\~*" argp
598 .IP
599 Set the status of modem bits.
600 .TP
601 .B TIOCMBIC
602 Argument:
603 .BI "const int\~*" argp
604 .IP
605 Clear the indicated modem bits.
606 .TP
607 .B TIOCMBIS
608 Argument:
609 .BI "const int\~*" argp
610 .IP
611 Set the indicated modem bits.
612 .PP
613 The following bits are used by the above ioctls:
614 .PP
615 .TS
616 lb l.
617 TIOCM_LE DSR (data set ready/line enable)
618 TIOCM_DTR DTR (data terminal ready)
619 TIOCM_RTS RTS (request to send)
620 TIOCM_ST Secondary TXD (transmit)
621 TIOCM_SR Secondary RXD (receive)
622 TIOCM_CTS CTS (clear to send)
623 TIOCM_CAR DCD (data carrier detect)
624 TIOCM_CD see TIOCM_CAR
625 TIOCM_RNG RNG (ring)
626 TIOCM_RI see TIOCM_RNG
627 TIOCM_DSR DSR (data set ready)
628 .TE
629 .TP
630 .B TIOCMIWAIT
631 Argument:
632 .BI "int " arg
633 .IP
634 Wait for any of the 4 modem bits (DCD, RI, DSR, CTS) to change.
635 The bits of interest are specified as a bit mask in
636 .IR arg ,
637 by ORing together any of the bit values,
638 .BR TIOCM_RNG ,
639 .BR TIOCM_DSR ,
640 .BR TIOCM_CD ,
641 and
642 .BR TIOCM_CTS .
643 The caller should use
644 .B TIOCGICOUNT
645 to see which bit has changed.
646 .TP
647 .B TIOCGICOUNT
648 Argument:
649 .BI "struct serial_icounter_struct\~*" argp
650 .IP
651 Get counts of input serial line interrupts (DCD, RI, DSR, CTS).
652 The counts are written to the
653 .I serial_icounter_struct
654 structure pointed to by
655 .IR argp .
656 .IP
657 Note: both 1->0 and 0->1 transitions are counted, except for
658 RI, where only 0->1 transitions are counted.
659 .SS Marking a line as local
660 .TP
661 .B TIOCGSOFTCAR
662 Argument:
663 .BI "int\~*" argp
664 .IP
665 ("Get software carrier flag")
666 Get the status of the CLOCAL flag in the c_cflag field of the
667 .I termios
668 structure.
669 .TP
670 .B TIOCSSOFTCAR
671 Argument:
672 .BI "const int\~*" argp
673 .IP
674 ("Set software carrier flag")
675 Set the CLOCAL flag in the
676 .I termios
677 structure when
678 .RI * argp
679 is nonzero, and clear it otherwise.
680 .PP
681 If the
682 .B CLOCAL
683 flag for a line is off, the hardware carrier detect (DCD)
684 signal is significant, and an
685 .BR open (2)
686 of the corresponding terminal will block until DCD is asserted,
687 unless the
688 .B O_NONBLOCK
689 flag is given.
690 If
691 .B CLOCAL
692 is set, the line behaves as if DCD is always asserted.
693 The software carrier flag is usually turned on for local devices,
694 and is off for lines with modems.
695 .SS Linux-specific
696 For the
697 .B TIOCLINUX
698 ioctl, see
699 .BR ioctl_console (2).
700 .SS Kernel debugging
701 .B "#include <linux/tty.h>"
702 .TP
703 .B TIOCTTYGSTRUCT
704 Argument:
705 .BI "struct tty_struct\~*" argp
706 .IP
707 Get the
708 .I tty_struct
709 corresponding to
710 .IR fd .
711 This command was removed in Linux 2.5.67.
712 .\" commit b3506a09d15dc5aee6d4bb88d759b157016e1864
713 .\" Author: Andries E. Brouwer <andries.brouwer@cwi.nl>
714 .\" Date: Tue Apr 1 04:42:46 2003 -0800
715 .\"
716 .\" [PATCH] kill TIOCTTYGSTRUCT
717 .\"
718 .\" Only used for (dubious) debugging purposes, and exposes
719 .\" internal kernel state.
720 .\"
721 .\" .SS Serial info
722 .\" .BR "#include <linux/serial.h>"
723 .\" .PP
724 .\" .TP
725 .\" .BI "TIOCGSERIAL struct serial_struct *" argp
726 .\" Get serial info.
727 .\" .TP
728 .\" .BI "TIOCSSERIAL const struct serial_struct *" argp
729 .\" Set serial info.
730 .SH RETURN VALUE
731 The
732 .BR ioctl (2)
733 system call returns 0 on success.
734 On error, it returns \-1 and sets
735 .I errno
736 to indicate the error.
737 .SH ERRORS
738 .TP
739 .B EINVAL
740 Invalid command parameter.
741 .TP
742 .B ENOIOCTLCMD
743 Unknown command.
744 .TP
745 .B ENOTTY
746 Inappropriate
747 .IR fd .
748 .TP
749 .B EPERM
750 Insufficient permission.
751 .SH EXAMPLES
752 Check the condition of DTR on the serial port.
753 .PP
754 .\" SRC BEGIN (tiocmget.c)
755 .EX
756 #include <fcntl.h>
757 #include <stdio.h>
758 #include <sys/ioctl.h>
759 #include <unistd.h>
760
761 int
762 main(void)
763 {
764 int fd, serial;
765
766 fd = open("/dev/ttyS0", O_RDONLY);
767 ioctl(fd, TIOCMGET, &serial);
768 if (serial & TIOCM_DTR)
769 puts("TIOCM_DTR is set");
770 else
771 puts("TIOCM_DTR is not set");
772 close(fd);
773 }
774 .EE
775 .\" SRC END
776 .PP
777 Get or set arbitrary baudrate on the serial port.
778 .PP
779 .\" SRC BEGIN (tcgets.c)
780 .EX
781 /* SPDX-License-Identifier: GPL-2.0-or-later */
782
783 #include <asm/termbits.h>
784 #include <fcntl.h>
785 #include <stdio.h>
786 #include <stdlib.h>
787 #include <sys/ioctl.h>
788 #include <sys/types.h>
789 #include <unistd.h>
790
791 int
792 main(int argc, char *argv[])
793 {
794 #if !defined BOTHER
795 fprintf(stderr, "BOTHER is unsupported\en");
796 /* Program may fallback to TCGETS/TCSETS with Bnnn constants */
797 exit(EXIT_FAILURE);
798 #else
799 /* Declare tio structure, its type depends on supported ioctl */
800 # if defined TCGETS2
801 struct termios2 tio;
802 # else
803 struct termios tio;
804 # endif
805 int fd, rc;
806
807 if (argc != 2 && argc != 3 && argc != 4) {
808 fprintf(stderr, "Usage: %s device [output [input] ]\en", argv[0]);
809 exit(EXIT_FAILURE);
810 }
811
812 fd = open(argv[1], O_RDWR | O_NONBLOCK | O_NOCTTY);
813 if (fd < 0) {
814 perror("open");
815 exit(EXIT_FAILURE);
816 }
817
818 /* Get the current serial port settings via supported ioctl */
819 # if defined TCGETS2
820 rc = ioctl(fd, TCGETS2, &tio);
821 # else
822 rc = ioctl(fd, TCGETS, &tio);
823 # endif
824 if (rc) {
825 perror("TCGETS");
826 close(fd);
827 exit(EXIT_FAILURE);
828 }
829
830 /* Change baud rate when more arguments were provided */
831 if (argc == 3 || argc == 4) {
832 /* Clear the current output baud rate and fill a new value */
833 tio.c_cflag &= ~CBAUD;
834 tio.c_cflag |= BOTHER;
835 tio.c_ospeed = atoi(argv[2]);
836
837 /* Clear the current input baud rate and fill a new value */
838 tio.c_cflag &= ~(CBAUD << IBSHIFT);
839 tio.c_cflag |= BOTHER << IBSHIFT;
840 /* When 4th argument is not provided reuse output baud rate */
841 tio.c_ispeed = (argc == 4) ? atoi(argv[3]) : atoi(argv[2]);
842
843 /* Set new serial port settings via supported ioctl */
844 # if defined TCSETS2
845 rc = ioctl(fd, TCSETS2, &tio);
846 # else
847 rc = ioctl(fd, TCSETS, &tio);
848 # endif
849 if (rc) {
850 perror("TCSETS");
851 close(fd);
852 exit(EXIT_FAILURE);
853 }
854
855 /* And get new values which were really configured */
856 # if defined TCGETS2
857 rc = ioctl(fd, TCGETS2, &tio);
858 # else
859 rc = ioctl(fd, TCGETS, &tio);
860 # endif
861 if (rc) {
862 perror("TCGETS");
863 close(fd);
864 exit(EXIT_FAILURE);
865 }
866 }
867
868 close(fd);
869
870 printf("output baud rate: %u\en", tio.c_ospeed);
871 printf("input baud rate: %u\en", tio.c_ispeed);
872
873 exit(EXIT_SUCCESS);
874 #endif
875 }
876 .EE
877 .\" SRC END
878 .SH SEE ALSO
879 .BR ldattach (8),
880 .BR ioctl (2),
881 .BR ioctl_console (2),
882 .BR termios (3),
883 .BR pty (7)
884 .\"
885 .\" FIONBIO const int *
886 .\" FIONCLEX void
887 .\" FIOCLEX void
888 .\" FIOASYNC const int *
889 .\" from serial.c:
890 .\" TIOCSERCONFIG void
891 .\" TIOCSERGWILD int *
892 .\" TIOCSERSWILD const int *
893 .\" TIOCSERGSTRUCT struct async_struct *
894 .\" TIOCSERGETLSR int *
895 .\" TIOCSERGETMULTI struct serial_multiport_struct *
896 .\" TIOCSERSETMULTI const struct serial_multiport_struct *
897 .\" TIOCGSERIAL, TIOCSSERIAL (see above)