13 #define IAC 255 /* interpret as command: */
14 #define DONT 254 /* you are not to use option */
15 #define DO 253 /* please, you use option */
16 #define WONT 252 /* I won't use option */
17 #define WILL 251 /* I will use option */
18 #define SB 250 /* interpret as subnegotiation */
19 #define SE 240 /* end sub negotiation */
21 #define GA 249 /* you may reverse the line */
22 #define EL 248 /* erase the current line */
23 #define EC 247 /* erase the current character */
24 #define AYT 246 /* are you there */
25 #define AO 245 /* abort output--but let prog finish */
26 #define IP 244 /* interrupt process--permanently */
27 #define BREAK 243 /* break */
28 #define DM 242 /* data mark--for connect. cleaning */
29 #define NOP 241 /* nop */
30 #define EOR 239 /* end of record (transparent mode) */
31 #define ABORT 238 /* Abort process */
32 #define SUSP 237 /* Suspend process */
33 #define xEOF 236 /* End of file: EOF is already used... */
35 #define TELOPT_BINARY 0 /* 8-bit data path */
36 #define TELOPT_ECHO 1 /* echo */
37 #define TELOPT_RCP 2 /* prepare to reconnect */
38 #define TELOPT_SGA 3 /* suppress go ahead */
39 #define TELOPT_NAMS 4 /* approximate message size */
40 #define TELOPT_STATUS 5 /* give status */
41 #define TELOPT_TM 6 /* timing mark */
42 #define TELOPT_RCTE 7 /* remote controlled transmission and echo */
43 #define TELOPT_NAOL 8 /* negotiate about output line width */
44 #define TELOPT_NAOP 9 /* negotiate about output page size */
45 #define TELOPT_NAOCRD 10 /* negotiate about CR disposition */
46 #define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */
47 #define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */
48 #define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */
49 #define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */
50 #define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */
51 #define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */
52 #define TELOPT_XASCII 17 /* extended ascic character set */
53 #define TELOPT_LOGOUT 18 /* force logout */
54 #define TELOPT_BM 19 /* byte macro */
55 #define TELOPT_DET 20 /* data entry terminal */
56 #define TELOPT_SUPDUP 21 /* supdup protocol */
57 #define TELOPT_SUPDUPOUTPUT 22 /* supdup output */
58 #define TELOPT_SNDLOC 23 /* send location */
59 #define TELOPT_TTYPE 24 /* terminal type */
60 #define TELOPT_EOR 25 /* end or record */
61 #define TELOPT_TUID 26 /* TACACS user identification */
62 #define TELOPT_OUTMRK 27 /* output marking */
63 #define TELOPT_TTYLOC 28 /* terminal location number */
64 #define TELOPT_3270REGIME 29 /* 3270 regime */
65 #define TELOPT_X3PAD 30 /* X.3 PAD */
66 #define TELOPT_NAWS 31 /* window size */
67 #define TELOPT_TSPEED 32 /* terminal speed */
68 #define TELOPT_LFLOW 33 /* remote flow control */
69 #define TELOPT_LINEMODE 34 /* Linemode option */
70 #define TELOPT_XDISPLOC 35 /* X Display Location */
71 #define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */
72 #define TELOPT_AUTHENTICATION 37 /* Authenticate */
73 #define TELOPT_ENCRYPT 38 /* Encryption option */
74 #define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */
75 #define TELOPT_EXOPL 255 /* extended-options-list */
77 #define TELQUAL_IS 0 /* option is... */
78 #define TELQUAL_SEND 1 /* send option */
79 #define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */
89 #define iswritable(x) \
91 (telnet->opt_states[o_we_bin.index] == ACTIVE || (x) != CR))
93 static char *telopt(int opt
)
95 #define i(x) if (opt == TELOPT_ ## x) return #x;
140 static void telnet_size(void *handle
, int width
, int height
);
143 int send
; /* what we initially send */
144 int nsend
; /* -ve send if requested to stop it */
145 int ack
, nak
; /* +ve and -ve acknowledgements */
146 int option
; /* the option code */
147 int index
; /* index into telnet->opt_states[] */
149 REQUESTED
, ACTIVE
, INACTIVE
, REALLY_INACTIVE
167 static const struct Opt o_naws
=
168 { WILL
, WONT
, DO
, DONT
, TELOPT_NAWS
, OPTINDEX_NAWS
, REQUESTED
};
169 static const struct Opt o_tspeed
=
170 { WILL
, WONT
, DO
, DONT
, TELOPT_TSPEED
, OPTINDEX_TSPEED
, REQUESTED
};
171 static const struct Opt o_ttype
=
172 { WILL
, WONT
, DO
, DONT
, TELOPT_TTYPE
, OPTINDEX_TTYPE
, REQUESTED
};
173 static const struct Opt o_oenv
= { WILL
, WONT
, DO
, DONT
, TELOPT_OLD_ENVIRON
,
174 OPTINDEX_OENV
, INACTIVE
176 static const struct Opt o_nenv
= { WILL
, WONT
, DO
, DONT
, TELOPT_NEW_ENVIRON
,
177 OPTINDEX_NENV
, REQUESTED
179 static const struct Opt o_echo
=
180 { DO
, DONT
, WILL
, WONT
, TELOPT_ECHO
, OPTINDEX_ECHO
, REQUESTED
};
181 static const struct Opt o_we_sga
=
182 { WILL
, WONT
, DO
, DONT
, TELOPT_SGA
, OPTINDEX_WE_SGA
, REQUESTED
};
183 static const struct Opt o_they_sga
=
184 { DO
, DONT
, WILL
, WONT
, TELOPT_SGA
, OPTINDEX_THEY_SGA
, REQUESTED
};
185 static const struct Opt o_we_bin
=
186 { WILL
, WONT
, DO
, DONT
, TELOPT_BINARY
, OPTINDEX_WE_BIN
, INACTIVE
};
187 static const struct Opt o_they_bin
=
188 { DO
, DONT
, WILL
, WONT
, TELOPT_BINARY
, OPTINDEX_THEY_BIN
, INACTIVE
};
190 static const struct Opt
*const opts
[] = {
191 &o_naws
, &o_tspeed
, &o_ttype
, &o_oenv
, &o_nenv
, &o_echo
,
192 &o_we_sga
, &o_they_sga
, &o_we_bin
, &o_they_bin
, NULL
195 typedef struct telnet_tag
{
196 const struct plug_function_table
*fn
;
197 /* the above field _must_ be first in the structure */
203 int term_width
, term_height
;
205 int opt_states
[NUM_OPTS
];
207 int echoing
, editing
;
212 unsigned char *sb_buf
;
216 TOP_LEVEL
, SEENIAC
, SEENWILL
, SEENWONT
, SEENDO
, SEENDONT
,
217 SEENSB
, SUBNEGOT
, SUBNEG_IAC
, SEENCR
223 #define TELNET_MAX_BACKLOG 4096
225 #define SB_DELTA 1024
227 static void c_write1(Telnet telnet
, int c
)
231 backlog
= from_backend(telnet
->frontend
, 0, &cc
, 1);
232 sk_set_frozen(telnet
->s
, backlog
> TELNET_MAX_BACKLOG
);
235 static void log_option(Telnet telnet
, char *sender
, int cmd
, int option
)
239 * The strange-looking "<?""?>" below is there to avoid a
240 * trigraph - a double question mark followed by > maps to a
241 * closing brace character!
243 buf
= dupprintf("%s:\t%s %s", sender
,
244 (cmd
== WILL ?
"WILL" : cmd
== WONT ?
"WONT" :
245 cmd
== DO ?
"DO" : cmd
== DONT ?
"DONT" : "<?""?>"),
247 logevent(telnet
->frontend
, buf
);
251 static void send_opt(Telnet telnet
, int cmd
, int option
)
258 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 3);
259 log_option(telnet
, "client", cmd
, option
);
262 static void deactivate_option(Telnet telnet
, const struct Opt
*o
)
264 if (telnet
->opt_states
[o
->index
] == REQUESTED
||
265 telnet
->opt_states
[o
->index
] == ACTIVE
)
266 send_opt(telnet
, o
->nsend
, o
->option
);
267 telnet
->opt_states
[o
->index
] = REALLY_INACTIVE
;
271 * Generate side effects of enabling or disabling an option.
273 static void option_side_effects(Telnet telnet
, const struct Opt
*o
, int enabled
)
275 if (o
->option
== TELOPT_ECHO
&& o
->send
== DO
)
276 telnet
->echoing
= !enabled
;
277 else if (o
->option
== TELOPT_SGA
&& o
->send
== DO
)
278 telnet
->editing
= !enabled
;
279 if (telnet
->ldisc
) /* cause ldisc to notice the change */
280 ldisc_send(telnet
->ldisc
, NULL
, 0, 0);
282 /* Ensure we get the minimum options */
283 if (!telnet
->activated
) {
284 if (telnet
->opt_states
[o_echo
.index
] == INACTIVE
) {
285 telnet
->opt_states
[o_echo
.index
] = REQUESTED
;
286 send_opt(telnet
, o_echo
.send
, o_echo
.option
);
288 if (telnet
->opt_states
[o_we_sga
.index
] == INACTIVE
) {
289 telnet
->opt_states
[o_we_sga
.index
] = REQUESTED
;
290 send_opt(telnet
, o_we_sga
.send
, o_we_sga
.option
);
292 if (telnet
->opt_states
[o_they_sga
.index
] == INACTIVE
) {
293 telnet
->opt_states
[o_they_sga
.index
] = REQUESTED
;
294 send_opt(telnet
, o_they_sga
.send
, o_they_sga
.option
);
296 telnet
->activated
= TRUE
;
300 static void activate_option(Telnet telnet
, const struct Opt
*o
)
302 if (o
->send
== WILL
&& o
->option
== TELOPT_NAWS
)
303 telnet_size(telnet
, telnet
->term_width
, telnet
->term_height
);
304 if (o
->send
== WILL
&&
305 (o
->option
== TELOPT_NEW_ENVIRON
||
306 o
->option
== TELOPT_OLD_ENVIRON
)) {
308 * We may only have one kind of ENVIRON going at a time.
309 * This is a hack, but who cares.
311 deactivate_option(telnet
, o
->option
==
312 TELOPT_NEW_ENVIRON ?
&o_oenv
: &o_nenv
);
314 option_side_effects(telnet
, o
, 1);
317 static void refused_option(Telnet telnet
, const struct Opt
*o
)
319 if (o
->send
== WILL
&& o
->option
== TELOPT_NEW_ENVIRON
&&
320 telnet
->opt_states
[o_oenv
.index
] == INACTIVE
) {
321 send_opt(telnet
, WILL
, TELOPT_OLD_ENVIRON
);
322 telnet
->opt_states
[o_oenv
.index
] = REQUESTED
;
324 option_side_effects(telnet
, o
, 0);
327 static void proc_rec_opt(Telnet telnet
, int cmd
, int option
)
329 const struct Opt
*const *o
;
331 log_option(telnet
, "server", cmd
, option
);
332 for (o
= opts
; *o
; o
++) {
333 if ((*o
)->option
== option
&& (*o
)->ack
== cmd
) {
334 switch (telnet
->opt_states
[(*o
)->index
]) {
336 telnet
->opt_states
[(*o
)->index
] = ACTIVE
;
337 activate_option(telnet
, *o
);
342 telnet
->opt_states
[(*o
)->index
] = ACTIVE
;
343 send_opt(telnet
, (*o
)->send
, option
);
344 activate_option(telnet
, *o
);
346 case REALLY_INACTIVE
:
347 send_opt(telnet
, (*o
)->nsend
, option
);
351 } else if ((*o
)->option
== option
&& (*o
)->nak
== cmd
) {
352 switch (telnet
->opt_states
[(*o
)->index
]) {
354 telnet
->opt_states
[(*o
)->index
] = INACTIVE
;
355 refused_option(telnet
, *o
);
358 telnet
->opt_states
[(*o
)->index
] = INACTIVE
;
359 send_opt(telnet
, (*o
)->nsend
, option
);
360 option_side_effects(telnet
, *o
, 0);
363 case REALLY_INACTIVE
:
370 * If we reach here, the option was one we weren't prepared to
371 * cope with. So send a negative ack.
373 send_opt(telnet
, (cmd
== WILL ? DONT
: WONT
), option
);
376 static void process_subneg(Telnet telnet
)
378 unsigned char b
[2048], *p
, *q
;
382 switch (telnet
->sb_opt
) {
384 if (telnet
->sb_len
== 1 && telnet
->sb_buf
[0] == TELQUAL_SEND
) {
388 b
[2] = TELOPT_TSPEED
;
390 strcpy((char *)(b
+ 4), telnet
->cfg
.termspeed
);
391 n
= 4 + strlen(telnet
->cfg
.termspeed
);
394 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, n
+ 2);
395 logevent(telnet
->frontend
, "server:\tSB TSPEED SEND");
396 logbuf
= dupprintf("client:\tSB TSPEED IS %s", telnet
->cfg
.termspeed
);
397 logevent(telnet
->frontend
, logbuf
);
400 logevent(telnet
->frontend
, "server:\tSB TSPEED <something weird>");
403 if (telnet
->sb_len
== 1 && telnet
->sb_buf
[0] == TELQUAL_SEND
) {
409 for (n
= 0; telnet
->cfg
.termtype
[n
]; n
++)
410 b
[n
+ 4] = (telnet
->cfg
.termtype
[n
] >= 'a'
411 && telnet
->cfg
.termtype
[n
] <=
412 'z' ? telnet
->cfg
.termtype
[n
] + 'A' -
413 'a' : telnet
->cfg
.termtype
[n
]);
416 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, n
+ 6);
418 logevent(telnet
->frontend
, "server:\tSB TTYPE SEND");
419 logbuf
= dupprintf("client:\tSB TTYPE IS %s", b
+ 4);
420 logevent(telnet
->frontend
, logbuf
);
423 logevent(telnet
->frontend
, "server:\tSB TTYPE <something weird>\r\n");
425 case TELOPT_OLD_ENVIRON
:
426 case TELOPT_NEW_ENVIRON
:
428 q
= p
+ telnet
->sb_len
;
429 if (p
< q
&& *p
== TELQUAL_SEND
) {
432 logbuf
= dupprintf("server:\tSB %s SEND", telopt(telnet
->sb_opt
));
433 logevent(telnet
->frontend
, logbuf
);
435 if (telnet
->sb_opt
== TELOPT_OLD_ENVIRON
) {
436 if (telnet
->cfg
.rfc_environ
) {
444 * Try to guess the sense of VAR and VALUE.
450 } else if (*p
== BSD_VAR
) {
458 * With NEW_ENVIRON, the sense of VAR and VALUE
466 b
[2] = telnet
->sb_opt
;
469 e
= telnet
->cfg
.environmt
;
472 while (*e
&& *e
!= '\t')
481 if (*telnet
->cfg
.username
) {
488 e
= telnet
->cfg
.username
;
494 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, n
);
495 logbuf
= dupprintf("client:\tSB %s IS %s", telopt(telnet
->sb_opt
),
496 n
== 6 ?
"<nothing>" : "<stuff>");
497 logevent(telnet
->frontend
, logbuf
);
504 static void do_telnet_read(Telnet telnet
, char *buf
, int len
)
508 int c
= (unsigned char) *buf
++;
510 switch (telnet
->state
) {
513 if (c
== NUL
&& telnet
->state
== SEENCR
)
514 telnet
->state
= TOP_LEVEL
;
516 telnet
->state
= SEENIAC
;
518 if (!telnet
->in_synch
)
522 /* I can't get the F***ing winsock to insert the urgent IAC
523 * into the right position! Even with SO_OOBINLINE it gives
524 * it to recv too soon. And of course the DM byte (that
525 * arrives in the same packet!) appears several K later!!
527 * Oh well, we do get the DM in the right place so I'll
528 * just stop hiding on the next 0xf2 and hope for the best.
531 telnet
->in_synch
= 0;
533 if (c
== CR
&& telnet
->opt_states
[o_they_bin
.index
] != ACTIVE
)
534 telnet
->state
= SEENCR
;
536 telnet
->state
= TOP_LEVEL
;
541 telnet
->state
= SEENDO
;
543 telnet
->state
= SEENDONT
;
545 telnet
->state
= SEENWILL
;
547 telnet
->state
= SEENWONT
;
549 telnet
->state
= SEENSB
;
551 telnet
->in_synch
= 0;
552 telnet
->state
= TOP_LEVEL
;
554 /* ignore everything else; print it if it's IAC */
558 telnet
->state
= TOP_LEVEL
;
562 proc_rec_opt(telnet
, WILL
, c
);
563 telnet
->state
= TOP_LEVEL
;
566 proc_rec_opt(telnet
, WONT
, c
);
567 telnet
->state
= TOP_LEVEL
;
570 proc_rec_opt(telnet
, DO
, c
);
571 telnet
->state
= TOP_LEVEL
;
574 proc_rec_opt(telnet
, DONT
, c
);
575 telnet
->state
= TOP_LEVEL
;
580 telnet
->state
= SUBNEGOT
;
584 telnet
->state
= SUBNEG_IAC
;
587 if (telnet
->sb_len
>= telnet
->sb_size
) {
588 unsigned char *newbuf
;
589 telnet
->sb_size
+= SB_DELTA
;
590 newbuf
= (telnet
->sb_buf ?
591 srealloc(telnet
->sb_buf
, telnet
->sb_size
) :
592 smalloc(telnet
->sb_size
));
594 telnet
->sb_buf
= newbuf
;
596 telnet
->sb_size
-= SB_DELTA
;
598 if (telnet
->sb_len
< telnet
->sb_size
)
599 telnet
->sb_buf
[telnet
->sb_len
++] = c
;
600 telnet
->state
= SUBNEGOT
; /* in case we came here by goto */
605 goto subneg_addchar
; /* yes, it's a hack, I know, but... */
607 process_subneg(telnet
);
608 telnet
->state
= TOP_LEVEL
;
615 static int telnet_closing(Plug plug
, char *error_msg
, int error_code
,
618 Telnet telnet
= (Telnet
) plug
;
625 /* A socket error has occurred. */
626 logevent(telnet
->frontend
, error_msg
);
627 connection_fatal("%s", error_msg
);
628 } /* Otherwise, the remote side closed the connection normally. */
632 static int telnet_receive(Plug plug
, int urgent
, char *data
, int len
)
634 Telnet telnet
= (Telnet
) plug
;
636 telnet
->in_synch
= TRUE
;
637 do_telnet_read(telnet
, data
, len
);
641 static void telnet_sent(Plug plug
, int bufsize
)
643 Telnet telnet
= (Telnet
) plug
;
644 telnet
->bufsize
= bufsize
;
648 * Called to set up the Telnet connection.
650 * Returns an error message, or NULL on success.
652 * Also places the canonical host name into `realhost'. It must be
653 * freed by the caller.
655 static char *telnet_init(void *frontend_handle
, void **backend_handle
,
657 char *host
, int port
, char **realhost
, int nodelay
)
659 static const struct plug_function_table fn_table
= {
668 telnet
= smalloc(sizeof(*telnet
));
669 telnet
->fn
= &fn_table
;
670 telnet
->cfg
= *cfg
; /* STRUCTURE COPY */
672 telnet
->echoing
= TRUE
;
673 telnet
->editing
= TRUE
;
674 telnet
->activated
= FALSE
;
675 telnet
->sb_buf
= NULL
;
677 telnet
->frontend
= frontend_handle
;
678 telnet
->term_width
= telnet
->cfg
.width
;
679 telnet
->term_height
= telnet
->cfg
.height
;
680 telnet
->state
= TOP_LEVEL
;
681 *backend_handle
= telnet
;
688 buf
= dupprintf("Looking up host \"%s\"", host
);
689 logevent(telnet
->frontend
, buf
);
692 addr
= name_lookup(host
, port
, realhost
, &telnet
->cfg
);
693 if ((err
= sk_addr_error(addr
)) != NULL
)
697 port
= 23; /* default telnet port */
703 char *buf
, addrbuf
[100];
704 sk_getaddr(addr
, addrbuf
, 100);
705 buf
= dupprintf("Connecting to %s port %d", addrbuf
, port
);
706 logevent(telnet
->frontend
, buf
);
709 telnet
->s
= new_connection(addr
, *realhost
, port
, 0, 1,
710 nodelay
, (Plug
) telnet
, &telnet
->cfg
);
711 if ((err
= sk_socket_error(telnet
->s
)) != NULL
)
717 * Initialise option states.
719 if (telnet
->cfg
.passive_telnet
) {
720 const struct Opt
*const *o
;
722 for (o
= opts
; *o
; o
++)
723 telnet
->opt_states
[(*o
)->index
] = INACTIVE
;
725 const struct Opt
*const *o
;
727 for (o
= opts
; *o
; o
++) {
728 telnet
->opt_states
[(*o
)->index
] = (*o
)->initial_state
;
729 if (telnet
->opt_states
[(*o
)->index
] == REQUESTED
)
730 send_opt(telnet
, (*o
)->send
, (*o
)->option
);
732 telnet
->activated
= TRUE
;
736 * Set up SYNCH state.
738 telnet
->in_synch
= FALSE
;
743 static void telnet_free(void *handle
)
745 Telnet telnet
= (Telnet
) handle
;
747 sfree(telnet
->sb_buf
);
753 * Reconfigure the Telnet backend. There's no immediate action
754 * necessary, in this backend: we just save the fresh config for
755 * any subsequent negotiations.
757 static void telnet_reconfig(void *handle
, Config
*cfg
)
759 Telnet telnet
= (Telnet
) handle
;
760 telnet
->cfg
= *cfg
; /* STRUCTURE COPY */
764 * Called to send data down the Telnet connection.
766 static int telnet_send(void *handle
, char *buf
, int len
)
768 Telnet telnet
= (Telnet
) handle
;
769 unsigned char *p
, *end
;
770 static const unsigned char iac
[2] = { IAC
, IAC
};
771 static const unsigned char cr
[2] = { CR
, NUL
};
773 static const unsigned char nl
[2] = { CR
, LF
};
776 if (telnet
->s
== NULL
)
779 p
= (unsigned char *)buf
;
780 end
= (unsigned char *)(buf
+ len
);
782 unsigned char *q
= p
;
784 while (p
< end
&& iswritable(*p
))
786 telnet
->bufsize
= sk_write(telnet
->s
, (char *)q
, p
- q
);
788 while (p
< end
&& !iswritable(*p
)) {
790 sk_write(telnet
->s
, (char *)(*p
== IAC ? iac
: cr
), 2);
795 return telnet
->bufsize
;
799 * Called to query the current socket sendability status.
801 static int telnet_sendbuffer(void *handle
)
803 Telnet telnet
= (Telnet
) handle
;
804 return telnet
->bufsize
;
808 * Called to set the size of the window from Telnet's POV.
810 static void telnet_size(void *handle
, int width
, int height
)
812 Telnet telnet
= (Telnet
) handle
;
817 telnet
->term_width
= width
;
818 telnet
->term_height
= height
;
820 if (telnet
->s
== NULL
|| telnet
->opt_states
[o_naws
.index
] != ACTIVE
)
825 b
[n
++] = TELOPT_NAWS
;
826 b
[n
++] = telnet
->term_width
>> 8;
827 if (b
[n
-1] == IAC
) b
[n
++] = IAC
; /* duplicate any IAC byte occurs */
828 b
[n
++] = telnet
->term_width
& 0xFF;
829 if (b
[n
-1] == IAC
) b
[n
++] = IAC
; /* duplicate any IAC byte occurs */
830 b
[n
++] = telnet
->term_height
>> 8;
831 if (b
[n
-1] == IAC
) b
[n
++] = IAC
; /* duplicate any IAC byte occurs */
832 b
[n
++] = telnet
->term_height
& 0xFF;
833 if (b
[n
-1] == IAC
) b
[n
++] = IAC
; /* duplicate any IAC byte occurs */
836 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, n
);
837 logbuf
= dupprintf("client:\tSB NAWS %d,%d",
838 telnet
->term_width
, telnet
->term_height
);
839 logevent(telnet
->frontend
, logbuf
);
844 * Send Telnet special codes.
846 static void telnet_special(void *handle
, Telnet_Special code
)
848 Telnet telnet
= (Telnet
) handle
;
851 if (telnet
->s
== NULL
)
858 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
862 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
866 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
870 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
874 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
878 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
882 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
886 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
890 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
894 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
898 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
902 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
905 /* In BINARY mode, CR-LF becomes just CR. */
906 if (telnet
->opt_states
[o_we_bin
.index
] == ACTIVE
)
907 telnet
->bufsize
= sk_write(telnet
->s
, "\r", 2);
909 telnet
->bufsize
= sk_write(telnet
->s
, "\r\n", 2);
913 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 1);
914 telnet
->bufsize
= sk_write_oob(telnet
->s
, (char *)(b
+ 1), 1);
917 if (telnet
->opt_states
[o_echo
.index
] == INACTIVE
||
918 telnet
->opt_states
[o_echo
.index
] == REALLY_INACTIVE
) {
919 telnet
->opt_states
[o_echo
.index
] = REQUESTED
;
920 send_opt(telnet
, o_echo
.send
, o_echo
.option
);
924 if (telnet
->opt_states
[o_echo
.index
] == ACTIVE
) {
925 telnet
->opt_states
[o_echo
.index
] = REQUESTED
;
926 send_opt(telnet
, o_echo
.nsend
, o_echo
.option
);
930 if (telnet
->opt_states
[o_they_sga
.index
] == ACTIVE
) {
932 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
938 static Socket
telnet_socket(void *handle
)
940 Telnet telnet
= (Telnet
) handle
;
944 static int telnet_sendok(void *handle
)
946 /* Telnet telnet = (Telnet) handle; */
950 static void telnet_unthrottle(void *handle
, int backlog
)
952 Telnet telnet
= (Telnet
) handle
;
953 sk_set_frozen(telnet
->s
, backlog
> TELNET_MAX_BACKLOG
);
956 static int telnet_ldisc(void *handle
, int option
)
958 Telnet telnet
= (Telnet
) handle
;
959 if (option
== LD_ECHO
)
960 return telnet
->echoing
;
961 if (option
== LD_EDIT
)
962 return telnet
->editing
;
966 static void telnet_provide_ldisc(void *handle
, void *ldisc
)
968 Telnet telnet
= (Telnet
) handle
;
969 telnet
->ldisc
= ldisc
;
972 static void telnet_provide_logctx(void *handle
, void *logctx
)
974 /* This is a stub. */
977 static int telnet_exitcode(void *handle
)
979 /* Telnet telnet = (Telnet) handle; */
980 /* Telnet doesn't transmit exit codes back to the client */
984 Backend telnet_backend
= {
996 telnet_provide_ldisc
,
997 telnet_provide_logctx
,