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