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