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