* Copyright (c) 1988 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)telnet.c 5.46 (Berkeley) %G%";
/* By the way, we need to include curses.h before telnet.h since,
* among other things, telnet.h #defines 'DO', which is a variable
#endif /* defined(unix) */
#define strip(x) ((x)&0x7f)
static char subbuffer
[SUBBUFSIZE
],
*subpointer
, *subend
; /* buffer for sub-options */
#define SB_CLEAR() subpointer = subbuffer;
#define SB_TERM() subend = subpointer;
#define SB_ACCUM(c) if (subpointer < (subbuffer+sizeof subbuffer)) { \
char options
[256]; /* The combined options */
char will_wont_resp
[256];
In3270
, /* Are we in 3270 mode? */
ISend
, /* trying to send network data in */
netdata
, /* Print out network data flow */
crlf
, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
noasynchtty
= 0,/* User specified "-noasynch" on command line */
noasynchnet
= 0,/* User specified "-noasynch" on command line */
askedSGA
= 0, /* We have talked about suppress go ahead */
#endif /* defined(TN3270) */
SYNCHing
, /* we are in TELNET SYNCH mode */
flushout
, /* flush output */
autoflush
= 0, /* flush output when interrupting? */
autosynch
, /* send interrupt characters with SYNCH? */
localflow
, /* we handle flow control locally */
localchars
, /* we recognize interrupt/quit */
donelclchars
, /* the user has set "localchars" */
donebinarytoggle
, /* the user has put us in binary */
dontlecho
, /* do we suppress local echoing right now? */
#define CONTROL(x) ((x)&0x1f) /* CTRL(x) is not portable */
unsigned char *prompt
= 0;
* Telnet receiver states for fsm
#define TS_SB 7 /* sub-option collection */
#define TS_SE 8 /* looking for sub-option end */
jmp_buf toplevel
= { 0 };
* The following are some clocks used to decide how to interpret
* the relationship between various variables.
{ "telnet command mode", COMMAND_LINE
},
{ "character-at-a-time mode", 0 },
{ "character-at-a-time mode (local echo)", LOCAL_ECHO
|LOCAL_CHARS
},
{ "line-by-line mode (remote echo)", LINE
| LOCAL_CHARS
},
{ "line-by-line mode", LINE
| LOCAL_ECHO
| LOCAL_CHARS
},
{ "line-by-line mode (local echoing suppressed)", LINE
| LOCAL_CHARS
},
* Initialize telnet environment.
connected
= In3270
= ISend
= localflow
= donebinarytoggle
= 0;
/* Don't change NetTrace */
char buffer
[100]; /* where things go */
ring
= va_arg(ap
, Ring
*);
format
= va_arg(ap
, char *);
while ((i
= *format
++) != 0) {
*ptr
++ = va_arg(ap
, int);
string
= va_arg(ap
, char *);
ring_supply_data(ring
, buffer
, ptr
-buffer
);
ring_supply_data(ring
, string
, strlen(string
));
ExitString("printring: trailing %%.\n", 1);
ExitString("printring: unknown format character.\n", 1);
ring_supply_data(ring
, buffer
, ptr
-buffer
);
* These routines are in charge of sending option negotiations
* The basic idea is that we send the negotiation if either side
* is in disagreement as to what the current state should be.
if (((do_dont_resp
[c
] == 0) && my_state_is_do(c
)) ||
printoption("SENT", "do", c
);
if (((do_dont_resp
[c
] == 0) && my_state_is_dont(c
)) ||
my_want_state_is_dont(c
))
set_my_want_state_dont(c
);
printoption("SENT", "dont", c
);
if (((will_wont_resp
[c
] == 0) && my_state_is_will(c
)) ||
my_want_state_is_will(c
))
set_my_want_state_will(c
);
printoption("SENT", "will", c
);
if (((will_wont_resp
[c
] == 0) && my_state_is_wont(c
)) ||
my_want_state_is_wont(c
))
set_my_want_state_wont(c
);
printoption("SENT", "wont", c
);
if (do_dont_resp
[option
]) {
if (do_dont_resp
[option
] && my_state_is_do(option
))
if ((do_dont_resp
[option
] == 0) && my_want_state_is_dont(option
)) {
* The following is a pain in the rear-end.
* Various IBM servers (some versions of Wiscnet,
* possibly Fibronics/Spartacus, and who knows who
* else) will NOT allow us to send "DO SGA" too early
* in the setup proceedings. On the other hand,
* 4.2 servers (telnetd) won't set SGA correctly.
* So, we are stuck. Empirically (but, based on
* a VERY small sample), the IBM servers don't send
* out anything about ECHO, so we postpone our sending
* "DO SGA" until we see "WILL ECHO" (which 4.2 servers
if (my_want_state_is_dont(TELOPT_SGA
))
#endif /* defined(TN3270) */
settimer(modenegotiated
);
* Special case for TM. If we get back a WILL,
* pretend we got back a WONT.
set_my_want_state_dont(option
);
set_my_state_dont(option
);
return; /* Never reply to TM will's/wont's */
set_my_want_state_do(option
);
setconnmode(0); /* possibly set new tty mode */
if (do_dont_resp
[option
]) {
if (do_dont_resp
[option
] && my_state_is_dont(option
))
if ((do_dont_resp
[option
] == 0) && my_want_state_is_do(option
)) {
settimer(modenegotiated
);
set_my_want_state_dont(option
);
set_my_state_dont(option
);
return; /* Never reply to TM will's/wont's */
set_my_want_state_dont(option
);
setconnmode(0); /* Set new tty mode */
} else if (option
== TELOPT_TM
) {
set_my_want_state_dont(option
);
set_my_state_dont(option
);
if (will_wont_resp
[option
]) {
--will_wont_resp
[option
];
if (will_wont_resp
[option
] && my_state_is_will(option
))
--will_wont_resp
[option
];
if (will_wont_resp
[option
] == 0) {
if (my_want_state_is_wont(option
)) {
* Special case for TM. We send a WILL, but pretend
set_my_want_state_wont(TELOPT_TM
);
set_my_state_wont(TELOPT_TM
);
case TELOPT_EOR
: /* end of record */
# endif /* defined(TN3270) */
case TELOPT_BINARY
: /* binary mode */
case TELOPT_NAWS
: /* window size */
case TELOPT_TSPEED
: /* terminal speed */
case TELOPT_LFLOW
: /* local flow control */
case TELOPT_TTYPE
: /* terminal type option */
case TELOPT_SGA
: /* no big deal */
set_my_want_state_will(TELOPT_LINEMODE
);
set_my_state_will(TELOPT_LINEMODE
);
case TELOPT_ECHO
: /* We're never going to echo... */
set_my_want_state_will(option
);
will_wont_resp
[option
]++;
* Handle options that need more things done after the
* other side has acknowledged the option.
set_my_state_will(option
);
set_my_state_will(option
);
if (will_wont_resp
[option
]) {
--will_wont_resp
[option
];
if (will_wont_resp
[option
] && my_state_is_wont(option
))
--will_wont_resp
[option
];
if ((will_wont_resp
[option
] == 0) && my_want_state_is_will(option
)) {
linemode
= 0; /* put us back to the default state */
/* we always accept a DONT */
set_my_want_state_wont(option
);
setconnmode(0); /* Set new tty mode */
set_my_state_wont(option
);
* Given a buffer returned by tgetent(), this routine will turn
* the pipe seperated list of names in the buffer into an array
* of pointers to null terminated names. We toss out any bad,
* duplicate, or verbose names (names with spaces).
static char *unknown
[] = { "UNKNOWN", 0 };
register char c
, *cp
, **argvp
, *cp2
, **argv
;
* Count up the number of names.
for (n
= 1, cp
= buf
; *cp
&& *cp
!= ':'; cp
++) {
* Allocate an array to put the name pointers into
argv
= (char **)malloc((n
+3)*sizeof(char *));
* Fill up the array of pointers to names.
for (cp
= cp2
= buf
; (c
= *cp
); cp
++) {
if (c
== '|' || c
== ':') {
* Skip entries that have spaces or are over 40
* characters long. If this is our environment
* name, then put it up front. Otherwise, as
* long as this is not a duplicate name (case
* insensitive) add it to the list.
if (n
|| (cp
- cp2
> 41))
else if (name
&& (strncasecmp(name
, cp2
, cp
-cp2
) == 0))
else if (is_unique(cp2
, argv
+1, argvp
))
* Skip multiple delimiters. Reset cp2 to
* the beginning of the next name. Reset n,
* the flag for names with spaces.
* Skip entries with spaces or non-ascii values.
* Convert lower case letters to upper case.
if ((c
== ' ') || !isascii(c
))
* Check for an old V6 2 character name. If the second
* name points to the beginning of the buffer, and is
* only 2 characters long, move it to the end of the array.
if ((argv
[1] == buf
) && (strlen(argv
[1]) == 2)) {
* Duplicate last name, for TTYPE option, and null
* terminate the array. If we didn't find a match on
* our terminal name, put that name at the beginning.
register char *name
, **as
, **ae
;
for (ap
= as
; ap
< ae
; ap
++)
if (strncasecmp(*ap
, name
, n
) == 0)
setupterm(tname
, fd
, errp
)
if (tgetent(termbuf
, tname
) == 1) {
if ((tname
= getenv("TERM")) &&
(setupterm(tname
, 1, &err
) == 0)) {
tnamep
= mklist(termbuf
, tname
);
if (tname
&& (strlen(tname
) <= 40)) {
* Look at the sub-option buffer, and try to be helpful to the other
* Currently we recognize:
* Terminal type, send request.
* Terminal speed (send request).
* Local flow control (is request).
printsub('<', subbuffer
, subend
-subbuffer
+2);
switch (subbuffer
[0]&0xff) {
if (my_want_state_is_wont(TELOPT_TTYPE
))
if ((subbuffer
[1]&0xff) != TELQUAL_SEND
) {
#endif /* defined(TN3270) */
len
= strlen(name
) + 4 + 2;
sprintf(temp
, "%c%c%c%c%s%c%c", IAC
, SB
, TELOPT_TTYPE
,
TELQUAL_IS
, name
, IAC
, SE
);
ring_supply_data(&netoring
, temp
, len
);
printsub('>', &temp
[2], len
-2);
ExitString("No room in buffer for terminal type.\n", 1);
if (my_want_state_is_wont(TELOPT_TSPEED
))
if ((subbuffer
[1]&0xff) == TELQUAL_SEND
) {
TerminalSpeeds(&ispeed
, &ospeed
);
sprintf(temp
, "%c%c%c%c%d,%d%c%c", IAC
, SB
, TELOPT_TSPEED
,
TELQUAL_IS
, ospeed
, ispeed
, IAC
, SE
);
len
= strlen(temp
+4) + 4; /* temp[3] is 0 ... */
ring_supply_data(&netoring
, temp
, len
);
printsub('>', temp
+2, len
- 2);
if (my_want_state_is_wont(TELOPT_LFLOW
))
if ((subbuffer
[1]&0xff) == 1) {
} else if ((subbuffer
[1]&0xff) == 0) {
if (my_want_state_is_wont(TELOPT_LINEMODE
))
switch (subbuffer
[1]&0xff) {
lm_will(&subbuffer
[2], subend
- &subbuffer
[2]);
lm_wont(&subbuffer
[2], subend
- &subbuffer
[2]);
lm_do(&subbuffer
[2], subend
- &subbuffer
[2]);
lm_dont(&subbuffer
[2], subend
- &subbuffer
[2]);
slc(&subbuffer
[2], subend
- &subbuffer
[2]);
lm_mode(&subbuffer
[2], subend
- &subbuffer
[2], 0);
static char str_lm
[] = { IAC
, SB
, TELOPT_LINEMODE
, 0, 0, IAC
, SE
};
case LM_FORWARDMASK
: /* We shouldn't ever get this... */
if (NETROOM() > sizeof(str_lm
)) {
ring_supply_data(&netoring
, str_lm
, sizeof(str_lm
));
printsub('>', &str_lm
[2], sizeof(str_lm
)-2);
/*@*/ else printf("lm_will: not enough room in buffer\n");
case LM_FORWARDMASK
: /* We shouldn't ever get this... */
/* We are always DONT, so don't respond */
if (NETROOM() > sizeof(str_lm
)) {
ring_supply_data(&netoring
, str_lm
, sizeof(str_lm
));
printsub('>', &str_lm
[2], sizeof(str_lm
)-2);
/*@*/ else printf("lm_do: not enough room in buffer\n");
/* we are always WONT, so don't respond */
static char str_lm_mode
[] = { IAC
, SB
, TELOPT_LINEMODE
, LM_MODE
, 0, IAC
, SE
};
if ((linemode
&(MODE_EDIT
|MODE_TRAPSIG
)) == *cmd
)
linemode
= (*cmd
&(MODE_EDIT
|MODE_TRAPSIG
));
str_lm_mode
[4] = linemode
;
str_lm_mode
[4] |= MODE_ACK
;
if (NETROOM() > sizeof(str_lm_mode
)) {
ring_supply_data(&netoring
, str_lm_mode
, sizeof(str_lm_mode
));
printsub('>', &str_lm_mode
[2], sizeof(str_lm_mode
)-2);
/*@*/ else printf("lm_mode: not enough room in buffer\n");
setconnmode(0); /* set changed mode */
* Handle special character suboption of LINEMODE.
char flags
; /* Current flags & level */
char mylevel
; /* Maximum level & flags */
static int slc_mode
= SLC_EXPORT
;
register struct spc
*spcp
;
for (spcp
= spc_data
; spcp
< &spc_data
[NSLC
+1]; spcp
++) {
spcp
->flags
= spcp
->mylevel
= SLC_NOSUPPORT
;
#define initfunc(func, flags) { \
spcp = &spc_data[func]; \
if (spcp->valp = tcval(func)) { \
spcp->val = *spcp->valp; \
spcp->mylevel = SLC_VARIABLE|flags; \
spcp->mylevel = SLC_DEFAULT; \
initfunc(SLC_ABORT
, SLC_FLUSHIN
|SLC_FLUSHOUT
);
initfunc(SLC_SUSP
, SLC_FLUSHIN
);
spc_data
[SLC_XON
].mylevel
= SLC_CANTCHANGE
;
spc_data
[SLC_XOFF
].mylevel
= SLC_CANTCHANGE
;
initfunc(SLC_IP
, SLC_FLUSHIN
|SLC_FLUSHOUT
);
if (slc_mode
== SLC_EXPORT
)
printf("Special characters are %s values\n",
slc_mode
== SLC_IMPORT
? "remote default" :
slc_mode
== SLC_EXPORT
? "local" :
if (my_state_is_will(TELOPT_LINEMODE
))
slc_mode
= def
? SLC_IMPORT
: SLC_RVALUE
;
if (my_state_is_will(TELOPT_LINEMODE
))
char slc_import_val
[] = {
IAC
, SB
, TELOPT_LINEMODE
, LM_SLC
, 0, SLC_VARIABLE
, 0, IAC
, SE
char slc_import_def
[] = {
IAC
, SB
, TELOPT_LINEMODE
, LM_SLC
, 0, SLC_DEFAULT
, 0, IAC
, SE
if (NETROOM() > sizeof(slc_import_val
)) {
ring_supply_data(&netoring
, slc_import_def
, sizeof(slc_import_def
));
printsub('>', &slc_import_def
[2], sizeof(slc_import_def
)-2);
ring_supply_data(&netoring
, slc_import_val
, sizeof(slc_import_val
));
printsub('>', &slc_import_val
[2], sizeof(slc_import_val
)-2);
/*@*/ else printf("slc_import: not enough room\n");
register struct spc
*spcp
;
for (spcp
= &spc_data
[1]; spcp
< &spc_data
[NSLC
+1]; spcp
++) {
if (spcp
->mylevel
!= SLC_NOSUPPORT
) {
spcp
->flags
= spcp
->mylevel
;
slc_add_reply(spcp
- spc_data
, spcp
->mylevel
, spcp
->val
);
setconnmode(1); /* set the new character values */
register struct spc
*spcp
;
for (; len
>= 3; len
-=3, cp
+=3) {
* Client side: always ignore 0 function.
if (cp
[SLC_FLAGS
] & SLC_LEVELBITS
!= SLC_NOSUPPORT
)
slc_add_reply(func
, SLC_NOSUPPORT
, 0);
level
= cp
[SLC_FLAGS
]&(SLC_LEVELBITS
|SLC_ACK
);
if ((cp
[SLC_VALUE
] == (unsigned char)spcp
->val
) &&
((level
&SLC_LEVELBITS
) == (spcp
->flags
&SLC_LEVELBITS
))) {
if (level
== (SLC_DEFAULT
|SLC_ACK
)) {
* This is an error condition, the SLC_ACK
* bit should never be set for the SLC_DEFAULT
* level. Our best guess to recover is to
* ignore the SLC_ACK bit.
cp
[SLC_FLAGS
] &= ~SLC_ACK
;
if (level
== ((spcp
->flags
&SLC_LEVELBITS
)|SLC_ACK
)) {
spcp
->val
= (cc_t
)cp
[SLC_VALUE
];
spcp
->flags
= cp
[SLC_FLAGS
]; /* include SLC_ACK */
if (level
<= (spcp
->mylevel
&SLC_LEVELBITS
)) {
spcp
->flags
= cp
[SLC_FLAGS
]|SLC_ACK
;
spcp
->val
= (cc_t
)cp
[SLC_VALUE
];
if (level
== SLC_DEFAULT
) {
if ((spcp
->mylevel
&SLC_LEVELBITS
) != SLC_DEFAULT
)
spcp
->flags
= spcp
->mylevel
;
spcp
->flags
= SLC_NOSUPPORT
;
slc_add_reply(func
, spcp
->flags
, spcp
->val
);
setconnmode(1); /* set the new character values */
register struct spc
*spcp
;
for (spcp
= &spc_data
[1]; spcp
< &spc_data
[NSLC
+1]; spcp
++) {
if (spcp
->valp
&& spcp
->val
!= *spcp
->valp
) {
slc_add_reply(spcp
- spc_data
, spcp
->mylevel
, spcp
->val
);
unsigned char slc_reply
[128];
unsigned char *slc_replyp
;
*slc_replyp
++ = TELOPT_LINEMODE
;
slc_add_reply(func
, flags
, value
)
if ((*slc_replyp
++ = func
) == IAC
)
if ((*slc_replyp
++ = flags
) == IAC
)
if ((*slc_replyp
++ = (unsigned char)value
) == IAC
)
len
= slc_replyp
- slc_reply
;
ring_supply_data(&netoring
, slc_reply
, slc_replyp
- slc_reply
);
printsub('>', &slc_reply
[2], slc_replyp
- slc_reply
- 2);
/*@*/else printf("slc_end_reply: not enough room\n");
register struct spc
*spcp
;
for (spcp
= &spc_data
[1]; spcp
< &spc_data
[NSLC
+1]; spcp
++) {
if (!(spcp
->flags
&SLC_ACK
))
if (spcp
->valp
&& (*spcp
->valp
!= spcp
->val
)) {
ring_consumed(&netiring
, count
);
scc
= ring_full_consecutive(&netiring
);
/* No more data coming in */
c
= *sbp
++ & 0xff, scc
--; count
++;
break; /* Ignore \0 after CR */
else if ((c
== '\n') && my_want_state_is_dont(TELOPT_ECHO
) && !crmod
) {
c
= *sbp
++ & 0377, scc
--; count
++;
# endif /* defined(TN3270) */
* The 'crmod' hack (see following) is needed
* since we can't * set CRMOD on output only.
* Machines like MULTICS like to send \r without
* \n; since we must turn off CRMOD to get proper
* input, the mapping is done here (sigh).
if ((c
== '\r') && my_want_state_is_dont(TELOPT_BINARY
)) {
} else if (my_want_state_is_dont(TELOPT_ECHO
) &&
* We may have missed an urgent notification,
* so make sure we flush whatever is in the
printoption("RCVD", "IAC", SB
);
Ibackp
+= DataFromNetwork(Ibackp
, Ifrontp
-Ibackp
, 1);
ISend
= 0; /* should have been! */
# endif /* defined(TN3270) */
# else /* !defined(TN3270) */
# endif /* !defined(TN3270) */
printoption("RCVD", "will", c
);
printoption("RCVD", "wont", c
);
printoption("RCVD", "do", c
);
} else if (c
== TELOPT_LFLOW
) {
printoption("RCVD", "dont", c
);
setconnmode(0); /* set new tty mode (maybe) */
* This is an error. We only expect to get
* "IAC IAC" or "IAC SE". Several things may
* have happend. An IAC was not doubled, the
* IAC SE was left off, or another option got
* inserted into the suboption are all possibilities.
* If we assume that the IAC was not doubled,
* and really the IAC SE was left off, we could
* get into an infinate loop here. So, instead,
* we terminate the suboption, and process the
* partial suboption if we can.
printoption("In SUBOPTION processing, RCVD", "IAC", c
);
suboption(); /* handle sub-option */
suboption(); /* handle sub-option */
ring_consumed(&netiring
, count
);
return returnValue
||count
;
ring_consumed(&ttyiring
, count
);
tcc
= ring_full_consecutive(&ttyiring
);
c
= *tbp
++ & 0xff, sc
= strip(c
), tcc
--; count
++;
* Double escape is a pass through of a single escape character.
if (tcc
&& strip(*tbp
) == escape
) {
if (kludgelinemode
&& (globalmode
&MODE_EDIT
) && (sc
== echoc
)) {
if (tcc
> 0 && strip(*tbp
) == echoc
) {
if (MODE_LOCAL_CHARS(globalmode
)) {
if (TerminalSpecialChars(sc
) == 0) {
if (my_want_state_is_wont(TELOPT_BINARY
)) {
* If we are in CRMOD mode (\r ==> \n)
* on our local machine, then probably
* a newline (unix) is CRLF (TELNET).
if (MODE_LOCAL_CHARS(globalmode
)) {
ring_consumed(&ttyiring
, count
);
return returnValue
||count
; /* Non-zero if we did anything */
* If we do something useful, return 1; else return 0.
int block
; /* should we block in the select ? */
/* One wants to be a bit careful about setting returnValue
* to one, since a one implies we did some useful work,
* and therefore probably won't be called to block next
* time (TN3270 mode only).
int netin
, netout
, netex
, ttyin
, ttyout
;
/* Decide which rings should be processed */
netout
= ring_full_count(&netoring
) &&
(my_want_state_is_wont(TELOPT_LINEMODE
)
&& (!kludgelinemode
|| my_want_state_is_do(TELOPT_SGA
))
my_want_state_is_will(TELOPT_BINARY
));
ttyout
= ring_full_count(&ttyoring
);
ttyin
= ring_empty_count(&ttyiring
) && (shell_active
== 0);
#else /* defined(TN3270) */
ttyin
= ring_empty_count(&ttyiring
);
#endif /* defined(TN3270) */
netin
= ring_empty_count(&netiring
);
# else /* !defined(TN3270) */
netin
= !ISend
&& ring_empty_count(&netiring
);
# endif /* !defined(TN3270) */
/* If we have seen a signal recently, reset things */
# if defined(TN3270) && defined(unix)
signal(SIGIO
, inputAvailable
);
#endif /* defined(TN3270) && defined(unix) */
/* Call to system code to process rings */
returnValue
= process_rings(netin
, netout
, netex
, ttyin
, ttyout
, !block
);
/* Now, look at the input rings, looking for work to do. */
if (ring_full_count(&ttyiring
)) {
c
= DataFromTerminal(ttyiring
.consume
,
ring_full_consecutive(&ttyiring
));
ring_consumed(&ttyiring
, c
);
# endif /* defined(TN3270) */
# endif /* defined(TN3270) */
if (ring_full_count(&netiring
)) {
# else /* !defined(TN3270) */
returnValue
= Push3270();
# endif /* !defined(TN3270) */
* Select from tty and network...
send_will(TELOPT_TTYPE
, 1);
send_will(TELOPT_NAWS
, 1);
send_will(TELOPT_TSPEED
, 1);
send_will(TELOPT_LFLOW
, 1);
send_will(TELOPT_LINEMODE
, 1);
send_do(TELOPT_STATUS
, 1);
# endif /* !defined(TN3270) */
while ((schedValue
= Scheduler(0)) != 0) {
if (Scheduler(1) == -1) {
# else /* !defined(TN3270) */
while (!In3270
&& !shell_active
) {
if (Scheduler(1) == -1) {
while ((schedValue
= Scheduler(0)) != 0) {
/* If there is data waiting to go out to terminal, don't
* schedule any more data for the terminal.
if (ring_full_count(&ttyoring
)) {
if (shell_continue() == 0) {
schedValue
= DoTerminalOutput();
if (schedValue
&& (shell_active
== 0)) {
if (Scheduler(1) == -1) {
# endif /* !defined(TN3270) */
#if 0 /* XXX - this not being in is a bug */
* Return the address of the next "item" in the TELNET data
* stream. This will be the address of the next character if
* the current address is a user data character, or it will
* be the address of the character following the TELNET command
* if the current address is a TELNET IAC ("I Am a Command")
if ((*current
&0xff) != IAC
) {
switch (*(current
+1)&0xff) {
case SB
: /* loop forever looking for the SE */
register char *look
= current
+2;
if ((*look
++&0xff) == IAC
) {
if ((*look
++&0xff) == SE
) {
* We are about to do a TELNET SYNCH operation. Clear
* the path to the network.
* Things are a bit tricky since we may have sent the first
* byte or so of a previous TELNET command into the network.
* So, we have to scan the network buffer from the beginning
* until we are up to where we want to be.
* A side effect of what we do, just to keep things
* simple, is to clear the urgent data pointer. The principal
* caller should be setting the urgent data pointer AFTER calling
register char *thisitem
, *next
;
#define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \
((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))
while ((next
= nextitem(thisitem
)) <= netobuf
.send
) {
/* Now, thisitem is first before/at boundary. */
good
= netobuf
; /* where the good bytes go */
while (netoring
.add
> thisitem
) {
} while (wewant(next
) && (nfrontp
> next
));
memcpy(good
, thisitem
, length
);
thisitem
= nextitem(thisitem
);
* These routines add various telnet commands to the data stream.
ttyflush(1); /* Flush/drop output */
/* do printoption AFTER flush, otherwise the output gets tossed... */
printoption("SENT", "do", TELOPT_TM
);
printoption("SENT", "IAC", AO
);
printoption("SENT", "IAC", EL
);
printoption("SENT", "IAC", EC
);
#else /* defined(NOT43) */
#endif /* defined(NOT43) */
netclear(); /* clear the path to the network */
printoption("SENT", "IAC", DM
);
#endif /* defined(NOT43) */
if (my_want_state_is_dont(TELOPT_STATUS
)) {
printf("Remote side does not support STATUS option\n");
printf("You will not see the response unless you set \"options\"\n");
if (NETROOM() >= cp
- tmp
) {
ring_supply_data(&netoring
, tmp
, cp
-tmp
);
printsub('>', tmp
+2, cp
- tmp
- 2);
printoption("SENT", "IAC", IP
);
printoption("SENT", "IAC", BREAK
);
printoption("SENT", "IAC", ABORT
);
printoption("SENT", "IAC", SUSP
);
printoption("SENT", "IAC", xEOF
);
* Send a window size update to the remote system.
register unsigned char *cp
;
if (my_state_is_wont(TELOPT_NAWS
))
#define PUTSHORT(cp, x) { if ((*cp++ = ((x)>>8)&0xff) == IAC) *cp++ = IAC; \
if ((*cp++ = ((x))&0xff) == IAC) *cp++ = IAC; }
if (TerminalWindowSize(&rows
, &cols
) == 0) { /* Failed */
if (NETROOM() >= cp
- tmp
) {
ring_supply_data(&netoring
, tmp
, cp
-tmp
);
printsub('>', tmp
+2, cp
- tmp
- 2);
send_do(TELOPT_BINARY
, 1);
send_will(TELOPT_BINARY
, 1);
send_dont(TELOPT_BINARY
, 1);
send_wont(TELOPT_BINARY
, 1);