31 |
static char sccsid[] = "@(#)termstat.c 8.2 (Berkeley) 5/30/95"; |
static char sccsid[] = "@(#)termstat.c 8.2 (Berkeley) 5/30/95"; |
32 |
#endif /* not lint */ |
#endif /* not lint */ |
33 |
|
|
|
#ifdef HAVE_CONFIG_H |
|
|
#include <config.h> |
|
|
#endif |
|
|
|
|
34 |
#include "telnetd.h" |
#include "telnetd.h" |
35 |
|
|
36 |
/* |
/* |
40 |
#ifdef TIOCSWINSZ |
#ifdef TIOCSWINSZ |
41 |
int def_row = 0, def_col = 0; |
int def_row = 0, def_col = 0; |
42 |
#endif |
#endif |
|
#ifdef LINEMODE |
|
43 |
static int _terminit = 0; |
static int _terminit = 0; |
|
#endif /* LINEMODE */ |
|
44 |
|
|
45 |
#if defined(CRAY2) && defined(UNICOS5) |
#if defined(CRAY2) && defined(UNICOS5) |
46 |
int newmap = 1; /* nonzero if \n maps to ^M^J */ |
int newmap = 1; /* nonzero if \n maps to ^M^J */ |
47 |
#endif |
#endif |
48 |
|
|
|
#ifdef LINEMODE |
|
49 |
/* |
/* |
50 |
* localstat |
* localstat |
51 |
* |
* |
217 |
send_wont(TELOPT_ECHO, 1); |
send_wont(TELOPT_ECHO, 1); |
218 |
else |
else |
219 |
need_will_echo = 1; |
need_will_echo = 1; |
|
#ifdef KLUDGELINEMODE |
|
220 |
if (lmodetype == KLUDGE_OK) |
if (lmodetype == KLUDGE_OK) |
221 |
lmodetype = KLUDGE_LINEMODE; |
lmodetype = KLUDGE_LINEMODE; |
|
#endif |
|
222 |
} |
} |
223 |
|
|
224 |
/* |
/* |
226 |
* command and then we're all done. |
* command and then we're all done. |
227 |
*/ |
*/ |
228 |
if (!uselinemode && linemode) { |
if (!uselinemode && linemode) { |
|
# ifdef KLUDGELINEMODE |
|
229 |
if (lmodetype == REAL_LINEMODE) { |
if (lmodetype == REAL_LINEMODE) { |
|
# endif /* KLUDGELINEMODE */ |
|
230 |
send_dont(TELOPT_LINEMODE, 1); |
send_dont(TELOPT_LINEMODE, 1); |
|
# ifdef KLUDGELINEMODE |
|
231 |
} else if (lmodetype == KLUDGE_LINEMODE) |
} else if (lmodetype == KLUDGE_LINEMODE) |
232 |
send_will(TELOPT_SGA, 1); |
send_will(TELOPT_SGA, 1); |
|
# endif /* KLUDGELINEMODE */ |
|
233 |
send_will(TELOPT_ECHO, 1); |
send_will(TELOPT_ECHO, 1); |
234 |
linemode = uselinemode; |
linemode = uselinemode; |
235 |
goto done; |
goto done; |
236 |
} |
} |
237 |
|
|
|
# ifdef KLUDGELINEMODE |
|
238 |
/* |
/* |
239 |
* If using real linemode check edit modes for possible later use. |
* If using real linemode check edit modes for possible later use. |
240 |
* If we are in kludge linemode, do the SGA negotiation. |
* If we are in kludge linemode, do the SGA negotiation. |
241 |
*/ |
*/ |
242 |
if (lmodetype == REAL_LINEMODE) { |
if (lmodetype == REAL_LINEMODE) { |
|
# endif /* KLUDGELINEMODE */ |
|
243 |
useeditmode = 0; |
useeditmode = 0; |
244 |
if (tty_isediting()) |
if (tty_isediting()) |
245 |
useeditmode |= MODE_EDIT; |
useeditmode |= MODE_EDIT; |
249 |
useeditmode |= MODE_SOFT_TAB; |
useeditmode |= MODE_SOFT_TAB; |
250 |
if (tty_islitecho()) |
if (tty_islitecho()) |
251 |
useeditmode |= MODE_LIT_ECHO; |
useeditmode |= MODE_LIT_ECHO; |
|
# ifdef KLUDGELINEMODE |
|
252 |
} else if (lmodetype == KLUDGE_LINEMODE) { |
} else if (lmodetype == KLUDGE_LINEMODE) { |
253 |
if (tty_isediting() && uselinemode) |
if (tty_isediting() && uselinemode) |
254 |
send_wont(TELOPT_SGA, 1); |
send_wont(TELOPT_SGA, 1); |
255 |
else |
else |
256 |
send_will(TELOPT_SGA, 1); |
send_will(TELOPT_SGA, 1); |
257 |
} |
} |
|
# endif /* KLUDGELINEMODE */ |
|
258 |
|
|
259 |
/* |
/* |
260 |
* Negotiate linemode on if pty state has changed to turn it on. |
* Negotiate linemode on if pty state has changed to turn it on. |
261 |
* Send appropriate command and send along edit mode, then all done. |
* Send appropriate command and send along edit mode, then all done. |
262 |
*/ |
*/ |
263 |
if (uselinemode && !linemode) { |
if (uselinemode && !linemode) { |
|
# ifdef KLUDGELINEMODE |
|
264 |
if (lmodetype == KLUDGE_LINEMODE) { |
if (lmodetype == KLUDGE_LINEMODE) { |
265 |
send_wont(TELOPT_SGA, 1); |
send_wont(TELOPT_SGA, 1); |
266 |
} else if (lmodetype == REAL_LINEMODE) { |
} else if (lmodetype == REAL_LINEMODE) { |
|
# endif /* KLUDGELINEMODE */ |
|
267 |
send_do(TELOPT_LINEMODE, 1); |
send_do(TELOPT_LINEMODE, 1); |
268 |
/* send along edit modes */ |
/* send along edit modes */ |
269 |
(void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB, |
net_output_data("%c%c%c%c%c%c%c", IAC, SB, |
270 |
TELOPT_LINEMODE, LM_MODE, useeditmode, |
TELOPT_LINEMODE, LM_MODE, useeditmode, |
271 |
IAC, SE); |
IAC, SE); |
|
nfrontp += 7; |
|
272 |
editmode = useeditmode; |
editmode = useeditmode; |
|
# ifdef KLUDGELINEMODE |
|
273 |
} |
} |
|
# endif /* KLUDGELINEMODE */ |
|
274 |
linemode = uselinemode; |
linemode = uselinemode; |
275 |
goto done; |
goto done; |
276 |
} |
} |
277 |
|
|
|
# ifdef KLUDGELINEMODE |
|
278 |
/* |
/* |
279 |
* None of what follows is of any value if not using |
* None of what follows is of any value if not using |
280 |
* real linemode. |
* real linemode. |
281 |
*/ |
*/ |
282 |
if (lmodetype < REAL_LINEMODE) |
if (lmodetype < REAL_LINEMODE) |
283 |
goto done; |
goto done; |
|
# endif /* KLUDGELINEMODE */ |
|
284 |
|
|
285 |
if (linemode && his_state_is_will(TELOPT_LINEMODE)) { |
if (linemode && his_state_is_will(TELOPT_LINEMODE)) { |
286 |
/* |
/* |
290 |
/* |
/* |
291 |
* Send along appropriate edit mode mask. |
* Send along appropriate edit mode mask. |
292 |
*/ |
*/ |
293 |
(void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB, |
net_output_data("%c%c%c%c%c%c%c", IAC, SB, |
294 |
TELOPT_LINEMODE, LM_MODE, useeditmode, |
TELOPT_LINEMODE, LM_MODE, useeditmode, |
295 |
IAC, SE); |
IAC, SE); |
|
nfrontp += 7; |
|
296 |
editmode = useeditmode; |
editmode = useeditmode; |
297 |
} |
} |
298 |
|
|
323 |
return; |
return; |
324 |
|
|
325 |
} /* end of localstat */ |
} /* end of localstat */ |
|
#endif /* LINEMODE */ |
|
326 |
|
|
327 |
/* |
/* |
328 |
* flowstat |
* flowstat |
335 |
if (his_state_is_will(TELOPT_LFLOW)) { |
if (his_state_is_will(TELOPT_LFLOW)) { |
336 |
if (tty_flowmode() != flowmode) { |
if (tty_flowmode() != flowmode) { |
337 |
flowmode = tty_flowmode(); |
flowmode = tty_flowmode(); |
338 |
(void) sprintf(nfrontp, "%c%c%c%c%c%c", |
net_output_data ("%c%c%c%c%c%c", |
339 |
IAC, SB, TELOPT_LFLOW, |
IAC, SB, TELOPT_LFLOW, |
340 |
flowmode ? LFLOW_ON : LFLOW_OFF, |
flowmode ? LFLOW_ON : LFLOW_OFF, |
341 |
IAC, SE); |
IAC, SE); |
|
nfrontp += 6; |
|
342 |
} |
} |
343 |
if (tty_restartany() != restartany) { |
if (tty_restartany() != restartany) { |
344 |
restartany = tty_restartany(); |
restartany = tty_restartany(); |
345 |
(void) sprintf(nfrontp, "%c%c%c%c%c%c", |
net_output_data ("%c%c%c%c%c%c", |
346 |
IAC, SB, TELOPT_LFLOW, |
IAC, SB, TELOPT_LFLOW, |
347 |
restartany ? LFLOW_RESTART_ANY |
restartany ? LFLOW_RESTART_ANY |
348 |
: LFLOW_RESTART_XON, |
: LFLOW_RESTART_XON, |
349 |
IAC, SE); |
IAC, SE); |
|
nfrontp += 6; |
|
350 |
} |
} |
351 |
} |
} |
352 |
} |
} |
373 |
* Process request from client. code tells what it is. |
* Process request from client. code tells what it is. |
374 |
*/ |
*/ |
375 |
switch (code) { |
switch (code) { |
|
#ifdef LINEMODE |
|
376 |
case TELOPT_LINEMODE: |
case TELOPT_LINEMODE: |
377 |
/* |
/* |
378 |
* Don't do anything unless client is asking us to change |
* Don't do anything unless client is asking us to change |
380 |
*/ |
*/ |
381 |
uselinemode = (parm1 == WILL); |
uselinemode = (parm1 == WILL); |
382 |
if (uselinemode != linemode) { |
if (uselinemode != linemode) { |
|
# ifdef KLUDGELINEMODE |
|
383 |
/* |
/* |
384 |
* If using kludge linemode, make sure that |
* If using kludge linemode, make sure that |
385 |
* we can do what the client asks. |
* we can do what the client asks. |
403 |
* turned on, send along the edit mode mask. |
* turned on, send along the edit mode mask. |
404 |
*/ |
*/ |
405 |
if (lmodetype == REAL_LINEMODE && uselinemode) |
if (lmodetype == REAL_LINEMODE && uselinemode) |
|
# else /* KLUDGELINEMODE */ |
|
406 |
if (uselinemode) |
if (uselinemode) |
|
# endif /* KLUDGELINEMODE */ |
|
407 |
{ |
{ |
408 |
useeditmode = 0; |
useeditmode = 0; |
409 |
if (tty_isediting()) |
if (tty_isediting()) |
414 |
useeditmode |= MODE_SOFT_TAB; |
useeditmode |= MODE_SOFT_TAB; |
415 |
if (tty_islitecho()) |
if (tty_islitecho()) |
416 |
useeditmode |= MODE_LIT_ECHO; |
useeditmode |= MODE_LIT_ECHO; |
417 |
(void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, |
net_output_data ("%c%c%c%c%c%c%c", IAC, |
418 |
SB, TELOPT_LINEMODE, LM_MODE, |
SB, TELOPT_LINEMODE, LM_MODE, |
419 |
useeditmode, IAC, SE); |
useeditmode, IAC, SE); |
|
nfrontp += 7; |
|
420 |
editmode = useeditmode; |
editmode = useeditmode; |
421 |
} |
} |
422 |
|
|
472 |
set_termbuf(); |
set_termbuf(); |
473 |
|
|
474 |
if (!ack) { |
if (!ack) { |
475 |
(void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, |
net_output_data ("%c%c%c%c%c%c%c", IAC, |
476 |
SB, TELOPT_LINEMODE, LM_MODE, |
SB, TELOPT_LINEMODE, LM_MODE, |
477 |
useeditmode|MODE_ACK, |
useeditmode|MODE_ACK, |
478 |
IAC, SE); |
IAC, SE); |
|
nfrontp += 7; |
|
479 |
} |
} |
480 |
|
|
481 |
editmode = useeditmode; |
editmode = useeditmode; |
484 |
break; |
break; |
485 |
|
|
486 |
} /* end of case LM_MODE */ |
} /* end of case LM_MODE */ |
|
#endif /* LINEMODE */ |
|
487 |
|
|
488 |
case TELOPT_NAWS: |
case TELOPT_NAWS: |
489 |
#ifdef TIOCSWINSZ |
#ifdef TIOCSWINSZ |
492 |
|
|
493 |
def_col = parm1; |
def_col = parm1; |
494 |
def_row = parm2; |
def_row = parm2; |
|
#ifdef LINEMODE |
|
495 |
/* |
/* |
496 |
* Defer changing window size until after terminal is |
* Defer changing window size until after terminal is |
497 |
* initialized. |
* initialized. |
498 |
*/ |
*/ |
499 |
if (terminit() == 0) |
if (terminit() == 0) |
500 |
return; |
return; |
|
#endif /* LINEMODE */ |
|
501 |
|
|
502 |
/* |
/* |
503 |
* Change window size as requested by client. |
* Change window size as requested by client. |
515 |
{ |
{ |
516 |
def_tspeed = parm1; |
def_tspeed = parm1; |
517 |
def_rspeed = parm2; |
def_rspeed = parm2; |
|
#ifdef LINEMODE |
|
518 |
/* |
/* |
519 |
* Defer changing the terminal speed. |
* Defer changing the terminal speed. |
520 |
*/ |
*/ |
521 |
if (terminit() == 0) |
if (terminit() == 0) |
522 |
return; |
return; |
|
#endif /* LINEMODE */ |
|
523 |
/* |
/* |
524 |
* Change terminal speed as requested by client. |
* Change terminal speed as requested by client. |
525 |
* We set the receive speed first, so that if we can't |
* We set the receive speed first, so that if we can't |
567 |
} |
} |
568 |
#endif /* defined(CRAY2) && defined(UNICOS5) */ |
#endif /* defined(CRAY2) && defined(UNICOS5) */ |
569 |
|
|
|
#ifdef LINEMODE |
|
570 |
/* |
/* |
571 |
* defer_terminit |
* defer_terminit |
572 |
* |
* |
616 |
return(_terminit); |
return(_terminit); |
617 |
|
|
618 |
} /* end of terminit */ |
} /* end of terminit */ |
|
#endif /* LINEMODE */ |
|