diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-11 02:56:39 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-11 02:56:39 +0000 |
commit | 9f2f808b0dd531840b906e6dd09550a626c32bf1 (patch) | |
tree | 732344f72ee3d4f852cc2bddeb21c92e4d4f5ee7 /networking/telnetd.c | |
parent | e9b9a19ad30e004b3532105af417e43575ce7779 (diff) | |
download | busybox-w32-9f2f808b0dd531840b906e6dd09550a626c32bf1.tar.gz busybox-w32-9f2f808b0dd531840b906e6dd09550a626c32bf1.tar.bz2 busybox-w32-9f2f808b0dd531840b906e6dd09550a626c32bf1.zip |
telnetd: correctly output 0xff char. ~100 bytes.
telnet: fix some atrocious names and style. no code changes
Diffstat (limited to 'networking/telnetd.c')
-rw-r--r-- | networking/telnetd.c | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/networking/telnetd.c b/networking/telnetd.c index 46dfb318f..f04b32f9e 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -74,9 +74,6 @@ static const char *issuefile = "/etc/issue.net"; | |||
74 | past (bf + len) then that IAC will be left unprocessed and *processed | 74 | past (bf + len) then that IAC will be left unprocessed and *processed |
75 | will be less than len. | 75 | will be less than len. |
76 | 76 | ||
77 | FIXME - if we mean to send 0xFF to the terminal then it will be escaped, | ||
78 | what is the escape character? We aren't handling that situation here. | ||
79 | |||
80 | CR-LF ->'s CR mapping is also done here, for convenience. | 77 | CR-LF ->'s CR mapping is also done here, for convenience. |
81 | 78 | ||
82 | NB: may fail to remove iacs which wrap around buffer! | 79 | NB: may fail to remove iacs which wrap around buffer! |
@@ -159,6 +156,47 @@ remove_iacs(struct tsession *ts, int *pnum_totty) | |||
159 | return memmove(ptr - num_totty, ptr0, num_totty); | 156 | return memmove(ptr - num_totty, ptr0, num_totty); |
160 | } | 157 | } |
161 | 158 | ||
159 | /* | ||
160 | * Converting single 0xff into double on output | ||
161 | */ | ||
162 | static size_t iac_safe_write(int fd, const char *buf, size_t count) | ||
163 | { | ||
164 | const char *oxff; | ||
165 | size_t wr, rc, total; | ||
166 | |||
167 | total = 0; | ||
168 | while (1) { | ||
169 | if (count == 0) | ||
170 | return total; | ||
171 | if (*buf == (char)0xff) { | ||
172 | rc = safe_write(fd, "\xff\xff", 2); | ||
173 | if (rc != 2) | ||
174 | break; | ||
175 | buf++; | ||
176 | total++; | ||
177 | count--; | ||
178 | continue; | ||
179 | } | ||
180 | /* count != 0, *buf != 0xff */ | ||
181 | oxff = memchr(buf, 0xff, count); | ||
182 | wr = count; | ||
183 | if (oxff) | ||
184 | wr = oxff - buf; | ||
185 | rc = safe_write(fd, buf, wr); | ||
186 | if (rc != wr) | ||
187 | break; | ||
188 | buf += rc; | ||
189 | total += rc; | ||
190 | count -= rc; | ||
191 | } | ||
192 | /* here: rc - result of last short write */ | ||
193 | if ((ssize_t)rc < 0) { /* error? */ | ||
194 | if (total == 0) | ||
195 | return rc; | ||
196 | rc = 0; | ||
197 | } | ||
198 | return total + rc; | ||
199 | } | ||
162 | 200 | ||
163 | static struct tsession * | 201 | static struct tsession * |
164 | make_new_session( | 202 | make_new_session( |
@@ -212,9 +250,15 @@ make_new_session( | |||
212 | IAC, WILL, TELOPT_ECHO, | 250 | IAC, WILL, TELOPT_ECHO, |
213 | IAC, WILL, TELOPT_SGA | 251 | IAC, WILL, TELOPT_SGA |
214 | }; | 252 | }; |
215 | memcpy(TS_BUF2, iacs_to_send, sizeof(iacs_to_send)); | 253 | /* This confuses iac_safe_write(), it will try to duplicate |
216 | ts->rdidx2 = sizeof(iacs_to_send); | 254 | * each IAC... */ |
217 | ts->size2 = sizeof(iacs_to_send); | 255 | //memcpy(TS_BUF2, iacs_to_send, sizeof(iacs_to_send)); |
256 | //ts->rdidx2 = sizeof(iacs_to_send); | ||
257 | //ts->size2 = sizeof(iacs_to_send); | ||
258 | /* So just stuff it into TCP buffer! */ | ||
259 | safe_write(sock, iacs_to_send, sizeof(iacs_to_send)); | ||
260 | /*ts->rdidx2 = 0; - xzalloc did it! */ | ||
261 | /*ts->size2 = 0;*/ | ||
218 | } | 262 | } |
219 | 263 | ||
220 | fflush(NULL); /* flush all streams */ | 264 | fflush(NULL); /* flush all streams */ |
@@ -538,7 +582,7 @@ int telnetd_main(int argc UNUSED_PARAM, char **argv) | |||
538 | if (/*ts->size2 &&*/ FD_ISSET(ts->sockfd_write, &wrfdset)) { | 582 | if (/*ts->size2 &&*/ FD_ISSET(ts->sockfd_write, &wrfdset)) { |
539 | /* Write to socket from buffer 2. */ | 583 | /* Write to socket from buffer 2. */ |
540 | count = MIN(BUFSIZE - ts->wridx2, ts->size2); | 584 | count = MIN(BUFSIZE - ts->wridx2, ts->size2); |
541 | count = safe_write(ts->sockfd_write, TS_BUF2 + ts->wridx2, count); | 585 | count = iac_safe_write(ts->sockfd_write, (void*)(TS_BUF2 + ts->wridx2), count); |
542 | if (count < 0) { | 586 | if (count < 0) { |
543 | if (errno == EAGAIN) | 587 | if (errno == EAGAIN) |
544 | goto skip2; | 588 | goto skip2; |