2 * Copyright (c) 1988, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "telnet_locl.h"
41 #define strip(x) (eight ? (x) : ((x) & 0x7f))
43 static unsigned char subbuffer
[SUBBUFSIZE
],
44 *subpointer
, *subend
; /* buffer for sub-options */
45 #define SB_CLEAR() subpointer = subbuffer;
46 #define SB_TERM() { subend = subpointer; SB_CLEAR(); }
47 #define SB_ACCUM(c) if (subpointer < (subbuffer+sizeof subbuffer)) { \
48 *subpointer++ = (c); \
51 #define SB_GET() ((*subpointer++)&0xff)
52 #define SB_PEEK() ((*subpointer)&0xff)
53 #define SB_EOF() (subpointer >= subend)
54 #define SB_LEN() (subend - subpointer)
56 char options
[256]; /* The combined options */
57 char do_dont_resp
[256];
58 char will_wont_resp
[256];
63 autologin
= 0, /* Autologin anyone? */
67 ISend
, /* trying to send network data in */
70 netdata
, /* Print out network data flow */
71 crlf
, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
74 SYNCHing
, /* we are in TELNET SYNCH mode */
75 flushout
, /* flush output */
76 autoflush
= 0, /* flush output when interrupting? */
77 autosynch
, /* send interrupt characters with SYNCH? */
78 localflow
, /* we handle flow control locally */
79 restartany
, /* if flow control enabled, restart on any character */
80 localchars
, /* we recognize interrupt/quit */
81 donelclchars
, /* the user has set "localchars" */
82 donebinarytoggle
, /* the user has put us in binary */
83 dontlecho
, /* do we suppress local echoing right now? */
88 int scheduler_lockout_tty
= 0;
97 * Telnet receiver states for fsm
106 #define TS_SB 7 /* sub-option collection */
107 #define TS_SE 8 /* looking for sub-option end */
109 static int telrcv_state
;
111 unsigned char telopt_environ
= TELOPT_NEW_ENVIRON
;
113 # define telopt_environ TELOPT_NEW_ENVIRON
122 #ifdef KLUDGELINEMODE
123 int kludgelinemode
= 1;
127 * The following are some clocks used to decide how to interpret
128 * the relationship between various variables.
133 static int is_unique(char *name
, char **as
, char **ae
);
137 * Initialize telnet environment.
146 memset(options
, 0, sizeof options
);
148 connected
= ISend
= localflow
= donebinarytoggle
= 0;
149 #if defined(AUTHENTICATION) || defined(ENCRYPTION)
150 auth_encrypt_connect(connected
);
151 #endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */
156 /* Don't change NetTrace */
158 escape
= CONTROL(']');
159 rlogin
= _POSIX_VDISABLE
;
160 #ifdef KLUDGELINEMODE
161 echoc
= CONTROL('E');
165 telrcv_state
= TS_DATA
;
170 * These routines are in charge of sending option negotiations
173 * The basic idea is that we send the negotiation if either side
174 * is in disagreement as to what the current state should be.
178 send_do(int c
, int init
)
181 if (((do_dont_resp
[c
] == 0) && my_state_is_do(c
)) ||
182 my_want_state_is_do(c
))
184 set_my_want_state_do(c
);
189 printoption("SENT", DO
, c
);
193 send_dont(int c
, int init
)
196 if (((do_dont_resp
[c
] == 0) && my_state_is_dont(c
)) ||
197 my_want_state_is_dont(c
))
199 set_my_want_state_dont(c
);
204 printoption("SENT", DONT
, c
);
208 send_will(int c
, int init
)
211 if (((will_wont_resp
[c
] == 0) && my_state_is_will(c
)) ||
212 my_want_state_is_will(c
))
214 set_my_want_state_will(c
);
219 printoption("SENT", WILL
, c
);
223 send_wont(int c
, int init
)
226 if (((will_wont_resp
[c
] == 0) && my_state_is_wont(c
)) ||
227 my_want_state_is_wont(c
))
229 set_my_want_state_wont(c
);
234 printoption("SENT", WONT
, c
);
239 willoption(int option
)
241 int new_state_ok
= 0;
243 if (do_dont_resp
[option
]) {
244 --do_dont_resp
[option
];
245 if (do_dont_resp
[option
] && my_state_is_do(option
))
246 --do_dont_resp
[option
];
249 if ((do_dont_resp
[option
] == 0) && my_want_state_is_dont(option
)) {
256 settimer(modenegotiated
);
259 #if defined(AUTHENTICATION)
260 case TELOPT_AUTHENTICATION
:
262 #if defined(ENCRYPTION)
272 * Special case for TM. If we get back a WILL,
273 * pretend we got back a WONT.
275 set_my_want_state_dont(option
);
276 set_my_state_dont(option
);
277 return; /* Never reply to TM will's/wont's */
279 case TELOPT_LINEMODE
:
285 set_my_want_state_do(option
);
287 setconnmode(0); /* possibly set new tty mode */
289 do_dont_resp
[option
]++;
290 send_dont(option
, 0);
293 set_my_state_do(option
);
294 #if defined(ENCRYPTION)
295 if (option
== TELOPT_ENCRYPT
)
296 encrypt_send_support();
301 wontoption(int option
)
303 if (do_dont_resp
[option
]) {
304 --do_dont_resp
[option
];
305 if (do_dont_resp
[option
] && my_state_is_dont(option
))
306 --do_dont_resp
[option
];
309 if ((do_dont_resp
[option
] == 0) && my_want_state_is_do(option
)) {
313 #ifdef KLUDGELINEMODE
320 settimer(modenegotiated
);
326 set_my_want_state_dont(option
);
327 set_my_state_dont(option
);
328 return; /* Never reply to TM will's/wont's */
338 set_my_want_state_dont(option
);
339 if (my_state_is_do(option
))
340 send_dont(option
, 0);
341 setconnmode(0); /* Set new tty mode */
342 } else if (option
== TELOPT_TM
) {
344 * Special case for TM.
348 set_my_want_state_dont(option
);
350 set_my_state_dont(option
);
356 int new_state_ok
= 0;
358 if (will_wont_resp
[option
]) {
359 --will_wont_resp
[option
];
360 if (will_wont_resp
[option
] && my_state_is_will(option
))
361 --will_wont_resp
[option
];
364 if (will_wont_resp
[option
] == 0) {
365 if (my_want_state_is_wont(option
)) {
371 * Special case for TM. We send a WILL, but pretend
374 send_will(option
, 0);
375 set_my_want_state_wont(TELOPT_TM
);
376 set_my_state_wont(TELOPT_TM
);
379 case TELOPT_BINARY
: /* binary mode */
380 case TELOPT_NAWS
: /* window size */
381 case TELOPT_TSPEED
: /* terminal speed */
382 case TELOPT_LFLOW
: /* local flow control */
383 case TELOPT_TTYPE
: /* terminal type option */
384 case TELOPT_SGA
: /* no big deal */
385 #if defined(ENCRYPTION)
386 case TELOPT_ENCRYPT
: /* encryption variable option */
391 case TELOPT_NEW_ENVIRON
: /* New environment variable option */
393 if (my_state_is_will(TELOPT_OLD_ENVIRON
))
394 send_wont(TELOPT_OLD_ENVIRON
, 1); /* turn off the old */
396 case TELOPT_OLD_ENVIRON
: /* Old environment variable option */
397 if (my_state_is_will(TELOPT_NEW_ENVIRON
))
398 break; /* Don't enable if new one is in use! */
400 telopt_environ
= option
;
405 #if defined(AUTHENTICATION)
406 case TELOPT_AUTHENTICATION
:
412 case TELOPT_XDISPLOC
: /* X Display location */
413 if (env_getvalue((unsigned char *)"DISPLAY"))
417 case TELOPT_LINEMODE
:
418 #ifdef KLUDGELINEMODE
420 send_do(TELOPT_SGA
, 1);
422 set_my_want_state_will(TELOPT_LINEMODE
);
423 send_will(option
, 0);
424 set_my_state_will(TELOPT_LINEMODE
);
428 case TELOPT_ECHO
: /* We're never going to echo... */
434 set_my_want_state_will(option
);
435 send_will(option
, 0);
436 setconnmode(0); /* Set new tty mode */
438 will_wont_resp
[option
]++;
439 send_wont(option
, 0);
443 * Handle options that need more things done after the
444 * other side has acknowledged the option.
447 case TELOPT_LINEMODE
:
448 #ifdef KLUDGELINEMODE
450 send_do(TELOPT_SGA
, 1);
452 set_my_state_will(option
);
454 send_do(TELOPT_SGA
, 0);
459 set_my_state_will(option
);
463 dontoption(int option
)
466 if (will_wont_resp
[option
]) {
467 --will_wont_resp
[option
];
468 if (will_wont_resp
[option
] && my_state_is_wont(option
))
469 --will_wont_resp
[option
];
472 if ((will_wont_resp
[option
] == 0) && my_want_state_is_will(option
)) {
474 case TELOPT_LINEMODE
:
475 linemode
= 0; /* put us back to the default state */
478 case TELOPT_NEW_ENVIRON
:
480 * The new environ option wasn't recognized, try
483 send_will(TELOPT_OLD_ENVIRON
, 1);
484 telopt_environ
= TELOPT_OLD_ENVIRON
;
495 /* we always accept a DONT */
496 set_my_want_state_wont(option
);
497 if (my_state_is_will(option
))
498 send_wont(option
, 0);
499 setconnmode(0); /* Set new tty mode */
501 set_my_state_wont(option
);
505 * Given a buffer returned by tgetent(), this routine will turn
506 * the pipe seperated list of names in the buffer into an array
507 * of pointers to null terminated names. We toss out any bad,
508 * duplicate, or verbose names (names with spaces).
511 static char *name_unknown
= "UNKNOWN";
512 static char *unknown
[] = { 0, 0 };
515 mklist(char *buf
, char *name
)
518 char c
, *cp
, **argvp
, *cp2
, **argv
, **avt
;
521 if ((int)strlen(name
) > 40) {
523 unknown
[0] = name_unknown
;
529 unknown
[0] = name_unknown
;
531 * Count up the number of names.
533 for (n
= 1, cp
= buf
; *cp
&& *cp
!= ':'; cp
++) {
538 * Allocate an array to put the name pointers into
540 argv
= (char **)malloc((n
+3)*sizeof(char *));
545 * Fill up the array of pointers to names.
550 for (cp
= cp2
= buf
; (c
= *cp
); cp
++) {
551 if (c
== '|' || c
== ':') {
554 * Skip entries that have spaces or are over 40
555 * characters long. If this is our environment
556 * name, then put it up front. Otherwise, as
557 * long as this is not a duplicate name (case
558 * insensitive) add it to the list.
560 if (n
|| (cp
- cp2
> 41))
562 else if (name
&& (strncasecmp(name
, cp2
, cp
-cp2
) == 0))
564 else if (is_unique(cp2
, argv
+1, argvp
))
569 * Skip multiple delimiters. Reset cp2 to
570 * the beginning of the next name. Reset n,
571 * the flag for names with spaces.
573 while ((c
= *cp
) == '|')
579 * Skip entries with spaces or non-ascii values.
580 * Convert lower case letters to upper case.
582 #define ISASCII(c) (!((c)&0x80))
583 if ((c
== ' ') || !ISASCII(c
))
585 else if (islower((unsigned char)c
))
590 * Check for an old V6 2 character name. If the second
591 * name points to the beginning of the buffer, and is
592 * only 2 characters long, move it to the end of the array.
594 if ((argv
[1] == buf
) && (strlen(argv
[1]) == 2)) {
596 for (avt
= &argv
[1]; avt
< argvp
; avt
++)
602 * Duplicate last name, for TTYPE option, and null
603 * terminate the array. If we didn't find a match on
604 * our terminal name, put that name at the beginning.
615 for (avt
= argv
; avt
< argvp
; avt
++)
626 is_unique(char *name
, char **as
, char **ae
)
631 n
= strlen(name
) + 1;
632 for (ap
= as
; ap
< ae
; ap
++)
633 if (strncasecmp(*ap
, name
, n
) == 0)
638 static char termbuf
[1024];
641 telnet_setupterm(const char *tname
, int fd
, int *errp
)
644 if (tgetent(termbuf
, tname
) == 1) {
645 termbuf
[1023] = '\0';
654 strlcpy(termbuf
, tname
, sizeof(termbuf
));
660 int resettermname
= 1;
666 static char **tnamep
= 0;
672 if (tnamep
&& tnamep
!= unknown
)
674 if ((tname
= (char *)env_getvalue((unsigned char *)"TERM")) &&
675 telnet_setupterm(tname
, 1, &err
) == 0) {
676 tnamep
= mklist(termbuf
, tname
);
678 if (tname
&& ((int)strlen(tname
) <= 40)) {
682 unknown
[0] = name_unknown
;
694 * Look at the sub-option buffer, and try to be helpful to the other
697 * Currently we recognize:
699 * Terminal type, send request.
700 * Terminal speed (send request).
701 * Local flow control (is request).
708 unsigned char subchar
;
710 printsub('<', subbuffer
, SB_LEN()+2);
711 switch (subchar
= SB_GET()) {
713 if (my_want_state_is_wont(TELOPT_TTYPE
))
715 if (SB_EOF() || SB_GET() != TELQUAL_SEND
) {
719 unsigned char temp
[50];
722 name
= gettermname();
723 len
= strlen(name
) + 4 + 2;
724 if (len
< NETROOM()) {
725 snprintf((char *)temp
, sizeof(temp
),
726 "%c%c%c%c%s%c%c", IAC
, SB
, TELOPT_TTYPE
,
727 TELQUAL_IS
, name
, IAC
, SE
);
728 ring_supply_data(&netoring
, temp
, len
);
729 printsub('>', &temp
[2], len
-2);
731 ExitString("No room in buffer for terminal type.\n", 1);
737 if (my_want_state_is_wont(TELOPT_TSPEED
))
741 if (SB_GET() == TELQUAL_SEND
) {
742 long output_speed
, input_speed
;
743 unsigned char temp
[50];
746 TerminalSpeeds(&input_speed
, &output_speed
);
748 snprintf((char *)temp
, sizeof(temp
),
749 "%c%c%c%c%u,%u%c%c", IAC
, SB
, TELOPT_TSPEED
,
751 (unsigned)output_speed
,
752 (unsigned)input_speed
, IAC
, SE
);
753 len
= strlen((char *)temp
+4) + 4; /* temp[3] is 0 ... */
755 if (len
< NETROOM()) {
756 ring_supply_data(&netoring
, temp
, len
);
757 printsub('>', temp
+2, len
- 2);
759 /*@*/ else printf("lm_will: not enough room in buffer\n");
763 if (my_want_state_is_wont(TELOPT_LFLOW
))
768 case LFLOW_RESTART_ANY
:
771 case LFLOW_RESTART_XON
:
787 case TELOPT_LINEMODE
:
788 if (my_want_state_is_wont(TELOPT_LINEMODE
))
794 lm_will(subpointer
, SB_LEN());
797 lm_wont(subpointer
, SB_LEN());
800 lm_do(subpointer
, SB_LEN());
803 lm_dont(subpointer
, SB_LEN());
806 slc(subpointer
, SB_LEN());
809 lm_mode(subpointer
, SB_LEN(), 0);
817 case TELOPT_OLD_ENVIRON
:
819 case TELOPT_NEW_ENVIRON
:
825 if (my_want_state_is_dont(subchar
))
829 if (my_want_state_is_wont(subchar
)) {
836 env_opt(subpointer
, SB_LEN());
839 case TELOPT_XDISPLOC
:
840 if (my_want_state_is_wont(TELOPT_XDISPLOC
))
844 if (SB_GET() == TELQUAL_SEND
) {
845 unsigned char temp
[50], *dp
;
848 if ((dp
= env_getvalue((unsigned char *)"DISPLAY")) == NULL
) {
850 * Something happened, we no longer have a DISPLAY
851 * variable. So, turn off the option.
853 send_wont(TELOPT_XDISPLOC
, 1);
856 snprintf((char *)temp
, sizeof(temp
),
857 "%c%c%c%c%s%c%c", IAC
, SB
, TELOPT_XDISPLOC
,
858 TELQUAL_IS
, dp
, IAC
, SE
);
859 len
= strlen((char *)temp
+4) + 4; /* temp[3] is 0 ... */
861 if (len
< NETROOM()) {
862 ring_supply_data(&netoring
, temp
, len
);
863 printsub('>', temp
+2, len
- 2);
865 /*@*/ else printf("lm_will: not enough room in buffer\n");
869 #if defined(AUTHENTICATION)
870 case TELOPT_AUTHENTICATION
: {
877 if (my_want_state_is_dont(TELOPT_AUTHENTICATION
))
879 auth_is(subpointer
, SB_LEN());
882 if (my_want_state_is_wont(TELOPT_AUTHENTICATION
))
884 auth_send(subpointer
, SB_LEN());
887 if (my_want_state_is_wont(TELOPT_AUTHENTICATION
))
889 auth_reply(subpointer
, SB_LEN());
892 if (my_want_state_is_dont(TELOPT_AUTHENTICATION
))
894 auth_name(subpointer
, SB_LEN());
900 #if defined(ENCRYPTION)
906 if (my_want_state_is_dont(TELOPT_ENCRYPT
))
908 encrypt_start(subpointer
, SB_LEN());
911 if (my_want_state_is_dont(TELOPT_ENCRYPT
))
915 case ENCRYPT_SUPPORT
:
916 if (my_want_state_is_wont(TELOPT_ENCRYPT
))
918 encrypt_support(subpointer
, SB_LEN());
920 case ENCRYPT_REQSTART
:
921 if (my_want_state_is_wont(TELOPT_ENCRYPT
))
923 encrypt_request_start(subpointer
, SB_LEN());
926 if (my_want_state_is_wont(TELOPT_ENCRYPT
))
929 * We can always send an REQEND so that we cannot
930 * get stuck encrypting. We should only get this
931 * if we have been able to get in the correct mode
934 encrypt_request_end();
937 if (my_want_state_is_dont(TELOPT_ENCRYPT
))
939 encrypt_is(subpointer
, SB_LEN());
942 if (my_want_state_is_wont(TELOPT_ENCRYPT
))
944 encrypt_reply(subpointer
, SB_LEN());
946 case ENCRYPT_ENC_KEYID
:
947 if (my_want_state_is_dont(TELOPT_ENCRYPT
))
949 encrypt_enc_keyid(subpointer
, SB_LEN());
951 case ENCRYPT_DEC_KEYID
:
952 if (my_want_state_is_wont(TELOPT_ENCRYPT
))
954 encrypt_dec_keyid(subpointer
, SB_LEN());
966 static unsigned char str_lm
[] = { IAC
, SB
, TELOPT_LINEMODE
, 0, 0, IAC
, SE
};
969 lm_will(unsigned char *cmd
, int len
)
972 /*@*/ printf("lm_will: no command!!!\n"); /* Should not happen... */
976 case LM_FORWARDMASK
: /* We shouldn't ever get this... */
980 if (NETROOM() > sizeof(str_lm
)) {
981 ring_supply_data(&netoring
, str_lm
, sizeof(str_lm
));
982 printsub('>', &str_lm
[2], sizeof(str_lm
)-2);
984 /*@*/ else printf("lm_will: not enough room in buffer\n");
990 lm_wont(unsigned char *cmd
, int len
)
993 /*@*/ printf("lm_wont: no command!!!\n"); /* Should not happen... */
997 case LM_FORWARDMASK
: /* We shouldn't ever get this... */
999 /* We are always DONT, so don't respond */
1005 lm_do(unsigned char *cmd
, int len
)
1008 /*@*/ printf("lm_do: no command!!!\n"); /* Should not happen... */
1012 case LM_FORWARDMASK
:
1016 if (NETROOM() > sizeof(str_lm
)) {
1017 ring_supply_data(&netoring
, str_lm
, sizeof(str_lm
));
1018 printsub('>', &str_lm
[2], sizeof(str_lm
)-2);
1020 /*@*/ else printf("lm_do: not enough room in buffer\n");
1026 lm_dont(unsigned char *cmd
, int len
)
1029 /*@*/ printf("lm_dont: no command!!!\n"); /* Should not happen... */
1033 case LM_FORWARDMASK
:
1035 /* we are always WONT, so don't respond */
1040 static unsigned char str_lm_mode
[] = {
1041 IAC
, SB
, TELOPT_LINEMODE
, LM_MODE
, 0, IAC
, SE
1045 lm_mode(unsigned char *cmd
, int len
, int init
)
1049 if ((linemode
&MODE_MASK
&~MODE_ACK
) == *cmd
)
1053 linemode
= *cmd
&(MODE_MASK
&~MODE_ACK
);
1054 str_lm_mode
[4] = linemode
;
1056 str_lm_mode
[4] |= MODE_ACK
;
1057 if (NETROOM() > sizeof(str_lm_mode
)) {
1058 ring_supply_data(&netoring
, str_lm_mode
, sizeof(str_lm_mode
));
1059 printsub('>', &str_lm_mode
[2], sizeof(str_lm_mode
)-2);
1061 /*@*/ else printf("lm_mode: not enough room in buffer\n");
1062 setconnmode(0); /* set changed mode */
1069 * Handle special character suboption of LINEMODE.
1075 char flags
; /* Current flags & level */
1076 char mylevel
; /* Maximum level & flags */
1079 #define SLC_IMPORT 0
1080 #define SLC_EXPORT 1
1081 #define SLC_RVALUE 2
1082 static int slc_mode
= SLC_EXPORT
;
1090 for (spcp
= spc_data
; spcp
< &spc_data
[NSLC
+1]; spcp
++) {
1093 spcp
->flags
= spcp
->mylevel
= SLC_NOSUPPORT
;
1096 #define initfunc(func, flags) { \
1097 spcp = &spc_data[func]; \
1098 if ((spcp->valp = tcval(func))) { \
1099 spcp->val = *spcp->valp; \
1100 spcp->mylevel = SLC_VARIABLE|flags; \
1103 spcp->mylevel = SLC_DEFAULT; \
1107 initfunc(SLC_SYNCH
, 0);
1109 initfunc(SLC_AO
, 0);
1110 initfunc(SLC_AYT
, 0);
1112 initfunc(SLC_ABORT
, SLC_FLUSHIN
|SLC_FLUSHOUT
);
1113 initfunc(SLC_EOF
, 0);
1114 initfunc(SLC_SUSP
, SLC_FLUSHIN
);
1115 initfunc(SLC_EC
, 0);
1116 initfunc(SLC_EL
, 0);
1117 initfunc(SLC_EW
, 0);
1118 initfunc(SLC_RP
, 0);
1119 initfunc(SLC_LNEXT
, 0);
1120 initfunc(SLC_XON
, 0);
1121 initfunc(SLC_XOFF
, 0);
1122 initfunc(SLC_FORW1
, 0);
1123 initfunc(SLC_FORW2
, 0);
1126 initfunc(SLC_IP
, SLC_FLUSHIN
|SLC_FLUSHOUT
);
1129 if (slc_mode
== SLC_EXPORT
)
1139 printf("Special characters are %s values\n",
1140 slc_mode
== SLC_IMPORT
? "remote default" :
1141 slc_mode
== SLC_EXPORT
? "local" :
1148 slc_mode
= SLC_EXPORT
;
1149 if (my_state_is_will(TELOPT_LINEMODE
))
1154 slc_mode_import(int def
)
1156 slc_mode
= def
? SLC_IMPORT
: SLC_RVALUE
;
1157 if (my_state_is_will(TELOPT_LINEMODE
))
1161 unsigned char slc_import_val
[] = {
1162 IAC
, SB
, TELOPT_LINEMODE
, LM_SLC
, 0, SLC_VARIABLE
, 0, IAC
, SE
1164 unsigned char slc_import_def
[] = {
1165 IAC
, SB
, TELOPT_LINEMODE
, LM_SLC
, 0, SLC_DEFAULT
, 0, IAC
, SE
1171 if (NETROOM() > sizeof(slc_import_val
)) {
1173 ring_supply_data(&netoring
, slc_import_def
, sizeof(slc_import_def
));
1174 printsub('>', &slc_import_def
[2], sizeof(slc_import_def
)-2);
1176 ring_supply_data(&netoring
, slc_import_val
, sizeof(slc_import_val
));
1177 printsub('>', &slc_import_val
[2], sizeof(slc_import_val
)-2);
1180 /*@*/ else printf("slc_import: not enough room\n");
1188 TerminalDefaultChars();
1191 for (spcp
= &spc_data
[1]; spcp
< &spc_data
[NSLC
+1]; spcp
++) {
1192 if (spcp
->mylevel
!= SLC_NOSUPPORT
) {
1193 if (spcp
->val
== (cc_t
)(_POSIX_VDISABLE
))
1194 spcp
->flags
= SLC_NOSUPPORT
;
1196 spcp
->flags
= spcp
->mylevel
;
1198 spcp
->val
= *spcp
->valp
;
1199 slc_add_reply(spcp
- spc_data
, spcp
->flags
, spcp
->val
);
1204 setconnmode(1); /* Make sure the character values are set */
1208 slc(unsigned char *cp
, int len
)
1215 for (; len
>= 3; len
-=3, cp
+=3) {
1217 func
= cp
[SLC_FUNC
];
1221 * Client side: always ignore 0 function.
1226 if ((cp
[SLC_FLAGS
] & SLC_LEVELBITS
) != SLC_NOSUPPORT
)
1227 slc_add_reply(func
, SLC_NOSUPPORT
, 0);
1231 spcp
= &spc_data
[func
];
1233 level
= cp
[SLC_FLAGS
]&(SLC_LEVELBITS
|SLC_ACK
);
1235 if ((cp
[SLC_VALUE
] == (unsigned char)spcp
->val
) &&
1236 ((level
&SLC_LEVELBITS
) == (spcp
->flags
&SLC_LEVELBITS
))) {
1240 if (level
== (SLC_DEFAULT
|SLC_ACK
)) {
1242 * This is an error condition, the SLC_ACK
1243 * bit should never be set for the SLC_DEFAULT
1244 * level. Our best guess to recover is to
1245 * ignore the SLC_ACK bit.
1247 cp
[SLC_FLAGS
] &= ~SLC_ACK
;
1250 if (level
== ((spcp
->flags
&SLC_LEVELBITS
)|SLC_ACK
)) {
1251 spcp
->val
= (cc_t
)cp
[SLC_VALUE
];
1252 spcp
->flags
= cp
[SLC_FLAGS
]; /* include SLC_ACK */
1258 if (level
<= (spcp
->mylevel
&SLC_LEVELBITS
)) {
1259 spcp
->flags
= cp
[SLC_FLAGS
]|SLC_ACK
;
1260 spcp
->val
= (cc_t
)cp
[SLC_VALUE
];
1262 if (level
== SLC_DEFAULT
) {
1263 if ((spcp
->mylevel
&SLC_LEVELBITS
) != SLC_DEFAULT
)
1264 spcp
->flags
= spcp
->mylevel
;
1266 spcp
->flags
= SLC_NOSUPPORT
;
1268 slc_add_reply(func
, spcp
->flags
, spcp
->val
);
1272 setconnmode(1); /* set the new character values */
1281 for (spcp
= &spc_data
[1]; spcp
< &spc_data
[NSLC
+1]; spcp
++) {
1282 if (spcp
->valp
&& spcp
->val
!= *spcp
->valp
) {
1283 spcp
->val
= *spcp
->valp
;
1284 if (spcp
->val
== (cc_t
)(_POSIX_VDISABLE
))
1285 spcp
->flags
= SLC_NOSUPPORT
;
1287 spcp
->flags
= spcp
->mylevel
;
1288 slc_add_reply(spcp
- spc_data
, spcp
->flags
, spcp
->val
);
1296 unsigned char slc_reply
[128];
1297 unsigned char const * const slc_reply_eom
= &slc_reply
[sizeof(slc_reply
)];
1298 unsigned char *slc_replyp
;
1303 slc_replyp
= slc_reply
;
1304 *slc_replyp
++ = IAC
;
1306 *slc_replyp
++ = TELOPT_LINEMODE
;
1307 *slc_replyp
++ = LM_SLC
;
1311 slc_add_reply(unsigned char func
, unsigned char flags
, cc_t value
)
1313 /* A sequence of up to 6 bytes my be written for this member of the SLC
1314 * suboption list by this function. The end of negotiation command,
1315 * which is written by slc_end_reply(), will require 2 additional
1316 * bytes. Do not proceed unless there is sufficient space for these
1319 if (&slc_replyp
[6+2] > slc_reply_eom
)
1321 if ((*slc_replyp
++ = func
) == IAC
)
1322 *slc_replyp
++ = IAC
;
1323 if ((*slc_replyp
++ = flags
) == IAC
)
1324 *slc_replyp
++ = IAC
;
1325 if ((*slc_replyp
++ = (unsigned char)value
) == IAC
)
1326 *slc_replyp
++ = IAC
;
1334 /* The end of negotiation command requires 2 bytes. */
1335 if (&slc_replyp
[2] > slc_reply_eom
)
1337 *slc_replyp
++ = IAC
;
1339 len
= slc_replyp
- slc_reply
;
1342 if (NETROOM() > len
) {
1343 ring_supply_data(&netoring
, slc_reply
, slc_replyp
- slc_reply
);
1344 printsub('>', &slc_reply
[2], slc_replyp
- slc_reply
- 2);
1346 /*@*/else printf("slc_end_reply: not enough room\n");
1353 int need_update
= 0;
1355 for (spcp
= &spc_data
[1]; spcp
< &spc_data
[NSLC
+1]; spcp
++) {
1356 if (!(spcp
->flags
&SLC_ACK
))
1358 spcp
->flags
&= ~SLC_ACK
;
1359 if (spcp
->valp
&& (*spcp
->valp
!= spcp
->val
)) {
1360 *spcp
->valp
= spcp
->val
;
1364 return(need_update
);
1368 # define old_env_var OLD_ENV_VAR
1369 # define old_env_value OLD_ENV_VALUE
1373 env_opt(unsigned char *buf
, int len
)
1375 unsigned char *ep
= 0, *epc
= 0;
1378 switch(buf
[0]&0xff) {
1383 } else for (i
= 1; i
< len
; i
++) {
1384 switch (buf
[i
]&0xff) {
1389 * Although OLD_ENV_VALUE is not legal, we will
1390 * still recognize it, just in case it is an
1391 * old server that has VAR & VALUE mixed up...
1402 ep
= epc
= &buf
[i
+1];
1422 /* Ignore for now. We shouldn't get it anyway. */
1430 #define OPT_REPLY_SIZE (2 * SUBBUFSIZE)
1431 unsigned char *opt_reply
;
1432 unsigned char *opt_replyp
;
1433 unsigned char *opt_replyend
;
1439 void *tmp
= realloc (opt_reply
, OPT_REPLY_SIZE
);
1447 opt_reply
= (unsigned char *)malloc(OPT_REPLY_SIZE
);
1448 if (opt_reply
== NULL
) {
1449 /*@*/ printf("env_opt_start: malloc()/realloc() failed!!!\n");
1450 opt_reply
= opt_replyp
= opt_replyend
= NULL
;
1453 opt_replyp
= opt_reply
;
1454 opt_replyend
= opt_reply
+ OPT_REPLY_SIZE
;
1455 *opt_replyp
++ = IAC
;
1457 *opt_replyp
++ = telopt_environ
;
1458 *opt_replyp
++ = TELQUAL_IS
;
1462 env_opt_start_info()
1466 opt_replyp
[-1] = TELQUAL_INFO
;
1470 env_opt_add(unsigned char *ep
)
1472 unsigned char *vp
, c
;
1474 if (opt_reply
== NULL
) /*XXX*/
1477 if (ep
== NULL
|| *ep
== '\0') {
1478 /* Send user defined variables first. */
1480 while ((ep
= env_default(0, 0)))
1483 /* Now add the list of well know variables. */
1485 while ((ep
= env_default(0, 1)))
1489 vp
= env_getvalue(ep
);
1490 if (opt_replyp
+ (vp
? 2 * strlen((char *)vp
) : 0) +
1491 2 * strlen((char *)ep
) + 6 > opt_replyend
)
1495 opt_replyend
+= OPT_REPLY_SIZE
;
1496 len
= opt_replyend
- opt_reply
;
1497 tmp
= realloc(opt_reply
, len
);
1499 /*@*/ printf("env_opt_add: realloc() failed!!!\n");
1500 opt_reply
= opt_replyp
= opt_replyend
= NULL
;
1504 opt_replyp
= opt_reply
+ len
- (opt_replyend
- opt_replyp
);
1505 opt_replyend
= opt_reply
+ len
;
1507 if (opt_welldefined((char *)ep
)) {
1509 if (telopt_environ
== TELOPT_OLD_ENVIRON
)
1510 *opt_replyp
++ = old_env_var
;
1513 *opt_replyp
++ = NEW_ENV_VAR
;
1515 *opt_replyp
++ = ENV_USERVAR
;
1517 while ((c
= *ep
++)) {
1518 if (opt_replyp
+ (2 + 2) > opt_replyend
)
1522 *opt_replyp
++ = IAC
;
1528 *opt_replyp
++ = ENV_ESC
;
1534 if (opt_replyp
+ (1 + 2 + 2) > opt_replyend
)
1537 if (telopt_environ
== TELOPT_OLD_ENVIRON
)
1538 *opt_replyp
++ = old_env_value
;
1541 *opt_replyp
++ = NEW_ENV_VALUE
;
1549 opt_welldefined(char *ep
)
1551 if ((strcmp(ep
, "USER") == 0) ||
1552 (strcmp(ep
, "DISPLAY") == 0) ||
1553 (strcmp(ep
, "PRINTER") == 0) ||
1554 (strcmp(ep
, "SYSTEMTYPE") == 0) ||
1555 (strcmp(ep
, "JOB") == 0) ||
1556 (strcmp(ep
, "ACCT") == 0))
1562 env_opt_end(int emptyok
)
1566 if (opt_replyp
+ 2 > opt_replyend
)
1568 len
= opt_replyp
+ 2 - opt_reply
;
1569 if (emptyok
|| len
> 6) {
1570 *opt_replyp
++ = IAC
;
1572 if (NETROOM() > len
) {
1573 ring_supply_data(&netoring
, opt_reply
, len
);
1574 printsub('>', &opt_reply
[2], len
- 2);
1576 /*@*/ else printf("slc_end_reply: not enough room\n");
1580 opt_reply
= opt_replyp
= opt_replyend
= NULL
;
1591 unsigned char *sbp
= NULL
;
1593 int returnValue
= 0;
1597 while (TTYROOM() > 2) {
1600 ring_consumed(&netiring
, count
);
1604 sbp
= netiring
.consume
;
1605 scc
= ring_full_consecutive(&netiring
);
1607 /* No more data coming in */
1612 c
= *sbp
++ & 0xff, scc
--; count
++;
1613 #if defined(ENCRYPTION)
1615 c
= (*decrypt_input
)(c
);
1618 switch (telrcv_state
) {
1621 telrcv_state
= TS_DATA
;
1623 break; /* Ignore \0 after CR */
1625 else if ((c
== '\n') && my_want_state_is_dont(TELOPT_ECHO
) && !crmod
) {
1629 /* Else, fall through */
1633 telrcv_state
= TS_IAC
;
1637 * The 'crmod' hack (see following) is needed
1638 * since we can't set CRMOD on output only.
1639 * Machines like MULTICS like to send \r without
1640 * \n; since we must turn off CRMOD to get proper
1641 * input, the mapping is done here (sigh).
1643 if ((c
== '\r') && my_want_state_is_dont(TELOPT_BINARY
)) {
1646 #if defined(ENCRYPTION)
1648 c
= (*decrypt_input
)(c
);
1651 sbp
++, scc
--; count
++;
1654 } else if (my_want_state_is_dont(TELOPT_ECHO
) &&
1656 sbp
++, scc
--; count
++;
1659 #if defined(ENCRYPTION)
1661 (*decrypt_input
)(-1);
1670 telrcv_state
= TS_CR
;
1686 telrcv_state
= TS_WILL
;
1690 telrcv_state
= TS_WONT
;
1694 telrcv_state
= TS_DO
;
1698 telrcv_state
= TS_DONT
;
1703 * We may have missed an urgent notification,
1704 * so make sure we flush whatever is in the
1707 printoption("RCVD", IAC
, DM
);
1710 SYNCHing
= stilloob();
1716 telrcv_state
= TS_SB
;
1727 printoption("RCVD", IAC
, c
);
1730 telrcv_state
= TS_DATA
;
1734 printoption("RCVD", WILL
, c
);
1736 telrcv_state
= TS_DATA
;
1740 printoption("RCVD", WONT
, c
);
1742 telrcv_state
= TS_DATA
;
1746 printoption("RCVD", DO
, c
);
1748 if (c
== TELOPT_NAWS
) {
1750 } else if (c
== TELOPT_LFLOW
) {
1755 telrcv_state
= TS_DATA
;
1759 printoption("RCVD", DONT
, c
);
1762 setconnmode(0); /* set new tty mode (maybe) */
1763 telrcv_state
= TS_DATA
;
1768 telrcv_state
= TS_SE
;
1778 * This is an error. We only expect to get
1779 * "IAC IAC" or "IAC SE". Several things may
1780 * have happend. An IAC was not doubled, the
1781 * IAC SE was left off, or another option got
1782 * inserted into the suboption are all possibilities.
1783 * If we assume that the IAC was not doubled,
1784 * and really the IAC SE was left off, we could
1785 * get into an infinate loop here. So, instead,
1786 * we terminate the suboption, and process the
1787 * partial suboption if we can.
1794 printoption("In SUBOPTION processing, RCVD", IAC
, c
);
1795 suboption(); /* handle sub-option */
1796 telrcv_state
= TS_IAC
;
1800 telrcv_state
= TS_SB
;
1806 suboption(); /* handle sub-option */
1807 telrcv_state
= TS_DATA
;
1812 ring_consumed(&netiring
, count
);
1813 return returnValue
||count
;
1816 static int bol
= 1, local
= 0;
1824 command(0, "z\n", 2);
1835 int returnValue
= 0;
1836 unsigned char *tbp
= NULL
;
1840 while (NETROOM() > 2) {
1846 ring_consumed(&ttyiring
, count
);
1850 tbp
= ttyiring
.consume
;
1851 tcc
= ring_full_consecutive(&ttyiring
);
1856 c
= *tbp
++ & 0xff, sc
= strip(c
), tcc
--; count
++;
1857 if (rlogin
!= _POSIX_VDISABLE
) {
1866 if (sc
== '.' || c
== termEofChar
) {
1868 command(0, "close\n", 6);
1871 if (sc
== termSuspChar
) {
1873 command(0, "z\n", 2);
1877 command(0, (char *)tbp
, tcc
);
1891 if ((sc
== '\n') || (sc
== '\r'))
1893 } else if (sc
== escape
) {
1895 * Double escape is a pass through of a single escape character.
1897 if (tcc
&& strip(*tbp
) == escape
) {
1903 command(0, (char *)tbp
, tcc
);
1912 #ifdef KLUDGELINEMODE
1913 if (kludgelinemode
&& (globalmode
&MODE_EDIT
) && (sc
== echoc
)) {
1914 if (tcc
> 0 && strip(*tbp
) == echoc
) {
1915 tcc
--; tbp
++; count
++;
1917 dontlecho
= !dontlecho
;
1918 settimer(echotoggle
);
1925 if (MODE_LOCAL_CHARS(globalmode
)) {
1926 if (TerminalSpecialChars(sc
) == 0) {
1931 if (my_want_state_is_wont(TELOPT_BINARY
)) {
1935 * If we are in CRMOD mode (\r ==> \n)
1936 * on our local machine, then probably
1937 * a newline (unix) is CRLF (TELNET).
1939 if (MODE_LOCAL_CHARS(globalmode
)) {
1943 bol
= flushline
= 1;
1947 NET2ADD('\r', '\0');
1949 NET2ADD('\r', '\n');
1951 bol
= flushline
= 1;
1960 } else if (c
== IAC
) {
1967 ring_consumed(&ttyiring
, count
);
1968 return returnValue
||count
; /* Non-zero if we did anything */
1974 * Try to do something.
1976 * If we do something useful, return 1; else return 0.
1982 Scheduler(int block
) /* should we block in the select ? */
1984 /* One wants to be a bit careful about setting returnValue
1985 * to one, since a one implies we did some useful work,
1986 * and therefore probably won't be called to block next
1987 * time (TN3270 mode only).
1990 int netin
, netout
, netex
, ttyin
, ttyout
;
1992 /* Decide which rings should be processed */
1994 netout
= ring_full_count(&netoring
) &&
1996 (my_want_state_is_wont(TELOPT_LINEMODE
)
1997 #ifdef KLUDGELINEMODE
1998 && (!kludgelinemode
|| my_want_state_is_do(TELOPT_SGA
))
2001 my_want_state_is_will(TELOPT_BINARY
));
2002 ttyout
= ring_full_count(&ttyoring
);
2004 ttyin
= ring_empty_count(&ttyiring
);
2006 netin
= !ISend
&& ring_empty_count(&netiring
);
2010 /* If we have seen a signal recently, reset things */
2012 if (scheduler_lockout_tty
) {
2016 /* Call to system code to process rings */
2018 returnValue
= process_rings(netin
, netout
, netex
, ttyin
, ttyout
, !block
);
2020 /* Now, look at the input rings, looking for work to do. */
2022 if (ring_full_count(&ttyiring
)) {
2023 returnValue
|= telsnd();
2026 if (ring_full_count(&netiring
)) {
2027 returnValue
|= telrcv();
2033 * Select from tty and network...
2036 my_telnet(char *user
)
2038 int printed_encrypt
= 0;
2042 #if defined(AUTHENTICATION) || defined(ENCRYPTION)
2044 static char local_host
[256] = { 0 };
2046 if (!local_host
[0]) {
2047 /* XXX - should be k_gethostname? */
2048 gethostname(local_host
, sizeof(local_host
));
2049 local_host
[sizeof(local_host
)-1] = 0;
2051 auth_encrypt_init(local_host
, hostname
, "TELNET", 0);
2052 auth_encrypt_user(user
);
2056 #if defined(AUTHENTICATION)
2058 send_will(TELOPT_AUTHENTICATION
, 1);
2060 #if defined(ENCRYPTION)
2061 send_do(TELOPT_ENCRYPT
, 1);
2062 send_will(TELOPT_ENCRYPT
, 1);
2064 send_do(TELOPT_SGA
, 1);
2065 send_will(TELOPT_TTYPE
, 1);
2066 send_will(TELOPT_NAWS
, 1);
2067 send_will(TELOPT_TSPEED
, 1);
2068 send_will(TELOPT_LFLOW
, 1);
2069 send_will(TELOPT_LINEMODE
, 1);
2070 send_will(TELOPT_NEW_ENVIRON
, 1);
2071 send_do(TELOPT_STATUS
, 1);
2072 if (env_getvalue((unsigned char *)"DISPLAY"))
2073 send_will(TELOPT_XDISPLOC
, 1);
2075 tel_enter_binary(binary
);
2080 * Note: we assume a tie to the authentication option here. This
2081 * is necessary so that authentication fails, we don't spin
2084 if (telnetport
&& wantencryption
) {
2085 extern int auth_has_failed
;
2086 time_t timeout
= time(0) + 60;
2088 send_do(TELOPT_ENCRYPT
, 1);
2089 send_will(TELOPT_ENCRYPT
, 1);
2091 if (my_want_state_is_wont(TELOPT_AUTHENTICATION
)) {
2092 if (wantencryption
== -1) {
2095 printf("\nServer refused to negotiate authentication,\n");
2096 printf("which is required for encryption.\n");
2100 if (auth_has_failed
) {
2101 printf("\nAuthentication negotation has failed,\n");
2102 printf("which is required for encryption.\n");
2105 if (my_want_state_is_dont(TELOPT_ENCRYPT
) ||
2106 my_want_state_is_wont(TELOPT_ENCRYPT
)) {
2107 printf("\nServer refused to negotiate encryption.\n");
2110 if (encrypt_is_encrypting())
2112 if (time(0) > timeout
) {
2113 printf("\nEncryption could not be enabled.\n");
2116 if (printed_encrypt
== 0) {
2117 printed_encrypt
= 1;
2118 printf("Waiting for encryption to be negotiated...\n");
2120 * Turn on MODE_TRAPSIG and then turn off localchars
2121 * so that ^C will cause telnet to exit.
2123 TerminalNewMode(getconnmode()|MODE_TRAPSIG
);
2126 if (intr_happened
) {
2127 printf("\nUser interrupt.\n");
2132 if (printed_encrypt
) {
2133 printf("Encryption negotiated.\n");
2143 while ((schedValue
= Scheduler(0)) != 0) {
2144 if (schedValue
== -1) {
2150 if (Scheduler(1) == -1) {
2160 * We are about to do a TELNET SYNCH operation. Clear
2161 * the path to the network.
2163 * Things are a bit tricky since we may have sent the first
2164 * byte or so of a previous TELNET command into the network.
2165 * So, we have to scan the network buffer from the beginning
2166 * until we are up to where we want to be.
2168 * A side effect of what we do, just to keep things
2169 * simple, is to clear the urgent data pointer. The principal
2170 * caller should be setting the urgent data pointer AFTER calling
2178 char *thisitem
, *next
;
2180 #define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \
2181 ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))
2185 while ((next
= nextitem(thisitem
)) <= netobuf
.send
) {
2189 /* Now, thisitem is first before/at boundary. */
2191 good
= netobuf
; /* where the good bytes go */
2193 while (netoring
.add
> thisitem
) {
2194 if (wewant(thisitem
)) {
2199 next
= nextitem(next
);
2200 } while (wewant(next
) && (nfrontp
> next
));
2201 length
= next
-thisitem
;
2202 memmove(good
, thisitem
, length
);
2206 thisitem
= nextitem(thisitem
);
2214 * These routines add various telnet commands to the data stream.
2224 ttyflush(1); /* Flush/drop output */
2225 /* do printoption AFTER flush, otherwise the output gets tossed... */
2226 printoption("SENT", DO
, TELOPT_TM
);
2233 printoption("SENT", IAC
, AO
);
2244 printoption("SENT", IAC
, EL
);
2251 printoption("SENT", IAC
, EC
);
2258 netclear(); /* clear the path to the network */
2262 printoption("SENT", IAC
, DM
);
2266 int want_status_response
= 0;
2271 unsigned char tmp
[16];
2274 if (my_want_state_is_dont(TELOPT_STATUS
)) {
2275 printf("Remote side does not support STATUS option\n");
2282 *cp
++ = TELOPT_STATUS
;
2283 *cp
++ = TELQUAL_SEND
;
2286 if (NETROOM() >= cp
- tmp
) {
2287 ring_supply_data(&netoring
, tmp
, cp
-tmp
);
2288 printsub('>', tmp
+2, cp
- tmp
- 2);
2290 ++want_status_response
;
2298 printoption("SENT", IAC
, IP
);
2311 NET2ADD(IAC
, BREAK
);
2312 printoption("SENT", IAC
, BREAK
);
2325 NET2ADD(IAC
, ABORT
);
2326 printoption("SENT", IAC
, ABORT
);
2340 printoption("SENT", IAC
, SUSP
);
2354 printoption("SENT", IAC
, xEOF
);
2361 printoption("SENT", IAC
, AYT
);
2365 * Send a window size update to the remote system.
2372 unsigned char tmp
[16];
2375 if (my_state_is_wont(TELOPT_NAWS
))
2379 #define PUTSHORT(cp, x) { if ((*cp++ = ((x)>>8)&0xff) == IAC) *cp++ = IAC; \
2380 if ((*cp++ = ((x))&0xff) == IAC) *cp++ = IAC; }
2382 if (TerminalWindowSize(&rows
, &cols
) == 0) { /* Failed */
2390 *cp
++ = TELOPT_NAWS
;
2395 if (NETROOM() >= cp
- tmp
) {
2396 ring_supply_data(&netoring
, tmp
, cp
-tmp
);
2397 printsub('>', tmp
+2, cp
- tmp
- 2);
2402 tel_enter_binary(int rw
)
2405 send_do(TELOPT_BINARY
, 1);
2407 send_will(TELOPT_BINARY
, 1);
2411 tel_leave_binary(int rw
)
2414 send_dont(TELOPT_BINARY
, 1);
2416 send_wont(TELOPT_BINARY
, 1);