blob: 4fb2d3dae8ee4a7e109367a2045d58abbb2796a6 [file] [log] [blame]
Ben Lindstrome626cf82001-04-14 23:21:50 +00001/*
2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
5 *
6 * As far as I am concerned, the code I have written for this software
7 * can be used freely for any purpose. Any derived versions of this
8 * software must be clearly marked as such, and if the derived work is
9 * incompatible with the protocol description in the RFC file, it must be
10 * called by a name other than "ssh" or "Secure Shell".
11 */
12/*
13 * Copyright (c) 2001 Markus Friedl. All rights reserved.
14 * Copyright (c) 2001 Kevin Steves. All rights reserved.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include "includes.h"
Darren Tucker9a2c4cd2003-09-22 21:16:05 +100038RCSID("$OpenBSD: sshtty.c,v 1.5 2003/09/19 17:43:35 markus Exp $");
Ben Lindstrome626cf82001-04-14 23:21:50 +000039
40#include "sshtty.h"
41#include "log.h"
42
43static struct termios _saved_tio;
44static int _in_raw_mode = 0;
45
Ben Lindstrome626cf82001-04-14 23:21:50 +000046struct termios
47get_saved_tio(void)
48{
49 return _saved_tio;
50}
51
52void
53leave_raw_mode(void)
54{
55 if (!_in_raw_mode)
56 return;
57 if (tcsetattr(fileno(stdin), TCSADRAIN, &_saved_tio) == -1)
58 perror("tcsetattr");
59 else
60 _in_raw_mode = 0;
Ben Lindstrome626cf82001-04-14 23:21:50 +000061}
62
63void
64enter_raw_mode(void)
65{
66 struct termios tio;
67
68 if (tcgetattr(fileno(stdin), &tio) == -1) {
69 perror("tcgetattr");
70 return;
71 }
72 _saved_tio = tio;
73 tio.c_iflag |= IGNPAR;
74 tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
Darren Tucker538d1802003-07-19 19:56:18 +100075#ifdef IUCLC
76 tio.c_iflag &= ~IUCLC;
77#endif
Ben Lindstrome626cf82001-04-14 23:21:50 +000078 tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
79#ifdef IEXTEN
80 tio.c_lflag &= ~IEXTEN;
81#endif
82 tio.c_oflag &= ~OPOST;
83 tio.c_cc[VMIN] = 1;
84 tio.c_cc[VTIME] = 0;
85 if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) == -1)
86 perror("tcsetattr");
87 else
88 _in_raw_mode = 1;
Ben Lindstrome626cf82001-04-14 23:21:50 +000089}