2 * Copyright (c) 1989, 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
38 unsigned char doopt
[] = { IAC
, DO
, '%', 'c', 0 };
39 unsigned char dont
[] = { IAC
, DONT
, '%', 'c', 0 };
40 unsigned char will
[] = { IAC
, WILL
, '%', 'c', 0 };
41 unsigned char wont
[] = { IAC
, WONT
, '%', 'c', 0 };
45 * Buffer for sub-options, and macros
46 * for suboptions buffer manipulations
48 unsigned char subbuffer
[1024*64], *subpointer
= subbuffer
, *subend
= subbuffer
;
50 #define SB_CLEAR() subpointer = subbuffer
51 #define SB_TERM() { subend = subpointer; SB_CLEAR(); }
52 #define SB_ACCUM(c) if (subpointer < (subbuffer+sizeof subbuffer)) { \
53 *subpointer++ = (c); \
55 #define SB_GET() ((*subpointer++)&0xff)
56 #define SB_EOF() (subpointer >= subend)
57 #define SB_LEN() (subend - subpointer)
60 unsigned char *subsave
;
61 #define SB_SAVE() subsave = subpointer;
62 #define SB_RESTORE() subpointer = subsave;
69 #define TS_DATA 0 /* base state */
70 #define TS_IAC 1 /* look for double IAC's */
71 #define TS_CR 2 /* CR-LF ->'s CR */
72 #define TS_SB 3 /* throw away begin's... */
73 #define TS_SE 4 /* ...end's (suboption negotiation) */
74 #define TS_WILL 5 /* will option negotiation */
75 #define TS_WONT 6 /* wont -''- */
76 #define TS_DO 7 /* do -''- */
77 #define TS_DONT 8 /* dont -''- */
83 static int state
= TS_DATA
;
86 if ((&ptyobuf
[BUFSIZ
] - pfrontp
) < 2)
88 c
= *netip
++ & 0377, ncc
--;
91 c
= (*decrypt_input
)(c
);
97 /* Strip off \n or \0 after a \r */
98 if ((c
== 0) || (c
== '\n')) {
109 * We now map \r\n ==> \r for pragmatic reasons.
110 * Many client implementations send \r\n when
111 * the user hits the CarriageReturn key.
113 * We USED to map \r\n ==> \n, since \r\n says
114 * that we want to be in column 1 of the next
115 * printable line, and \n is the standard
116 * unix way of saying that (\r is only good
117 * if CRMOD is set, which it normally is).
119 if ((c
== '\r') && his_state_is_wont(TELOPT_BINARY
)) {
123 nc
= (*decrypt_input
)(nc
& 0xff);
128 (void)(*decrypt_input
)(-1);
140 * Send the process on the pty side an
141 * interrupt. Do this with a NULL or
142 * interrupt char; depending on the tty mode.
146 printoption("td: recv IAC", c
));
152 printoption("td: recv IAC", c
));
161 printoption("td: recv IAC", c
));
171 printoption("td: recv IAC", c
));
172 ptyflush(); /* half-hearted */
175 if (slctab
[SLC_AO
].sptr
&&
176 *slctab
[SLC_AO
].sptr
!= (cc_t
)(_POSIX_VDISABLE
)) {
178 (unsigned char)*slctab
[SLC_AO
].sptr
;
181 netclear(); /* clear buffer back */
182 output_data ("%c%c", IAC
, DM
);
183 neturg
= nfrontp
-1; /* off by one XXX */
185 printoption("td: send IAC", DM
));
190 * Erase Character and
199 printoption("td: recv IAC", c
));
200 ptyflush(); /* half-hearted */
203 ch
= *slctab
[SLC_EC
].sptr
;
205 ch
= *slctab
[SLC_EL
].sptr
;
206 if (ch
!= (cc_t
)(_POSIX_VDISABLE
))
207 *pfrontp
++ = (unsigned char)ch
;
212 * Check for urgent data...
216 printoption("td: recv IAC", c
));
217 SYNCHing
= stilloob(net
);
223 * Begin option subnegotiation...
246 if (his_state_is_will(TELOPT_EOR
))
251 * Handle RFC 10xx Telnet linemode option additions
252 * to command stream (EOF, SUSP, ABORT).
285 * bad form of suboption negotiation.
286 * handle it in such a way as to avoid
287 * damage to local state. Parse
288 * suboption buffer found so far,
289 * then treat remaining stream as
290 * another command sequence.
293 /* for DIAGNOSTICS */
306 /* for DIAGNOSTICS */
312 suboption(); /* handle sub-option */
324 if (c
==TELOPT_ENCRYPT
&& his_do_dont_is_changing(TELOPT_ENCRYPT
) )
340 syslog(LOG_ERR
, "telnetd: panic state=%d\n", state
);
341 printf("telnetd: panic state=%d\n", state
);
345 } /* end of telrcv */
348 * The will/wont/do/dont state machines are based on Dave Borman's
349 * Telnet option processing state machine.
351 * These correspond to the following states:
352 * my_state = the last negotiated state
353 * want_state = what I want the state to go to
354 * want_resp = how many requests I have sent
355 * All state defaults are negative, and resp defaults to 0.
357 * When initiating a request to change state to new_state:
359 * if ((want_resp == 0 && new_state == my_state) || want_state == new_state) {
362 * want_state = new_state;
367 * When receiving new_state:
371 * if (want_resp && (new_state == my_state))
374 * if ((want_resp == 0) && (new_state != want_state)) {
375 * if (ok_to_switch_to new_state)
376 * want_state = new_state;
381 * my_state = new_state;
383 * Note that new_state is implied in these functions by the function itself.
384 * will and do imply positive new_state, wont and dont imply negative.
386 * Finally, there is one catch. If we send a negative response to a
387 * positive request, my_state will be the positive while want_state will
388 * remain negative. my_state will revert to negative when the negative
389 * acknowlegment arrives from the peer. Thus, my_state generally tells
390 * us not only the last negotiated state, but also tells us what the peer
391 * wants to be doing as well. It is important to understand this difference
392 * as we may wish to be processing data streams based on our desired state
393 * (want_state) or based on what the peer thinks the state is (my_state).
395 * This all works fine because if the peer sends a positive request, the data
396 * that we receive prior to negative acknowlegment will probably be affected
397 * by the positive state, and we can process it as such (if we can; if we
398 * can't then it really doesn't matter). If it is that important, then the
399 * peer probably should be buffering until this option state negotiation
404 send_do(int option
, int init
)
407 if ((do_dont_resp
[option
] == 0 && his_state_is_will(option
)) ||
408 his_want_state_is_will(option
))
411 * Special case for TELOPT_TM: We send a DO, but pretend
412 * that we sent a DONT, so that we can send more DOs if
415 if (option
== TELOPT_TM
)
416 set_his_want_state_wont(option
);
418 set_his_want_state_will(option
);
419 do_dont_resp
[option
]++;
421 output_data((const char *)doopt
, option
);
423 DIAG(TD_OPTIONS
, printoption("td: send do", option
));
426 #ifdef AUTHENTICATION
427 extern void auth_request(void);
430 extern void encrypt_send_support(void);
434 willoption(int option
)
437 void (*func
)(void) = NULL
;
440 * process input from peer.
443 DIAG(TD_OPTIONS
, printoption("td: recv will", option
));
445 if (do_dont_resp
[option
]) {
446 do_dont_resp
[option
]--;
447 if (do_dont_resp
[option
] && his_state_is_will(option
))
448 do_dont_resp
[option
]--;
450 if (do_dont_resp
[option
] == 0) {
451 if (his_want_state_is_wont(option
)) {
463 * See comments below for more info.
465 not42
= 0; /* looks like a 4.2 system */
470 * We never respond to a WILL TM, and
471 * we leave the state WONT.
477 * If we are going to support flow control
478 * option, then don't worry peer that we can't
479 * change the flow control characters.
481 slctab
[SLC_XON
].defset
.flag
&= ~SLC_LEVELBITS
;
482 slctab
[SLC_XON
].defset
.flag
|= SLC_DEFAULT
;
483 slctab
[SLC_XOFF
].defset
.flag
&= ~SLC_LEVELBITS
;
484 slctab
[SLC_XOFF
].defset
.flag
|= SLC_DEFAULT
;
489 case TELOPT_XDISPLOC
:
490 case TELOPT_NEW_ENVIRON
:
491 case TELOPT_OLD_ENVIRON
:
496 #ifdef AUTHENTICATION
497 case TELOPT_AUTHENTICATION
:
505 func
= encrypt_send_support
;
514 set_his_want_state_will(option
);
517 do_dont_resp
[option
]++;
518 send_dont(option
, 0);
522 * Option processing that should happen when
523 * we receive conformation of a change in
524 * state that we had requested.
528 not42
= 0; /* looks like a 4.2 system */
530 * Egads, he responded "WILL ECHO". Turn
533 send_dont(option
, 1);
535 * "WILL ECHO". Kludge upon kludge!
536 * A 4.2 client is now echoing user input at
537 * the tty. This is probably undesireable and
538 * it should be stopped. The client will
539 * respond WONT TM to the DO TM that we send to
540 * check for kludge linemode. When the WONT TM
541 * arrives, linemode will be turned off and a
542 * change propogated to the pty. This change
543 * will cause us to process the new pty state
544 * in localstat(), which will notice that
545 * linemode is off and send a WILL ECHO
546 * so that we are properly in character mode and
551 #ifdef AUTHENTICATION
552 case TELOPT_AUTHENTICATION
:
559 func
= encrypt_send_support
;
569 set_his_state_will(option
);
572 } /* end of willoption */
575 send_dont(int option
, int init
)
578 if ((do_dont_resp
[option
] == 0 && his_state_is_wont(option
)) ||
579 his_want_state_is_wont(option
))
581 set_his_want_state_wont(option
);
582 do_dont_resp
[option
]++;
584 output_data((const char *)dont
, option
);
586 DIAG(TD_OPTIONS
, printoption("td: send dont", option
));
590 wontoption(int option
)
593 * Process client input.
596 DIAG(TD_OPTIONS
, printoption("td: recv wont", option
));
598 if (do_dont_resp
[option
]) {
599 do_dont_resp
[option
]--;
600 if (do_dont_resp
[option
] && his_state_is_wont(option
))
601 do_dont_resp
[option
]--;
603 if (do_dont_resp
[option
] == 0) {
604 if (his_want_state_is_will(option
)) {
605 /* it is always ok to change to negative state */
608 not42
= 1; /* doesn't seem to be a 4.2 system */
619 * If we get a WONT TM, and had sent a DO TM,
620 * don't respond with a DONT TM, just leave it
621 * as is. Short circut the state machine to
624 set_his_want_state_wont(TELOPT_TM
);
629 * If we are not going to support flow control
630 * option, then let peer know that we can't
631 * change the flow control characters.
633 slctab
[SLC_XON
].defset
.flag
&= ~SLC_LEVELBITS
;
634 slctab
[SLC_XON
].defset
.flag
|= SLC_CANTCHANGE
;
635 slctab
[SLC_XOFF
].defset
.flag
&= ~SLC_LEVELBITS
;
636 slctab
[SLC_XOFF
].defset
.flag
|= SLC_CANTCHANGE
;
639 #ifdef AUTHENTICATION
640 case TELOPT_AUTHENTICATION
:
641 auth_finished(0, AUTH_REJECT
);
646 * For options that we might spin waiting for
647 * sub-negotiation, if the client turns off the
648 * option rather than responding to the request,
649 * we have to treat it here as if we got a response
650 * to the sub-negotiation, (by updating the timers)
651 * so that we'll break out of the loop.
654 settimer(ttypesubopt
);
658 settimer(tspeedsubopt
);
661 case TELOPT_XDISPLOC
:
662 settimer(xdisplocsubopt
);
665 case TELOPT_OLD_ENVIRON
:
666 settimer(oenvironsubopt
);
669 case TELOPT_NEW_ENVIRON
:
670 settimer(environsubopt
);
676 set_his_want_state_wont(option
);
677 if (his_state_is_will(option
))
678 send_dont(option
, 0);
684 #ifdef AUTHENTICATION
685 case TELOPT_AUTHENTICATION
:
686 auth_finished(0, AUTH_REJECT
);
694 set_his_state_wont(option
);
696 } /* end of wontoption */
699 send_will(int option
, int init
)
702 if ((will_wont_resp
[option
] == 0 && my_state_is_will(option
))||
703 my_want_state_is_will(option
))
705 set_my_want_state_will(option
);
706 will_wont_resp
[option
]++;
708 output_data ((const char *)will
, option
);
710 DIAG(TD_OPTIONS
, printoption("td: send will", option
));
714 * When we get a DONT SGA, we will try once to turn it
715 * back on. If the other side responds DONT SGA, we
716 * leave it at that. This is so that when we talk to
717 * clients that understand KLUDGELINEMODE but not LINEMODE,
718 * we'll keep them in char-at-a-time mode.
728 * Process client input.
731 DIAG(TD_OPTIONS
, printoption("td: recv do", option
));
733 if (will_wont_resp
[option
]) {
734 will_wont_resp
[option
]--;
735 if (will_wont_resp
[option
] && my_state_is_will(option
))
736 will_wont_resp
[option
]--;
738 if ((will_wont_resp
[option
] == 0) && (my_want_state_is_wont(option
))) {
767 * Special case for TM. We send a WILL, but
768 * pretend we sent a WONT.
770 send_will(option
, 0);
771 set_my_want_state_wont(option
);
772 set_my_state_wont(option
);
777 * When we get a LOGOUT option, respond
778 * with a WILL LOGOUT, make sure that
779 * it gets written out to the network,
780 * and then just go away...
782 set_my_want_state_will(TELOPT_LOGOUT
);
783 send_will(TELOPT_LOGOUT
, 0);
784 set_my_state_will(TELOPT_LOGOUT
);
795 case TELOPT_LINEMODE
:
800 case TELOPT_XDISPLOC
:
801 #ifdef TELOPT_ENVIRON
802 case TELOPT_NEW_ENVIRON
:
804 case TELOPT_OLD_ENVIRON
:
809 set_my_want_state_will(option
);
810 send_will(option
, 0);
812 will_wont_resp
[option
]++;
813 send_wont(option
, 0);
816 set_my_state_will(option
);
818 } /* end of dooption */
821 send_wont(int option
, int init
)
824 if ((will_wont_resp
[option
] == 0 && my_state_is_wont(option
)) ||
825 my_want_state_is_wont(option
))
827 set_my_want_state_wont(option
);
828 will_wont_resp
[option
]++;
830 output_data ((const char *)wont
, option
);
832 DIAG(TD_OPTIONS
, printoption("td: send wont", option
));
836 dontoption(int option
)
839 * Process client input.
843 DIAG(TD_OPTIONS
, printoption("td: recv dont", option
));
845 if (will_wont_resp
[option
]) {
846 will_wont_resp
[option
]--;
847 if (will_wont_resp
[option
] && my_state_is_wont(option
))
848 will_wont_resp
[option
]--;
850 if ((will_wont_resp
[option
] == 0) && (my_want_state_is_will(option
))) {
858 case TELOPT_ECHO
: /* we should stop echoing */
867 set_my_want_state_wont(option
);
868 if (my_state_is_will(option
))
869 send_wont(option
, 0);
870 set_my_state_wont(option
);
871 if (turn_on_sga
^= 1)
872 send_will(option
, 1);
879 set_my_want_state_wont(option
);
880 if (my_state_is_will(option
))
881 send_wont(option
, 0);
883 set_my_state_wont(option
);
885 } /* end of dontoption */
891 # define env_ovar OLD_ENV_VAR
892 # define env_ovalue OLD_ENV_VALUE
893 #endif /* ENV_HACK */
898 * Look at the sub-option buffer, and try to be helpful to the other
901 * Currently we recognize:
913 DIAG(TD_OPTIONS
, {netflush(); printsub('<', subpointer
, SB_LEN()+2);});
917 case TELOPT_TSPEED
: {
920 if (his_state_is_wont(TELOPT_TSPEED
)) /* Ignore if option disabled */
923 settimer(tspeedsubopt
);
925 if (SB_EOF() || SB_GET() != TELQUAL_IS
)
928 xspeed
= atoi((char *)subpointer
);
930 while (SB_GET() != ',' && !SB_EOF());
934 rspeed
= atoi((char *)subpointer
);
935 clientstat(TELOPT_TSPEED
, xspeed
, rspeed
);
939 } /* end of case TELOPT_TSPEED */
941 case TELOPT_TTYPE
: { /* Yaaaay! */
944 if (his_state_is_wont(TELOPT_TTYPE
)) /* Ignore if option disabled */
946 settimer(ttypesubopt
);
948 if (SB_EOF() || SB_GET() != TELQUAL_IS
) {
949 return; /* ??? XXX but, this is the most robust */
954 while ((p
< (terminaltype
+ sizeof terminaltype
-1)) &&
962 *p
++ = c
; /* accumulate name */
966 } /* end of case TELOPT_TTYPE */
969 int xwinsize
, ywinsize
;
971 if (his_state_is_wont(TELOPT_NAWS
)) /* Ignore if option disabled */
976 xwinsize
= SB_GET() << 8;
979 xwinsize
|= SB_GET();
982 ywinsize
= SB_GET() << 8;
985 ywinsize
|= SB_GET();
986 clientstat(TELOPT_NAWS
, xwinsize
, ywinsize
);
990 } /* end of case TELOPT_NAWS */
992 case TELOPT_STATUS
: {
1000 if (my_state_is_will(TELOPT_STATUS
))
1011 } /* end of case TELOPT_STATUS */
1013 case TELOPT_XDISPLOC
: {
1014 if (SB_EOF() || SB_GET() != TELQUAL_IS
)
1016 settimer(xdisplocsubopt
);
1017 subpointer
[SB_LEN()] = '\0';
1018 esetenv("DISPLAY", (char *)subpointer
, 1);
1020 } /* end of case TELOPT_XDISPLOC */
1022 #ifdef TELOPT_NEW_ENVIRON
1023 case TELOPT_NEW_ENVIRON
:
1025 case TELOPT_OLD_ENVIRON
: {
1027 char *cp
, *varp
, *valp
;
1032 if (c
== TELQUAL_IS
) {
1033 if (subchar
== TELOPT_OLD_ENVIRON
)
1034 settimer(oenvironsubopt
);
1036 settimer(environsubopt
);
1037 } else if (c
!= TELQUAL_INFO
) {
1041 #ifdef TELOPT_NEW_ENVIRON
1042 if (subchar
== TELOPT_NEW_ENVIRON
) {
1045 if ((c
== NEW_ENV_VAR
) || (c
== ENV_USERVAR
))
1053 * We only want to do this if we haven't already decided
1054 * whether or not the other side has its VALUE and VAR
1058 int last
= -1; /* invalid value */
1060 int got_var
= 0, got_value
= 0, got_uservar
= 0;
1063 * The other side might have its VALUE and VAR values
1064 * reversed. To be interoperable, we need to determine
1065 * which way it is. If the first recognized character
1066 * is a VAR or VALUE, then that will tell us what
1067 * type of client it is. If the fist recognized
1068 * character is a USERVAR, then we continue scanning
1069 * the suboption looking for two consecutive
1070 * VAR or VALUE fields. We should not get two
1071 * consecutive VALUE fields, so finding two
1072 * consecutive VALUE or VAR fields will tell us
1073 * what the client is.
1080 if (last
< 0 || last
== OLD_ENV_VAR
1081 || (empty
&& (last
== OLD_ENV_VALUE
)))
1087 if (last
< 0 || last
== OLD_ENV_VALUE
1088 || (empty
&& (last
== OLD_ENV_VAR
)))
1089 goto env_ovar_wrong
;
1091 last
= OLD_ENV_VALUE
;
1094 /* count strings of USERVAR as one */
1095 if (last
!= ENV_USERVAR
)
1098 if (last
== OLD_ENV_VALUE
)
1100 if (last
== OLD_ENV_VAR
)
1101 goto env_ovar_wrong
;
1116 if (last
== OLD_ENV_VALUE
)
1118 if (last
== OLD_ENV_VAR
)
1119 goto env_ovar_wrong
;
1122 * Ok, the first thing was a USERVAR, and there
1123 * are not two consecutive VAR or VALUE commands,
1124 * and none of the VAR or VALUE commands are empty.
1125 * If the client has sent us a well-formed option,
1126 * then the number of VALUEs received should always
1127 * be less than or equal to the number of VARs and
1128 * USERVARs received.
1130 * If we got exactly as many VALUEs as VARs and
1131 * USERVARs, the client has the same definitions.
1133 * If we got exactly as many VARs as VALUEs and
1134 * USERVARS, the client has reversed definitions.
1136 if (got_uservar
+ got_var
== got_value
) {
1138 env_ovar
= OLD_ENV_VAR
;
1139 env_ovalue
= OLD_ENV_VALUE
;
1140 } else if (got_uservar
+ got_value
== got_var
) {
1142 env_ovar
= OLD_ENV_VALUE
;
1143 env_ovalue
= OLD_ENV_VAR
;
1145 output_data("ENVIRON VALUE and VAR are reversed!\r\n");
1155 if ((c
== env_ovar
) || (c
== ENV_USERVAR
))
1163 cp
= varp
= (char *)subpointer
;
1168 if (subchar
== TELOPT_OLD_ENVIRON
) {
1171 else if (c
== env_ovalue
)
1178 cp
= valp
= (char *)subpointer
;
1185 esetenv(varp
, valp
, 1);
1188 cp
= varp
= (char *)subpointer
;
1204 esetenv(varp
, valp
, 1);
1208 } /* end of case TELOPT_NEW_ENVIRON */
1209 #ifdef AUTHENTICATION
1210 case TELOPT_AUTHENTICATION
:
1217 * These are sent by us and cannot be sent by
1222 auth_is(subpointer
, SB_LEN());
1225 auth_name(subpointer
, SB_LEN());
1231 case TELOPT_ENCRYPT
:
1235 case ENCRYPT_SUPPORT
:
1236 encrypt_support(subpointer
, SB_LEN());
1239 encrypt_is(subpointer
, SB_LEN());
1242 encrypt_reply(subpointer
, SB_LEN());
1245 encrypt_start(subpointer
, SB_LEN());
1248 if (require_encryption
)
1249 fatal(net
, "Output encryption is not possible to turn off");
1252 case ENCRYPT_REQSTART
:
1253 encrypt_request_start(subpointer
, SB_LEN());
1255 case ENCRYPT_REQEND
:
1257 * We can always send an REQEND so that we cannot
1258 * get stuck encrypting. We should only get this
1259 * if we have been able to get in the correct mode
1262 if (require_encryption
)
1263 fatal(net
, "Input encryption is not possible to turn off");
1264 encrypt_request_end();
1266 case ENCRYPT_ENC_KEYID
:
1267 encrypt_enc_keyid(subpointer
, SB_LEN());
1269 case ENCRYPT_DEC_KEYID
:
1270 encrypt_dec_keyid(subpointer
, SB_LEN());
1280 } /* end of switch */
1282 } /* end of suboption */
1287 clientstat(TELOPT_LINEMODE
, WILL
, 0);
1291 #define ADD(c) *ncp++ = c
1292 #define ADD_DATA(c) { *ncp++ = c; if (c == SE || c == IAC) *ncp++ = c; }
1297 unsigned char statusbuf
[256];
1303 netflush(); /* get rid of anything waiting to go out */
1311 * We check the want_state rather than the current state,
1312 * because if we received a DO/WILL for an option that we
1313 * don't support, and the other side didn't send a DONT/WONT
1314 * in response to our WONT/DONT, then the "state" will be
1315 * WILL/DO, and the "want_state" will be WONT/DONT. We
1316 * need to go by the latter.
1318 for (i
= 0; i
< (unsigned char)NTELOPTS
; i
++) {
1319 if (my_want_state_is_will(i
)) {
1323 if (his_want_state_is_will(i
)) {
1329 if (his_want_state_is_will(TELOPT_LFLOW
)) {
1339 if (restartany
>= 0) {
1343 ADD(LFLOW_RESTART_ANY
);
1345 ADD(LFLOW_RESTART_XON
);
1355 writenet(statusbuf
, ncp
- statusbuf
);
1356 netflush(); /* Send it on its way */
1359 {printsub('>', statusbuf
, ncp
- statusbuf
); netflush();});