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
35 static const char sccsid[] = "@(#)telnet.c 8.4 (Berkeley) 5/30/95";
38 #include <sys/types.h>
42 /* By the way, we need to include curses.h before telnet.h since,
43 * among other things, telnet.h #defines 'DO', which is a variable
44 * declared in curses.h.
46 #endif /* defined(unix) */
48 #include <arpa/telnet.h>
62 #if defined(AUTHENTICATION)
63 #include <libtelnet/auth.h>
65 #if defined(ENCRYPTION)
66 #include <libtelnet/encrypt.h>
68 #include <libtelnet/misc.h>
70 #define strip(x) ((my_want_state_is_wont(TELOPT_BINARY)) ? ((x)&0x7f) : (x))
72 static unsigned char subbuffer[SUBBUFSIZE],
73 *subpointer, *subend; /* buffer for sub-options */
74 #define SB_CLEAR() subpointer = subbuffer;
75 #define SB_TERM() { subend = subpointer; SB_CLEAR(); }
76 #define SB_ACCUM(c) if (subpointer < (subbuffer+sizeof subbuffer)) { \
77 *subpointer++ = (c); \
80 #define SB_GET() ((*subpointer++)&0xff)
81 #define SB_PEEK() ((*subpointer)&0xff)
82 #define SB_EOF() (subpointer >= subend)
83 #define SB_LEN() (subend - subpointer)
85 char options[256]; /* The combined options */
86 char do_dont_resp[256];
87 char will_wont_resp[256];
91 autologin = 0, /* Autologin anyone? */
95 In3270, /* Are we in 3270 mode? */
96 ISend, /* trying to send network data in */
99 netdata, /* Print out network data flow */
100 crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
102 noasynchtty = 0,/* User specified "-noasynch" on command line */
103 noasynchnet = 0,/* User specified "-noasynch" on command line */
104 askedSGA = 0, /* We have talked about suppress go ahead */
105 #endif /* defined(TN3270) */
107 SYNCHing, /* we are in TELNET SYNCH mode */
108 flushout, /* flush output */
109 autoflush = 0, /* flush output when interrupting? */
110 autosynch, /* send interrupt characters with SYNCH? */
111 localflow, /* we handle flow control locally */
112 restartany, /* if flow control enabled, restart on any character */
113 localchars, /* we recognize interrupt/quit */
114 donelclchars, /* the user has set "localchars" */
115 donebinarytoggle, /* the user has put us in binary */
116 dontlecho, /* do we suppress local echoing right now? */
118 doaddrlookup = 1, /* do a reverse address lookup? */
125 #ifdef KLUDGELINEMODE
130 * Telnet receiver states for fsm
139 #define TS_SB 7 /* sub-option collection */
140 #define TS_SE 8 /* looking for sub-option end */
142 static int telrcv_state;
144 unsigned char telopt_environ = TELOPT_NEW_ENVIRON;
146 # define telopt_environ TELOPT_NEW_ENVIRON
149 jmp_buf toplevel = { 0 };
155 #ifdef KLUDGELINEMODE
156 int kludgelinemode = 1;
160 * The following are some clocks used to decide how to interpret
161 * the relationship between various variables.
167 Modelist modelist[] = {
168 { "telnet command mode", COMMAND_LINE },
169 { "character-at-a-time mode", 0 },
170 { "character-at-a-time mode (local echo)", LOCAL_ECHO|LOCAL_CHARS },
171 { "line-by-line mode (remote echo)", LINE | LOCAL_CHARS },
172 { "line-by-line mode", LINE | LOCAL_ECHO | LOCAL_CHARS },
173 { "line-by-line mode (local echoing suppressed)", LINE | LOCAL_CHARS },
180 * Initialize telnet environment.
191 connected = In3270 = ISend = localflow = donebinarytoggle = 0;
192 #if defined(AUTHENTICATION) || defined(ENCRYPTION)
193 auth_encrypt_connect(connected);
194 #endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */
199 /* Don't change NetTrace */
201 escape = CONTROL(']');
202 rlogin = _POSIX_VDISABLE;
203 #ifdef KLUDGELINEMODE
204 echoc = CONTROL('E');
208 telrcv_state = TS_DATA;
221 char buffer[100]; /* where things go */
230 ring = va_arg(ap, Ring *);
231 format = va_arg(ap, char *);
234 while ((i = *format++) != 0) {
239 *ptr++ = va_arg(ap, int);
242 string = va_arg(ap, char *);
243 ring_supply_data(ring, buffer, ptr-buffer);
244 ring_supply_data(ring, string, strlen(string));
248 ExitString("printring: trailing %%.\n", 1);
251 ExitString("printring: unknown format character.\n", 1);
258 ring_supply_data(ring, buffer, ptr-buffer);
263 * These routines are in charge of sending option negotiations
266 * The basic idea is that we send the negotiation if either side
267 * is in disagreement as to what the current state should be.
272 register int c, init;
275 if (((do_dont_resp[c] == 0) && my_state_is_do(c)) ||
276 my_want_state_is_do(c))
278 set_my_want_state_do(c);
283 printoption("SENT", DO, c);
288 register int c, init;
291 if (((do_dont_resp[c] == 0) && my_state_is_dont(c)) ||
292 my_want_state_is_dont(c))
294 set_my_want_state_dont(c);
299 printoption("SENT", DONT, c);
304 register int c, init;
307 if (((will_wont_resp[c] == 0) && my_state_is_will(c)) ||
308 my_want_state_is_will(c))
310 set_my_want_state_will(c);
315 printoption("SENT", WILL, c);
320 register int c, init;
323 if (((will_wont_resp[c] == 0) && my_state_is_wont(c)) ||
324 my_want_state_is_wont(c))
326 set_my_want_state_wont(c);
331 printoption("SENT", WONT, c);
339 int new_state_ok = 0;
341 if (do_dont_resp[option]) {
342 --do_dont_resp[option];
343 if (do_dont_resp[option] && my_state_is_do(option))
344 --do_dont_resp[option];
347 if ((do_dont_resp[option] == 0) && my_want_state_is_dont(option)) {
354 * The following is a pain in the rear-end.
355 * Various IBM servers (some versions of Wiscnet,
356 * possibly Fibronics/Spartacus, and who knows who
357 * else) will NOT allow us to send "DO SGA" too early
358 * in the setup proceedings. On the other hand,
359 * 4.2 servers (telnetd) won't set SGA correctly.
360 * So, we are stuck. Empirically (but, based on
361 * a VERY small sample), the IBM servers don't send
362 * out anything about ECHO, so we postpone our sending
363 * "DO SGA" until we see "WILL ECHO" (which 4.2 servers
369 if (my_want_state_is_dont(TELOPT_SGA))
370 send_do(TELOPT_SGA, 1);
375 #endif /* defined(TN3270) */
378 settimer(modenegotiated);
381 #if defined(AUTHENTICATION)
382 case TELOPT_AUTHENTICATION:
386 #endif /* ENCRYPTION */
394 * Special case for TM. If we get back a WILL,
395 * pretend we got back a WONT.
397 set_my_want_state_dont(option);
398 set_my_state_dont(option);
399 return; /* Never reply to TM will's/wont's */
401 case TELOPT_LINEMODE:
407 set_my_want_state_do(option);
409 setconnmode(0); /* possibly set new tty mode */
411 do_dont_resp[option]++;
412 send_dont(option, 0);
415 set_my_state_do(option);
417 if (option == TELOPT_ENCRYPT)
418 encrypt_send_support();
419 #endif /* ENCRYPTION */
426 if (do_dont_resp[option]) {
427 --do_dont_resp[option];
428 if (do_dont_resp[option] && my_state_is_dont(option))
429 --do_dont_resp[option];
432 if ((do_dont_resp[option] == 0) && my_want_state_is_do(option)) {
436 #ifdef KLUDGELINEMODE
443 settimer(modenegotiated);
449 set_my_want_state_dont(option);
450 set_my_state_dont(option);
451 return; /* Never reply to TM will's/wont's */
456 set_my_want_state_dont(option);
457 if (my_state_is_do(option))
458 send_dont(option, 0);
459 setconnmode(0); /* Set new tty mode */
460 } else if (option == TELOPT_TM) {
462 * Special case for TM.
466 set_my_want_state_dont(option);
468 set_my_state_dont(option);
475 int new_state_ok = 0;
477 if (will_wont_resp[option]) {
478 --will_wont_resp[option];
479 if (will_wont_resp[option] && my_state_is_will(option))
480 --will_wont_resp[option];
483 if (will_wont_resp[option] == 0) {
484 if (my_want_state_is_wont(option)) {
490 * Special case for TM. We send a WILL, but pretend
493 send_will(option, 0);
494 set_my_want_state_wont(TELOPT_TM);
495 set_my_state_wont(TELOPT_TM);
499 case TELOPT_EOR: /* end of record */
500 # endif /* defined(TN3270) */
501 case TELOPT_BINARY: /* binary mode */
502 case TELOPT_NAWS: /* window size */
503 case TELOPT_TSPEED: /* terminal speed */
504 case TELOPT_LFLOW: /* local flow control */
505 case TELOPT_TTYPE: /* terminal type option */
506 case TELOPT_SGA: /* no big deal */
508 case TELOPT_ENCRYPT: /* encryption variable option */
509 #endif /* ENCRYPTION */
513 case TELOPT_NEW_ENVIRON: /* New environment variable option */
515 if (my_state_is_will(TELOPT_OLD_ENVIRON))
516 send_wont(TELOPT_OLD_ENVIRON, 1); /* turn off the old */
518 case TELOPT_OLD_ENVIRON: /* Old environment variable option */
519 if (my_state_is_will(TELOPT_NEW_ENVIRON))
520 break; /* Don't enable if new one is in use! */
522 telopt_environ = option;
527 #if defined(AUTHENTICATION)
528 case TELOPT_AUTHENTICATION:
534 case TELOPT_XDISPLOC: /* X Display location */
535 if (env_getvalue((unsigned char *)"DISPLAY"))
539 case TELOPT_LINEMODE:
540 #ifdef KLUDGELINEMODE
542 send_do(TELOPT_SGA, 1);
544 set_my_want_state_will(TELOPT_LINEMODE);
545 send_will(option, 0);
546 set_my_state_will(TELOPT_LINEMODE);
550 case TELOPT_ECHO: /* We're never going to echo... */
556 set_my_want_state_will(option);
557 send_will(option, 0);
558 setconnmode(0); /* Set new tty mode */
560 will_wont_resp[option]++;
561 send_wont(option, 0);
565 * Handle options that need more things done after the
566 * other side has acknowledged the option.
569 case TELOPT_LINEMODE:
570 #ifdef KLUDGELINEMODE
572 send_do(TELOPT_SGA, 1);
574 set_my_state_will(option);
576 send_do(TELOPT_SGA, 0);
581 set_my_state_will(option);
589 if (will_wont_resp[option]) {
590 --will_wont_resp[option];
591 if (will_wont_resp[option] && my_state_is_wont(option))
592 --will_wont_resp[option];
595 if ((will_wont_resp[option] == 0) && my_want_state_is_will(option)) {
597 case TELOPT_LINEMODE:
598 linemode = 0; /* put us back to the default state */
601 case TELOPT_NEW_ENVIRON:
603 * The new environ option wasn't recognized, try
606 send_will(TELOPT_OLD_ENVIRON, 1);
607 telopt_environ = TELOPT_OLD_ENVIRON;
611 /* we always accept a DONT */
612 set_my_want_state_wont(option);
613 if (my_state_is_will(option))
614 send_wont(option, 0);
615 setconnmode(0); /* Set new tty mode */
617 set_my_state_wont(option);
621 * Given a buffer returned by tgetent(), this routine will turn
622 * the pipe seperated list of names in the buffer into an array
623 * of pointers to null terminated names. We toss out any bad,
624 * duplicate, or verbose names (names with spaces).
627 static char *name_unknown = "UNKNOWN";
628 static char *unknown[] = { 0, 0 };
635 register char c, *cp, **argvp, *cp2, **argv, **avt;
638 if ((int)strlen(name) > 40) {
640 unknown[0] = name_unknown;
646 unknown[0] = name_unknown;
648 * Count up the number of names.
650 for (n = 1, cp = buf; *cp && *cp != ':'; cp++) {
655 * Allocate an array to put the name pointers into
657 argv = (char **)malloc((n+3)*sizeof(char *));
662 * Fill up the array of pointers to names.
667 for (cp = cp2 = buf; (c = *cp); cp++) {
668 if (c == '|' || c == ':') {
671 * Skip entries that have spaces or are over 40
672 * characters long. If this is our environment
673 * name, then put it up front. Otherwise, as
674 * long as this is not a duplicate name (case
675 * insensitive) add it to the list.
677 if (n || (cp - cp2 > 41))
679 else if (name && (strncasecmp(name, cp2, cp-cp2) == 0))
681 else if (is_unique(cp2, argv+1, argvp))
686 * Skip multiple delimiters. Reset cp2 to
687 * the beginning of the next name. Reset n,
688 * the flag for names with spaces.
690 while ((c = *cp) == '|')
696 * Skip entries with spaces or non-ascii values.
697 * Convert lower case letters to upper case.
699 if ((c == ' ') || !isascii(c))
706 * Check for an old V6 2 character name. If the second
707 * name points to the beginning of the buffer, and is
708 * only 2 characters long, move it to the end of the array.
710 if ((argv[1] == buf) && (strlen(argv[1]) == 2)) {
712 for (avt = &argv[1]; avt < argvp; avt++)
718 * Duplicate last name, for TTYPE option, and null
719 * terminate the array. If we didn't find a match on
720 * our terminal name, put that name at the beginning.
731 for (avt = argv; avt < argvp; avt++)
742 is_unique(name, as, ae)
743 register char *name, **as, **ae;
748 n = strlen(name) + 1;
749 for (ap = as; ap < ae; ap++)
750 if (strncasecmp(*ap, name, n) == 0)
760 setupterm(tname, fd, errp)
764 if (tgetent(termbuf, tname) == 1) {
765 termbuf[1023] = '\0';
775 #define termbuf ttytype
776 extern char ttytype[];
779 int resettermname = 1;
785 static char **tnamep = 0;
791 if (tnamep && tnamep != unknown)
793 if ((tname = (char *)env_getvalue((unsigned char *)"TERM")) &&
794 (setupterm(tname, 1, &err) == 0)) {
795 tnamep = mklist(termbuf, tname);
797 if (tname && ((int)strlen(tname) <= 40)) {
801 unknown[0] = name_unknown;
813 * Look at the sub-option buffer, and try to be helpful to the other
816 * Currently we recognize:
818 * Terminal type, send request.
819 * Terminal speed (send request).
820 * Local flow control (is request).
827 unsigned char subchar;
829 printsub('<', subbuffer, SB_LEN()+2);
830 switch (subchar = SB_GET()) {
832 if (my_want_state_is_wont(TELOPT_TTYPE))
834 if (SB_EOF() || SB_GET() != TELQUAL_SEND) {
838 unsigned char temp[50];
842 if (tn3270_ttype()) {
845 #endif /* defined(TN3270) */
846 name = gettermname();
847 len = strlen(name) + 4 + 2;
848 if (len < NETROOM()) {
849 sprintf((char *)temp, "%c%c%c%c%s%c%c", IAC, SB, TELOPT_TTYPE,
850 TELQUAL_IS, name, IAC, SE);
851 ring_supply_data(&netoring, temp, len);
852 printsub('>', &temp[2], len-2);
854 ExitString("No room in buffer for terminal type.\n", 1);
860 if (my_want_state_is_wont(TELOPT_TSPEED))
864 if (SB_GET() == TELQUAL_SEND) {
866 unsigned char temp[50];
869 TerminalSpeeds(&ispeed, &ospeed);
871 sprintf((char *)temp, "%c%c%c%c%ld,%ld%c%c", IAC, SB, TELOPT_TSPEED,
872 TELQUAL_IS, ospeed, ispeed, IAC, SE);
873 len = strlen((char *)temp+4) + 4; /* temp[3] is 0 ... */
875 if (len < NETROOM()) {
876 ring_supply_data(&netoring, temp, len);
877 printsub('>', temp+2, len - 2);
879 /*@*/ else printf("lm_will: not enough room in buffer\n");
883 if (my_want_state_is_wont(TELOPT_LFLOW))
888 case LFLOW_RESTART_ANY:
891 case LFLOW_RESTART_XON:
907 case TELOPT_LINEMODE:
908 if (my_want_state_is_wont(TELOPT_LINEMODE))
914 lm_will(subpointer, SB_LEN());
917 lm_wont(subpointer, SB_LEN());
920 lm_do(subpointer, SB_LEN());
923 lm_dont(subpointer, SB_LEN());
926 slc(subpointer, SB_LEN());
929 lm_mode(subpointer, SB_LEN(), 0);
937 case TELOPT_OLD_ENVIRON:
939 case TELOPT_NEW_ENVIRON:
945 if (my_want_state_is_dont(subchar))
949 if (my_want_state_is_wont(subchar)) {
956 env_opt(subpointer, SB_LEN());
959 case TELOPT_XDISPLOC:
960 if (my_want_state_is_wont(TELOPT_XDISPLOC))
964 if (SB_GET() == TELQUAL_SEND) {
965 unsigned char temp[50], *dp;
968 if ((dp = env_getvalue((unsigned char *)"DISPLAY")) == NULL) {
970 * Something happened, we no longer have a DISPLAY
971 * variable. So, turn off the option.
973 send_wont(TELOPT_XDISPLOC, 1);
976 sprintf((char *)temp, "%c%c%c%c%s%c%c", IAC, SB, TELOPT_XDISPLOC,
977 TELQUAL_IS, dp, IAC, SE);
978 len = strlen((char *)temp+4) + 4; /* temp[3] is 0 ... */
980 if (len < NETROOM()) {
981 ring_supply_data(&netoring, temp, len);
982 printsub('>', temp+2, len - 2);
984 /*@*/ else printf("lm_will: not enough room in buffer\n");
988 #if defined(AUTHENTICATION)
989 case TELOPT_AUTHENTICATION: {
996 if (my_want_state_is_dont(TELOPT_AUTHENTICATION))
998 auth_is(subpointer, SB_LEN());
1001 if (my_want_state_is_wont(TELOPT_AUTHENTICATION))
1003 auth_send(subpointer, SB_LEN());
1006 if (my_want_state_is_wont(TELOPT_AUTHENTICATION))
1008 auth_reply(subpointer, SB_LEN());
1011 if (my_want_state_is_dont(TELOPT_AUTHENTICATION))
1013 auth_name(subpointer, SB_LEN());
1020 case TELOPT_ENCRYPT:
1025 if (my_want_state_is_dont(TELOPT_ENCRYPT))
1027 encrypt_start(subpointer, SB_LEN());
1030 if (my_want_state_is_dont(TELOPT_ENCRYPT))
1034 case ENCRYPT_SUPPORT:
1035 if (my_want_state_is_wont(TELOPT_ENCRYPT))
1037 encrypt_support(subpointer, SB_LEN());
1039 case ENCRYPT_REQSTART:
1040 if (my_want_state_is_wont(TELOPT_ENCRYPT))
1042 encrypt_request_start(subpointer, SB_LEN());
1044 case ENCRYPT_REQEND:
1045 if (my_want_state_is_wont(TELOPT_ENCRYPT))
1048 * We can always send an REQEND so that we cannot
1049 * get stuck encrypting. We should only get this
1050 * if we have been able to get in the correct mode
1053 encrypt_request_end();
1056 if (my_want_state_is_dont(TELOPT_ENCRYPT))
1058 encrypt_is(subpointer, SB_LEN());
1061 if (my_want_state_is_wont(TELOPT_ENCRYPT))
1063 encrypt_reply(subpointer, SB_LEN());
1065 case ENCRYPT_ENC_KEYID:
1066 if (my_want_state_is_dont(TELOPT_ENCRYPT))
1068 encrypt_enc_keyid(subpointer, SB_LEN());
1070 case ENCRYPT_DEC_KEYID:
1071 if (my_want_state_is_wont(TELOPT_ENCRYPT))
1073 encrypt_dec_keyid(subpointer, SB_LEN());
1079 #endif /* ENCRYPTION */
1085 static unsigned char str_lm[] = { IAC, SB, TELOPT_LINEMODE, 0, 0, IAC, SE };
1093 /*@*/ printf("lm_will: no command!!!\n"); /* Should not happen... */
1097 case LM_FORWARDMASK: /* We shouldn't ever get this... */
1101 if (NETROOM() > sizeof(str_lm)) {
1102 ring_supply_data(&netoring, str_lm, sizeof(str_lm));
1103 printsub('>', &str_lm[2], sizeof(str_lm)-2);
1105 /*@*/ else printf("lm_will: not enough room in buffer\n");
1116 /*@*/ printf("lm_wont: no command!!!\n"); /* Should not happen... */
1120 case LM_FORWARDMASK: /* We shouldn't ever get this... */
1122 /* We are always DONT, so don't respond */
1133 /*@*/ printf("lm_do: no command!!!\n"); /* Should not happen... */
1137 case LM_FORWARDMASK:
1141 if (NETROOM() > sizeof(str_lm)) {
1142 ring_supply_data(&netoring, str_lm, sizeof(str_lm));
1143 printsub('>', &str_lm[2], sizeof(str_lm)-2);
1145 /*@*/ else printf("lm_do: not enough room in buffer\n");
1156 /*@*/ printf("lm_dont: no command!!!\n"); /* Should not happen... */
1160 case LM_FORWARDMASK:
1162 /* we are always WONT, so don't respond */
1167 static unsigned char str_lm_mode[] = {
1168 IAC, SB, TELOPT_LINEMODE, LM_MODE, 0, IAC, SE
1172 lm_mode(cmd, len, init)
1178 if ((linemode&MODE_MASK&~MODE_ACK) == *cmd)
1182 linemode = *cmd&(MODE_MASK&~MODE_ACK);
1183 str_lm_mode[4] = linemode;
1185 str_lm_mode[4] |= MODE_ACK;
1186 if (NETROOM() > sizeof(str_lm_mode)) {
1187 ring_supply_data(&netoring, str_lm_mode, sizeof(str_lm_mode));
1188 printsub('>', &str_lm_mode[2], sizeof(str_lm_mode)-2);
1190 /*@*/ else printf("lm_mode: not enough room in buffer\n");
1191 setconnmode(0); /* set changed mode */
1198 * Handle special character suboption of LINEMODE.
1204 char flags; /* Current flags & level */
1205 char mylevel; /* Maximum level & flags */
1208 #define SLC_IMPORT 0
1209 #define SLC_EXPORT 1
1210 #define SLC_RVALUE 2
1211 static int slc_mode = SLC_EXPORT;
1216 register struct spc *spcp;
1219 for (spcp = spc_data; spcp < &spc_data[NSLC+1]; spcp++) {
1222 spcp->flags = spcp->mylevel = SLC_NOSUPPORT;
1225 #define initfunc(func, flags) { \
1226 spcp = &spc_data[func]; \
1227 if ((spcp->valp = tcval(func))) { \
1228 spcp->val = *spcp->valp; \
1229 spcp->mylevel = SLC_VARIABLE|flags; \
1232 spcp->mylevel = SLC_DEFAULT; \
1236 initfunc(SLC_SYNCH, 0);
1238 initfunc(SLC_AO, 0);
1239 initfunc(SLC_AYT, 0);
1241 initfunc(SLC_ABORT, SLC_FLUSHIN|SLC_FLUSHOUT);
1242 initfunc(SLC_EOF, 0);
1244 initfunc(SLC_SUSP, SLC_FLUSHIN);
1246 initfunc(SLC_EC, 0);
1247 initfunc(SLC_EL, 0);
1249 initfunc(SLC_EW, 0);
1250 initfunc(SLC_RP, 0);
1251 initfunc(SLC_LNEXT, 0);
1253 initfunc(SLC_XON, 0);
1254 initfunc(SLC_XOFF, 0);
1256 spc_data[SLC_XON].mylevel = SLC_CANTCHANGE;
1257 spc_data[SLC_XOFF].mylevel = SLC_CANTCHANGE;
1259 initfunc(SLC_FORW1, 0);
1261 initfunc(SLC_FORW2, 0);
1265 initfunc(SLC_IP, SLC_FLUSHIN|SLC_FLUSHOUT);
1268 if (slc_mode == SLC_EXPORT)
1278 printf("Special characters are %s values\n",
1279 slc_mode == SLC_IMPORT ? "remote default" :
1280 slc_mode == SLC_EXPORT ? "local" :
1287 slc_mode = SLC_EXPORT;
1288 if (my_state_is_will(TELOPT_LINEMODE))
1293 slc_mode_import(def)
1296 slc_mode = def ? SLC_IMPORT : SLC_RVALUE;
1297 if (my_state_is_will(TELOPT_LINEMODE))
1301 unsigned char slc_import_val[] = {
1302 IAC, SB, TELOPT_LINEMODE, LM_SLC, 0, SLC_VARIABLE, 0, IAC, SE
1304 unsigned char slc_import_def[] = {
1305 IAC, SB, TELOPT_LINEMODE, LM_SLC, 0, SLC_DEFAULT, 0, IAC, SE
1312 if (NETROOM() > sizeof(slc_import_val)) {
1314 ring_supply_data(&netoring, slc_import_def, sizeof(slc_import_def));
1315 printsub('>', &slc_import_def[2], sizeof(slc_import_def)-2);
1317 ring_supply_data(&netoring, slc_import_val, sizeof(slc_import_val));
1318 printsub('>', &slc_import_val[2], sizeof(slc_import_val)-2);
1321 /*@*/ else printf("slc_import: not enough room\n");
1327 register struct spc *spcp;
1329 TerminalDefaultChars();
1332 for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) {
1333 if (spcp->mylevel != SLC_NOSUPPORT) {
1334 if (spcp->val == (cc_t)(_POSIX_VDISABLE))
1335 spcp->flags = SLC_NOSUPPORT;
1337 spcp->flags = spcp->mylevel;
1339 spcp->val = *spcp->valp;
1340 slc_add_reply(spcp - spc_data, spcp->flags, spcp->val);
1345 setconnmode(1); /* Make sure the character values are set */
1350 register unsigned char *cp;
1353 register struct spc *spcp;
1354 register int func,level;
1358 for (; len >= 3; len -=3, cp +=3) {
1360 func = cp[SLC_FUNC];
1364 * Client side: always ignore 0 function.
1369 if ((cp[SLC_FLAGS] & SLC_LEVELBITS) != SLC_NOSUPPORT)
1370 slc_add_reply(func, SLC_NOSUPPORT, 0);
1374 spcp = &spc_data[func];
1376 level = cp[SLC_FLAGS]&(SLC_LEVELBITS|SLC_ACK);
1378 if ((cp[SLC_VALUE] == (unsigned char)spcp->val) &&
1379 ((level&SLC_LEVELBITS) == (spcp->flags&SLC_LEVELBITS))) {
1383 if (level == (SLC_DEFAULT|SLC_ACK)) {
1385 * This is an error condition, the SLC_ACK
1386 * bit should never be set for the SLC_DEFAULT
1387 * level. Our best guess to recover is to
1388 * ignore the SLC_ACK bit.
1390 cp[SLC_FLAGS] &= ~SLC_ACK;
1393 if (level == ((spcp->flags&SLC_LEVELBITS)|SLC_ACK)) {
1394 spcp->val = (cc_t)cp[SLC_VALUE];
1395 spcp->flags = cp[SLC_FLAGS]; /* include SLC_ACK */
1401 if (level <= (spcp->mylevel&SLC_LEVELBITS)) {
1402 spcp->flags = cp[SLC_FLAGS]|SLC_ACK;
1403 spcp->val = (cc_t)cp[SLC_VALUE];
1405 if (level == SLC_DEFAULT) {
1406 if ((spcp->mylevel&SLC_LEVELBITS) != SLC_DEFAULT)
1407 spcp->flags = spcp->mylevel;
1409 spcp->flags = SLC_NOSUPPORT;
1411 slc_add_reply(func, spcp->flags, spcp->val);
1415 setconnmode(1); /* set the new character values */
1421 register struct spc *spcp;
1424 for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) {
1425 if (spcp->valp && spcp->val != *spcp->valp) {
1426 spcp->val = *spcp->valp;
1427 if (spcp->val == (cc_t)(_POSIX_VDISABLE))
1428 spcp->flags = SLC_NOSUPPORT;
1430 spcp->flags = spcp->mylevel;
1431 slc_add_reply(spcp - spc_data, spcp->flags, spcp->val);
1439 unsigned char slc_reply[128];
1440 unsigned char *slc_replyp;
1445 slc_replyp = slc_reply;
1446 *slc_replyp++ = IAC;
1448 *slc_replyp++ = TELOPT_LINEMODE;
1449 *slc_replyp++ = LM_SLC;
1453 slc_add_reply(func, flags, value)
1455 unsigned char flags;
1458 if ((*slc_replyp++ = func) == IAC)
1459 *slc_replyp++ = IAC;
1460 if ((*slc_replyp++ = flags) == IAC)
1461 *slc_replyp++ = IAC;
1462 if ((*slc_replyp++ = (unsigned char)value) == IAC)
1463 *slc_replyp++ = IAC;
1471 *slc_replyp++ = IAC;
1473 len = slc_replyp - slc_reply;
1476 if (NETROOM() > len) {
1477 ring_supply_data(&netoring, slc_reply, slc_replyp - slc_reply);
1478 printsub('>', &slc_reply[2], slc_replyp - slc_reply - 2);
1480 /*@*/else printf("slc_end_reply: not enough room\n");
1486 register struct spc *spcp;
1487 int need_update = 0;
1489 for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) {
1490 if (!(spcp->flags&SLC_ACK))
1492 spcp->flags &= ~SLC_ACK;
1493 if (spcp->valp && (*spcp->valp != spcp->val)) {
1494 *spcp->valp = spcp->val;
1498 return(need_update);
1504 * Earlier version of telnet/telnetd from the BSD code had
1505 * the definitions of VALUE and VAR reversed. To ensure
1506 * maximum interoperability, we assume that the server is
1507 * an older BSD server, until proven otherwise. The newer
1508 * BSD servers should be able to handle either definition,
1509 * so it is better to use the wrong values if we don't
1510 * know what type of server it is.
1513 int old_env_var = OLD_ENV_VAR;
1514 int old_env_value = OLD_ENV_VALUE;
1516 # define old_env_var OLD_ENV_VAR
1517 # define old_env_value OLD_ENV_VALUE
1523 register unsigned char *buf;
1526 register unsigned char *ep = 0, *epc = 0;
1529 switch(buf[0]&0xff) {
1534 } else for (i = 1; i < len; i++) {
1535 switch (buf[i]&0xff) {
1539 if (telopt_environ == TELOPT_OLD_ENVIRON
1541 /* Server has the same definitions */
1542 old_env_var = OLD_ENV_VAR;
1543 old_env_value = OLD_ENV_VALUE;
1549 * Although OLD_ENV_VALUE is not legal, we will
1550 * still recognize it, just in case it is an
1551 * old server that has VAR & VALUE mixed up...
1562 ep = epc = &buf[i+1];
1582 /* Ignore for now. We shouldn't get it anyway. */
1590 #define OPT_REPLY_SIZE 256
1591 unsigned char *opt_reply;
1592 unsigned char *opt_replyp;
1593 unsigned char *opt_replyend;
1599 opt_reply = (unsigned char *)realloc(opt_reply, OPT_REPLY_SIZE);
1601 opt_reply = (unsigned char *)malloc(OPT_REPLY_SIZE);
1602 if (opt_reply == NULL) {
1603 /*@*/ printf("env_opt_start: malloc()/realloc() failed!!!\n");
1604 opt_reply = opt_replyp = opt_replyend = NULL;
1607 opt_replyp = opt_reply;
1608 opt_replyend = opt_reply + OPT_REPLY_SIZE;
1609 *opt_replyp++ = IAC;
1611 *opt_replyp++ = telopt_environ;
1612 *opt_replyp++ = TELQUAL_IS;
1616 env_opt_start_info()
1620 opt_replyp[-1] = TELQUAL_INFO;
1625 register unsigned char *ep;
1627 register unsigned char *vp, c;
1629 if (opt_reply == NULL) /*XXX*/
1632 if (ep == NULL || *ep == '\0') {
1633 /* Send user defined variables first. */
1635 while ((ep = env_default(0, 0)))
1638 /* Now add the list of well know variables. */
1640 while ((ep = env_default(0, 1)))
1644 vp = env_getvalue(ep);
1645 if (opt_replyp + (vp ? strlen((char *)vp) : 0) +
1646 strlen((char *)ep) + 6 > opt_replyend)
1649 opt_replyend += OPT_REPLY_SIZE;
1650 len = opt_replyend - opt_reply;
1651 opt_reply = (unsigned char *)realloc(opt_reply, len);
1652 if (opt_reply == NULL) {
1653 /*@*/ printf("env_opt_add: realloc() failed!!!\n");
1654 opt_reply = opt_replyp = opt_replyend = NULL;
1657 opt_replyp = opt_reply + len - (opt_replyend - opt_replyp);
1658 opt_replyend = opt_reply + len;
1660 if (opt_welldefined(ep))
1662 if (telopt_environ == TELOPT_OLD_ENVIRON)
1663 *opt_replyp++ = old_env_var;
1666 *opt_replyp++ = NEW_ENV_VAR;
1668 *opt_replyp++ = ENV_USERVAR;
1670 while ((c = *ep++)) {
1673 *opt_replyp++ = IAC;
1679 *opt_replyp++ = ENV_ESC;
1686 if (telopt_environ == TELOPT_OLD_ENVIRON)
1687 *opt_replyp++ = old_env_value;
1690 *opt_replyp++ = NEW_ENV_VALUE;
1701 if ((strcmp(ep, "USER") == 0) ||
1702 (strcmp(ep, "DISPLAY") == 0) ||
1703 (strcmp(ep, "PRINTER") == 0) ||
1704 (strcmp(ep, "SYSTEMTYPE") == 0) ||
1705 (strcmp(ep, "JOB") == 0) ||
1706 (strcmp(ep, "ACCT") == 0))
1711 env_opt_end(emptyok)
1712 register int emptyok;
1716 len = opt_replyp - opt_reply + 2;
1717 if (emptyok || len > 6) {
1718 *opt_replyp++ = IAC;
1720 if (NETROOM() > len) {
1721 ring_supply_data(&netoring, opt_reply, len);
1722 printsub('>', &opt_reply[2], len - 2);
1724 /*@*/ else printf("slc_end_reply: not enough room\n");
1728 opt_reply = opt_replyp = opt_replyend = NULL;
1739 register unsigned char *sbp;
1741 int returnValue = 0;
1745 while (TTYROOM() > 2) {
1748 ring_consumed(&netiring, count);
1752 sbp = netiring.consume;
1753 scc = ring_full_consecutive(&netiring);
1755 /* No more data coming in */
1760 c = *sbp++ & 0xff, scc--; count++;
1763 c = (*decrypt_input)(c);
1764 #endif /* ENCRYPTION */
1766 switch (telrcv_state) {
1769 telrcv_state = TS_DATA;
1771 break; /* Ignore \0 after CR */
1773 else if ((c == '\n') && my_want_state_is_dont(TELOPT_ECHO) && !crmod) {
1777 /* Else, fall through */
1781 telrcv_state = TS_IAC;
1784 # if defined(TN3270)
1788 c = *sbp++ & 0377, scc--; count++;
1791 c = (*decrypt_input)(c);
1792 #endif /* ENCRYPTION */
1794 telrcv_state = TS_IAC;
1800 # endif /* defined(TN3270) */
1802 * The 'crmod' hack (see following) is needed
1803 * since we can't * set CRMOD on output only.
1804 * Machines like MULTICS like to send \r without
1805 * \n; since we must turn off CRMOD to get proper
1806 * input, the mapping is done here (sigh).
1808 if ((c == '\r') && my_want_state_is_dont(TELOPT_BINARY)) {
1813 c = (*decrypt_input)(c);
1814 #endif /* ENCRYPTION */
1816 sbp++, scc--; count++;
1819 } else if (my_want_state_is_dont(TELOPT_ECHO) &&
1821 sbp++, scc--; count++;
1826 (*decrypt_input)(-1);
1827 #endif /* ENCRYPTION */
1835 telrcv_state = TS_CR;
1851 telrcv_state = TS_WILL;
1855 telrcv_state = TS_WONT;
1859 telrcv_state = TS_DO;
1863 telrcv_state = TS_DONT;
1868 * We may have missed an urgent notification,
1869 * so make sure we flush whatever is in the
1872 printoption("RCVD", IAC, DM);
1875 SYNCHing = stilloob();
1881 telrcv_state = TS_SB;
1884 # if defined(TN3270)
1887 if (Ibackp == Ifrontp) {
1888 Ibackp = Ifrontp = Ibuf;
1889 ISend = 0; /* should have been! */
1891 Ibackp += DataFromNetwork(Ibackp, Ifrontp-Ibackp, 1);
1895 printoption("RCVD", IAC, EOR);
1897 # endif /* defined(TN3270) */
1900 # if !defined(TN3270)
1902 # else /* !defined(TN3270) */
1908 # endif /* !defined(TN3270) */
1914 printoption("RCVD", IAC, c);
1917 telrcv_state = TS_DATA;
1921 printoption("RCVD", WILL, c);
1924 telrcv_state = TS_DATA;
1928 printoption("RCVD", WONT, c);
1931 telrcv_state = TS_DATA;
1935 printoption("RCVD", DO, c);
1938 if (c == TELOPT_NAWS) {
1940 } else if (c == TELOPT_LFLOW) {
1945 telrcv_state = TS_DATA;
1949 printoption("RCVD", DONT, c);
1952 setconnmode(0); /* set new tty mode (maybe) */
1954 telrcv_state = TS_DATA;
1959 telrcv_state = TS_SE;
1969 * This is an error. We only expect to get
1970 * "IAC IAC" or "IAC SE". Several things may
1971 * have happend. An IAC was not doubled, the
1972 * IAC SE was left off, or another option got
1973 * inserted into the suboption are all possibilities.
1974 * If we assume that the IAC was not doubled,
1975 * and really the IAC SE was left off, we could
1976 * get into an infinate loop here. So, instead,
1977 * we terminate the suboption, and process the
1978 * partial suboption if we can.
1985 printoption("In SUBOPTION processing, RCVD", IAC, c);
1986 suboption(); /* handle sub-option */
1988 telrcv_state = TS_IAC;
1992 telrcv_state = TS_SB;
1998 suboption(); /* handle sub-option */
2000 telrcv_state = TS_DATA;
2005 ring_consumed(&netiring, count);
2006 return returnValue||count;
2009 static int bol = 1, local = 0;
2017 command(0, "z\n", 2);
2028 int returnValue = 0;
2033 while (NETROOM() > 2) {
2039 ring_consumed(&ttyiring, count);
2043 tbp = ttyiring.consume;
2044 tcc = ring_full_consecutive(&ttyiring);
2049 c = *tbp++ & 0xff, sc = strip(c), tcc--; count++;
2050 if (rlogin != _POSIX_VDISABLE) {
2059 if (sc == '.' || c == termEofChar) {
2061 command(0, "close\n", 6);
2064 if (sc == termSuspChar) {
2066 command(0, "z\n", 2);
2070 command(0, (char *)tbp, tcc);
2084 if ((sc == '\n') || (sc == '\r'))
2086 } else if (escape != _POSIX_VDISABLE && sc == escape) {
2088 * Double escape is a pass through of a single escape character.
2090 if (tcc && strip(*tbp) == escape) {
2096 command(0, (char *)tbp, tcc);
2105 #ifdef KLUDGELINEMODE
2106 if (kludgelinemode && (globalmode&MODE_EDIT) && (sc == echoc)) {
2107 if (tcc > 0 && strip(*tbp) == echoc) {
2108 tcc--; tbp++; count++;
2110 dontlecho = !dontlecho;
2111 settimer(echotoggle);
2118 if (MODE_LOCAL_CHARS(globalmode)) {
2119 if (TerminalSpecialChars(sc) == 0) {
2124 if (my_want_state_is_wont(TELOPT_BINARY)) {
2128 * If we are in CRMOD mode (\r ==> \n)
2129 * on our local machine, then probably
2130 * a newline (unix) is CRLF (TELNET).
2132 if (MODE_LOCAL_CHARS(globalmode)) {
2136 bol = flushline = 1;
2140 NET2ADD('\r', '\0');
2142 NET2ADD('\r', '\n');
2144 bol = flushline = 1;
2153 } else if (c == IAC) {
2160 ring_consumed(&ttyiring, count);
2161 return returnValue||count; /* Non-zero if we did anything */
2167 * Try to do something.
2169 * If we do something useful, return 1; else return 0.
2176 int block; /* should we block in the select ? */
2178 /* One wants to be a bit careful about setting returnValue
2179 * to one, since a one implies we did some useful work,
2180 * and therefore probably won't be called to block next
2181 * time (TN3270 mode only).
2184 int netin, netout, netex, ttyin, ttyout;
2186 /* Decide which rings should be processed */
2188 netout = ring_full_count(&netoring) &&
2190 (my_want_state_is_wont(TELOPT_LINEMODE)
2191 #ifdef KLUDGELINEMODE
2192 && (!kludgelinemode || my_want_state_is_do(TELOPT_SGA))
2195 my_want_state_is_will(TELOPT_BINARY));
2196 ttyout = ring_full_count(&ttyoring);
2199 ttyin = ring_empty_count(&ttyiring) && (clienteof == 0) && (shell_active == 0);
2200 #else /* defined(TN3270) */
2201 ttyin = ring_empty_count(&ttyiring) && (clienteof == 0);
2202 #endif /* defined(TN3270) */
2205 netin = ring_empty_count(&netiring);
2206 # else /* !defined(TN3270) */
2207 netin = !ISend && ring_empty_count(&netiring);
2208 # endif /* !defined(TN3270) */
2212 /* If we have seen a signal recently, reset things */
2213 # if defined(TN3270) && defined(unix)
2216 (void) signal(SIGIO, inputAvailable);
2218 #endif /* defined(TN3270) && defined(unix) */
2220 /* Call to system code to process rings */
2222 returnValue = process_rings(netin, netout, netex, ttyin, ttyout, !block);
2224 /* Now, look at the input rings, looking for work to do. */
2226 if (ring_full_count(&ttyiring)) {
2227 # if defined(TN3270)
2231 c = DataFromTerminal(ttyiring.consume,
2232 ring_full_consecutive(&ttyiring));
2235 ring_consumed(&ttyiring, c);
2238 # endif /* defined(TN3270) */
2239 returnValue |= telsnd();
2240 # if defined(TN3270)
2242 # endif /* defined(TN3270) */
2245 if (ring_full_count(&netiring)) {
2246 # if !defined(TN3270)
2247 returnValue |= telrcv();
2248 # else /* !defined(TN3270) */
2249 returnValue = Push3270();
2250 # endif /* !defined(TN3270) */
2256 * Select from tty and network...
2264 #if defined(AUTHENTICATION) || defined(ENCRYPTION)
2266 static char local_host[256] = { 0 };
2268 if (!local_host[0]) {
2269 gethostname(local_host, sizeof(local_host));
2270 local_host[sizeof(local_host)-1] = 0;
2272 auth_encrypt_init(local_host, hostname, "TELNET", 0);
2273 auth_encrypt_user(user);
2275 #endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */
2276 # if !defined(TN3270)
2278 #if defined(AUTHENTICATION)
2280 send_will(TELOPT_AUTHENTICATION, 1);
2283 send_do(TELOPT_ENCRYPT, 1);
2284 send_will(TELOPT_ENCRYPT, 1);
2285 #endif /* ENCRYPTION */
2286 send_do(TELOPT_SGA, 1);
2287 send_will(TELOPT_TTYPE, 1);
2288 send_will(TELOPT_NAWS, 1);
2289 send_will(TELOPT_TSPEED, 1);
2290 send_will(TELOPT_LFLOW, 1);
2291 send_will(TELOPT_LINEMODE, 1);
2292 send_will(TELOPT_NEW_ENVIRON, 1);
2293 send_do(TELOPT_STATUS, 1);
2294 if (env_getvalue((unsigned char *)"DISPLAY"))
2295 send_will(TELOPT_XDISPLOC, 1);
2297 tel_enter_binary(eight);
2299 # endif /* !defined(TN3270) */
2301 # if !defined(TN3270)
2305 while ((schedValue = Scheduler(0)) != 0) {
2306 if (schedValue == -1) {
2312 if (Scheduler(1) == -1) {
2317 # else /* !defined(TN3270) */
2321 while (!In3270 && !shell_active) {
2322 if (Scheduler(1) == -1) {
2328 while ((schedValue = Scheduler(0)) != 0) {
2329 if (schedValue == -1) {
2334 /* If there is data waiting to go out to terminal, don't
2335 * schedule any more data for the terminal.
2337 if (ring_full_count(&ttyoring)) {
2341 if (shell_continue() == 0) {
2344 } else if (In3270) {
2345 schedValue = DoTerminalOutput();
2348 if (schedValue && (shell_active == 0)) {
2349 if (Scheduler(1) == -1) {
2355 # endif /* !defined(TN3270) */
2358 #if 0 /* XXX - this not being in is a bug */
2362 * Return the address of the next "item" in the TELNET data
2363 * stream. This will be the address of the next character if
2364 * the current address is a user data character, or it will
2365 * be the address of the character following the TELNET command
2366 * if the current address is a TELNET IAC ("I Am a Command")
2374 if ((*current&0xff) != IAC) {
2377 switch (*(current+1)&0xff) {
2383 case SB: /* loop forever looking for the SE */
2385 register char *look = current+2;
2388 if ((*look++&0xff) == IAC) {
2389 if ((*look++&0xff) == SE) {
2404 * We are about to do a TELNET SYNCH operation. Clear
2405 * the path to the network.
2407 * Things are a bit tricky since we may have sent the first
2408 * byte or so of a previous TELNET command into the network.
2409 * So, we have to scan the network buffer from the beginning
2410 * until we are up to where we want to be.
2412 * A side effect of what we do, just to keep things
2413 * simple, is to clear the urgent data pointer. The principal
2414 * caller should be setting the urgent data pointer AFTER calling
2422 register char *thisitem, *next;
2424 #define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \
2425 ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))
2429 while ((next = nextitem(thisitem)) <= netobuf.send) {
2433 /* Now, thisitem is first before/at boundary. */
2435 good = netobuf; /* where the good bytes go */
2437 while (netoring.add > thisitem) {
2438 if (wewant(thisitem)) {
2443 next = nextitem(next);
2444 } while (wewant(next) && (nfrontp > next));
2445 length = next-thisitem;
2446 memmove(good, thisitem, length);
2450 thisitem = nextitem(thisitem);
2458 * These routines add various telnet commands to the data stream.
2468 (void) ttyflush(1); /* Flush/drop output */
2469 /* do printoption AFTER flush, otherwise the output gets tossed... */
2470 printoption("SENT", DO, TELOPT_TM);
2477 printoption("SENT", IAC, AO);
2488 printoption("SENT", IAC, EL);
2495 printoption("SENT", IAC, EC);
2502 netclear(); /* clear the path to the network */
2506 printoption("SENT", IAC, DM);
2510 int want_status_response = 0;
2515 unsigned char tmp[16];
2516 register unsigned char *cp;
2518 if (my_want_state_is_dont(TELOPT_STATUS)) {
2519 printf("Remote side does not support STATUS option\n");
2526 *cp++ = TELOPT_STATUS;
2527 *cp++ = TELQUAL_SEND;
2530 if (NETROOM() >= cp - tmp) {
2531 ring_supply_data(&netoring, tmp, cp-tmp);
2532 printsub('>', tmp+2, cp - tmp - 2);
2534 ++want_status_response;
2542 printoption("SENT", IAC, IP);
2555 NET2ADD(IAC, BREAK);
2556 printoption("SENT", IAC, BREAK);
2569 NET2ADD(IAC, ABORT);
2570 printoption("SENT", IAC, ABORT);
2584 printoption("SENT", IAC, SUSP);
2598 printoption("SENT", IAC, xEOF);
2605 printoption("SENT", IAC, AYT);
2609 * Send a window size update to the remote system.
2616 unsigned char tmp[16];
2617 register unsigned char *cp;
2619 if (my_state_is_wont(TELOPT_NAWS))
2622 #define PUTSHORT(cp, x) { if ((*cp++ = ((x)>>8)&0xff) == IAC) *cp++ = IAC; \
2623 if ((*cp++ = ((x))&0xff) == IAC) *cp++ = IAC; }
2625 if (TerminalWindowSize(&rows, &cols) == 0) { /* Failed */
2633 *cp++ = TELOPT_NAWS;
2638 if (NETROOM() >= cp - tmp) {
2639 ring_supply_data(&netoring, tmp, cp-tmp);
2640 printsub('>', tmp+2, cp - tmp - 2);
2645 tel_enter_binary(rw)
2649 send_do(TELOPT_BINARY, 1);
2651 send_will(TELOPT_BINARY, 1);
2655 tel_leave_binary(rw)
2659 send_dont(TELOPT_BINARY, 1);
2661 send_wont(TELOPT_BINARY, 1);