aboutsummaryrefslogtreecommitdiff
path: root/networking/telnetd.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-11-07 01:58:21 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-11-07 01:58:21 +0000
commitb0150d299f80b8d0245bd419c78a40a013f03e0c (patch)
tree0449221895dbf671cecf7f3d5b79d9c6b234a4e5 /networking/telnetd.c
parent4f7d90f1c75c9cc379436e04a80c9440525eedcc (diff)
downloadbusybox-w32-b0150d299f80b8d0245bd419c78a40a013f03e0c.tar.gz
busybox-w32-b0150d299f80b8d0245bd419c78a40a013f03e0c.tar.bz2
busybox-w32-b0150d299f80b8d0245bd419c78a40a013f03e0c.zip
telnetd: handle emacs M-DEL and IAC-NOP (putty keepalive)
by Jim Cathey (jcathey AT ciena.com) function old new delta telnetd_main 1314 1364 +50
Diffstat (limited to 'networking/telnetd.c')
-rw-r--r--networking/telnetd.c71
1 files changed, 41 insertions, 30 deletions
diff --git a/networking/telnetd.c b/networking/telnetd.c
index efc2bf607..f60c42056 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -96,44 +96,55 @@ remove_iacs(struct tsession *ts, int *pnum_totty)
96 96
97 *totty++ = c; 97 *totty++ = c;
98 ptr++; 98 ptr++;
99 /* We now map \r\n ==> \r for pragmatic reasons. 99 /* We map \r\n ==> \r for pragmatic reasons.
100 * Many client implementations send \r\n when 100 * Many client implementations send \r\n when
101 * the user hits the CarriageReturn key. 101 * the user hits the CarriageReturn key.
102 */ 102 */
103 if (c == '\r' && ptr < end && (*ptr == '\n' || *ptr == '\0')) 103 if (c == '\r' && ptr < end && (*ptr == '\n' || *ptr == '\0'))
104 ptr++; 104 ptr++;
105 } else { 105 continue;
106 /* 106 }
107 * TELOPT_NAWS support!
108 */
109 if ((ptr+2) >= end) {
110 /* only the beginning of the IAC is in the
111 buffer we were asked to process, we can't
112 process this char. */
113 break;
114 }
115 107
116 /* 108 if ((ptr+1) >= end)
117 * IAC -> SB -> TELOPT_NAWS -> 4-byte -> IAC -> SE 109 break;
118 */ 110 if (ptr[1] == NOP) { /* Ignore? (putty keepalive, etc.) */
119 else if (ptr[1] == SB && ptr[2] == TELOPT_NAWS) { 111 ptr += 2;
120 struct winsize ws; 112 continue;
121 113 }
122 if ((ptr+8) >= end) 114 if (ptr[1] == IAC) { /* Literal IAC? (emacs M-DEL) */
123 break; /* incomplete, can't process */ 115 *totty++ = ptr[1];
124 ws.ws_col = (ptr[3] << 8) | ptr[4]; 116 ptr += 2;
125 ws.ws_row = (ptr[5] << 8) | ptr[6]; 117 continue;
126 ioctl(ts->ptyfd, TIOCSWINSZ, (char *)&ws); 118 }
127 ptr += 9; 119
128 } else { 120 /*
129 /* skip 3-byte IAC non-SB cmd */ 121 * TELOPT_NAWS support!
122 */
123 if ((ptr+2) >= end) {
124 /* only the beginning of the IAC is in the
125 buffer we were asked to process, we can't
126 process this char. */
127 break;
128 }
129 /*
130 * IAC -> SB -> TELOPT_NAWS -> 4-byte -> IAC -> SE
131 */
132 if (ptr[1] == SB && ptr[2] == TELOPT_NAWS) {
133 struct winsize ws;
134 if ((ptr+8) >= end)
135 break; /* incomplete, can't process */
136 ws.ws_col = (ptr[3] << 8) | ptr[4];
137 ws.ws_row = (ptr[5] << 8) | ptr[6];
138 ioctl(ts->ptyfd, TIOCSWINSZ, (char *)&ws);
139 ptr += 9;
140 continue;
141 }
142 /* skip 3-byte IAC non-SB cmd */
130#if DEBUG 143#if DEBUG
131 fprintf(stderr, "Ignoring IAC %s,%s\n", 144 fprintf(stderr, "Ignoring IAC %s,%s\n",
132 TELCMD(ptr[1]), TELOPT(ptr[2])); 145 TELCMD(ptr[1]), TELOPT(ptr[2]));
133#endif 146#endif
134 ptr += 3; 147 ptr += 3;
135 }
136 }
137 } 148 }
138 149
139 num_totty = totty - ptr0; 150 num_totty = totty - ptr0;