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
222 #define TELNET_MAX_BACKLOG 4096
224 #define SB_DELTA 1024
226 static void c_write1(Telnet telnet
, int c
)
230 backlog
= from_backend(telnet
->frontend
, 0, &cc
, 1);
231 sk_set_frozen(telnet
->s
, backlog
> TELNET_MAX_BACKLOG
);
234 static void log_option(Telnet telnet
, char *sender
, int cmd
, int option
)
238 * The strange-looking "<?""?>" below is there to avoid a
239 * trigraph - a double question mark followed by > maps to a
240 * closing brace character!
242 buf
= dupprintf("%s:\t%s %s", sender
,
243 (cmd
== WILL ?
"WILL" : cmd
== WONT ?
"WONT" :
244 cmd
== DO ?
"DO" : cmd
== DONT ?
"DONT" : "<?""?>"),
246 logevent(telnet
->frontend
, buf
);
250 static void send_opt(Telnet telnet
, int cmd
, int option
)
257 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 3);
258 log_option(telnet
, "client", cmd
, option
);
261 static void deactivate_option(Telnet telnet
, const struct Opt
*o
)
263 if (telnet
->opt_states
[o
->index
] == REQUESTED
||
264 telnet
->opt_states
[o
->index
] == ACTIVE
)
265 send_opt(telnet
, o
->nsend
, o
->option
);
266 telnet
->opt_states
[o
->index
] = REALLY_INACTIVE
;
270 * Generate side effects of enabling or disabling an option.
272 static void option_side_effects(Telnet telnet
, const struct Opt
*o
, int enabled
)
274 if (o
->option
== TELOPT_ECHO
&& o
->send
== DO
)
275 telnet
->echoing
= !enabled
;
276 else if (o
->option
== TELOPT_SGA
&& o
->send
== DO
)
277 telnet
->editing
= !enabled
;
278 if (telnet
->ldisc
) /* cause ldisc to notice the change */
279 ldisc_send(telnet
->ldisc
, NULL
, 0, 0);
281 /* Ensure we get the minimum options */
282 if (!telnet
->activated
) {
283 if (telnet
->opt_states
[o_echo
.index
] == INACTIVE
) {
284 telnet
->opt_states
[o_echo
.index
] = REQUESTED
;
285 send_opt(telnet
, o_echo
.send
, o_echo
.option
);
287 if (telnet
->opt_states
[o_we_sga
.index
] == INACTIVE
) {
288 telnet
->opt_states
[o_we_sga
.index
] = REQUESTED
;
289 send_opt(telnet
, o_we_sga
.send
, o_we_sga
.option
);
291 if (telnet
->opt_states
[o_they_sga
.index
] == INACTIVE
) {
292 telnet
->opt_states
[o_they_sga
.index
] = REQUESTED
;
293 send_opt(telnet
, o_they_sga
.send
, o_they_sga
.option
);
295 telnet
->activated
= TRUE
;
299 static void activate_option(Telnet telnet
, const struct Opt
*o
)
301 if (o
->send
== WILL
&& o
->option
== TELOPT_NAWS
)
302 telnet_size(telnet
, telnet
->term_width
, telnet
->term_height
);
303 if (o
->send
== WILL
&&
304 (o
->option
== TELOPT_NEW_ENVIRON
||
305 o
->option
== TELOPT_OLD_ENVIRON
)) {
307 * We may only have one kind of ENVIRON going at a time.
308 * This is a hack, but who cares.
310 deactivate_option(telnet
, o
->option
==
311 TELOPT_NEW_ENVIRON ?
&o_oenv
: &o_nenv
);
313 option_side_effects(telnet
, o
, 1);
316 static void refused_option(Telnet telnet
, const struct Opt
*o
)
318 if (o
->send
== WILL
&& o
->option
== TELOPT_NEW_ENVIRON
&&
319 telnet
->opt_states
[o_oenv
.index
] == INACTIVE
) {
320 send_opt(telnet
, WILL
, TELOPT_OLD_ENVIRON
);
321 telnet
->opt_states
[o_oenv
.index
] = REQUESTED
;
323 option_side_effects(telnet
, o
, 0);
326 static void proc_rec_opt(Telnet telnet
, int cmd
, int option
)
328 const struct Opt
*const *o
;
330 log_option(telnet
, "server", cmd
, option
);
331 for (o
= opts
; *o
; o
++) {
332 if ((*o
)->option
== option
&& (*o
)->ack
== cmd
) {
333 switch (telnet
->opt_states
[(*o
)->index
]) {
335 telnet
->opt_states
[(*o
)->index
] = ACTIVE
;
336 activate_option(telnet
, *o
);
341 telnet
->opt_states
[(*o
)->index
] = ACTIVE
;
342 send_opt(telnet
, (*o
)->send
, option
);
343 activate_option(telnet
, *o
);
345 case REALLY_INACTIVE
:
346 send_opt(telnet
, (*o
)->nsend
, option
);
350 } else if ((*o
)->option
== option
&& (*o
)->nak
== cmd
) {
351 switch (telnet
->opt_states
[(*o
)->index
]) {
353 telnet
->opt_states
[(*o
)->index
] = INACTIVE
;
354 refused_option(telnet
, *o
);
357 telnet
->opt_states
[(*o
)->index
] = INACTIVE
;
358 send_opt(telnet
, (*o
)->nsend
, option
);
359 option_side_effects(telnet
, *o
, 0);
362 case REALLY_INACTIVE
:
369 * If we reach here, the option was one we weren't prepared to
370 * cope with. So send a negative ack.
372 send_opt(telnet
, (cmd
== WILL ? DONT
: WONT
), option
);
375 static void process_subneg(Telnet telnet
)
377 unsigned char b
[2048], *p
, *q
;
381 switch (telnet
->sb_opt
) {
383 if (telnet
->sb_len
== 1 && telnet
->sb_buf
[0] == TELQUAL_SEND
) {
387 b
[2] = TELOPT_TSPEED
;
389 strcpy((char *)(b
+ 4), cfg
.termspeed
);
390 n
= 4 + strlen(cfg
.termspeed
);
393 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, n
+ 2);
394 logevent(telnet
->frontend
, "server:\tSB TSPEED SEND");
395 logbuf
= dupprintf("client:\tSB TSPEED IS %s", cfg
.termspeed
);
396 logevent(telnet
->frontend
, logbuf
);
399 logevent(telnet
->frontend
, "server:\tSB TSPEED <something weird>");
402 if (telnet
->sb_len
== 1 && telnet
->sb_buf
[0] == TELQUAL_SEND
) {
408 for (n
= 0; cfg
.termtype
[n
]; n
++)
409 b
[n
+ 4] = (cfg
.termtype
[n
] >= 'a'
410 && cfg
.termtype
[n
] <=
411 'z' ? cfg
.termtype
[n
] + 'A' -
412 'a' : cfg
.termtype
[n
]);
415 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, n
+ 6);
417 logevent(telnet
->frontend
, "server:\tSB TTYPE SEND");
418 logbuf
= dupprintf("client:\tSB TTYPE IS %s", b
+ 4);
419 logevent(telnet
->frontend
, logbuf
);
422 logevent(telnet
->frontend
, "server:\tSB TTYPE <something weird>\r\n");
424 case TELOPT_OLD_ENVIRON
:
425 case TELOPT_NEW_ENVIRON
:
427 q
= p
+ telnet
->sb_len
;
428 if (p
< q
&& *p
== TELQUAL_SEND
) {
431 logbuf
= dupprintf("server:\tSB %s SEND", telopt(telnet
->sb_opt
));
432 logevent(telnet
->frontend
, logbuf
);
434 if (telnet
->sb_opt
== TELOPT_OLD_ENVIRON
) {
435 if (cfg
.rfc_environ
) {
443 * Try to guess the sense of VAR and VALUE.
449 } else if (*p
== BSD_VAR
) {
457 * With NEW_ENVIRON, the sense of VAR and VALUE
465 b
[2] = telnet
->sb_opt
;
471 while (*e
&& *e
!= '\t')
493 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, n
);
494 logbuf
= dupprintf("client:\tSB %s IS %s", telopt(telnet
->sb_opt
),
495 n
== 6 ?
"<nothing>" : "<stuff>");
496 logevent(telnet
->frontend
, logbuf
);
503 static void do_telnet_read(Telnet telnet
, char *buf
, int len
)
507 int c
= (unsigned char) *buf
++;
509 switch (telnet
->state
) {
512 if (c
== NUL
&& telnet
->state
== SEENCR
)
513 telnet
->state
= TOP_LEVEL
;
515 telnet
->state
= SEENIAC
;
517 if (!telnet
->in_synch
)
521 /* I can't get the F***ing winsock to insert the urgent IAC
522 * into the right position! Even with SO_OOBINLINE it gives
523 * it to recv too soon. And of course the DM byte (that
524 * arrives in the same packet!) appears several K later!!
526 * Oh well, we do get the DM in the right place so I'll
527 * just stop hiding on the next 0xf2 and hope for the best.
530 telnet
->in_synch
= 0;
532 if (c
== CR
&& telnet
->opt_states
[o_they_bin
.index
] != ACTIVE
)
533 telnet
->state
= SEENCR
;
535 telnet
->state
= TOP_LEVEL
;
540 telnet
->state
= SEENDO
;
542 telnet
->state
= SEENDONT
;
544 telnet
->state
= SEENWILL
;
546 telnet
->state
= SEENWONT
;
548 telnet
->state
= SEENSB
;
550 telnet
->in_synch
= 0;
551 telnet
->state
= TOP_LEVEL
;
553 /* ignore everything else; print it if it's IAC */
557 telnet
->state
= TOP_LEVEL
;
561 proc_rec_opt(telnet
, WILL
, c
);
562 telnet
->state
= TOP_LEVEL
;
565 proc_rec_opt(telnet
, WONT
, c
);
566 telnet
->state
= TOP_LEVEL
;
569 proc_rec_opt(telnet
, DO
, c
);
570 telnet
->state
= TOP_LEVEL
;
573 proc_rec_opt(telnet
, DONT
, c
);
574 telnet
->state
= TOP_LEVEL
;
579 telnet
->state
= SUBNEGOT
;
583 telnet
->state
= SUBNEG_IAC
;
586 if (telnet
->sb_len
>= telnet
->sb_size
) {
587 unsigned char *newbuf
;
588 telnet
->sb_size
+= SB_DELTA
;
589 newbuf
= (telnet
->sb_buf ?
590 srealloc(telnet
->sb_buf
, telnet
->sb_size
) :
591 smalloc(telnet
->sb_size
));
593 telnet
->sb_buf
= newbuf
;
595 telnet
->sb_size
-= SB_DELTA
;
597 if (telnet
->sb_len
< telnet
->sb_size
)
598 telnet
->sb_buf
[telnet
->sb_len
++] = c
;
599 telnet
->state
= SUBNEGOT
; /* in case we came here by goto */
604 goto subneg_addchar
; /* yes, it's a hack, I know, but... */
606 process_subneg(telnet
);
607 telnet
->state
= TOP_LEVEL
;
614 static int telnet_closing(Plug plug
, char *error_msg
, int error_code
,
617 Telnet telnet
= (Telnet
) plug
;
624 /* A socket error has occurred. */
625 logevent(telnet
->frontend
, error_msg
);
626 connection_fatal("%s", error_msg
);
627 } /* Otherwise, the remote side closed the connection normally. */
631 static int telnet_receive(Plug plug
, int urgent
, char *data
, int len
)
633 Telnet telnet
= (Telnet
) plug
;
635 telnet
->in_synch
= TRUE
;
636 do_telnet_read(telnet
, data
, len
);
640 static void telnet_sent(Plug plug
, int bufsize
)
642 Telnet telnet
= (Telnet
) plug
;
643 telnet
->bufsize
= bufsize
;
647 * Called to set up the Telnet connection.
649 * Returns an error message, or NULL on success.
651 * Also places the canonical host name into `realhost'. It must be
652 * freed by the caller.
654 static char *telnet_init(void *frontend_handle
, void **backend_handle
,
655 char *host
, int port
, char **realhost
, int nodelay
)
657 static const struct plug_function_table fn_table
= {
666 telnet
= smalloc(sizeof(*telnet
));
667 telnet
->fn
= &fn_table
;
669 telnet
->echoing
= TRUE
;
670 telnet
->editing
= TRUE
;
671 telnet
->activated
= FALSE
;
672 telnet
->sb_buf
= NULL
;
674 telnet
->frontend
= frontend_handle
;
675 telnet
->term_width
= cfg
.width
;
676 telnet
->term_height
= cfg
.height
;
677 telnet
->state
= TOP_LEVEL
;
678 *backend_handle
= telnet
;
685 buf
= dupprintf("Looking up host \"%s\"", host
);
686 logevent(telnet
->frontend
, buf
);
689 addr
= name_lookup(host
, port
, realhost
);
690 if ((err
= sk_addr_error(addr
)) != NULL
)
694 port
= 23; /* default telnet port */
700 char *buf
, addrbuf
[100];
701 sk_getaddr(addr
, addrbuf
, 100);
702 buf
= dupprintf("Connecting to %s port %d", addrbuf
, port
);
703 logevent(telnet
->frontend
, buf
);
706 telnet
->s
= new_connection(addr
, *realhost
, port
, 0, 1,
707 nodelay
, (Plug
) telnet
);
708 if ((err
= sk_socket_error(telnet
->s
)) != NULL
)
714 * Initialise option states.
716 if (cfg
.passive_telnet
) {
717 const struct Opt
*const *o
;
719 for (o
= opts
; *o
; o
++)
720 telnet
->opt_states
[(*o
)->index
] = INACTIVE
;
722 const struct Opt
*const *o
;
724 for (o
= opts
; *o
; o
++) {
725 telnet
->opt_states
[(*o
)->index
] = (*o
)->initial_state
;
726 if (telnet
->opt_states
[(*o
)->index
] == REQUESTED
)
727 send_opt(telnet
, (*o
)->send
, (*o
)->option
);
729 telnet
->activated
= TRUE
;
733 * Set up SYNCH state.
735 telnet
->in_synch
= FALSE
;
741 * Called to send data down the Telnet connection.
743 static int telnet_send(void *handle
, char *buf
, int len
)
745 Telnet telnet
= (Telnet
) handle
;
746 unsigned char *p
, *end
;
747 static unsigned char iac
[2] = { IAC
, IAC
};
748 static unsigned char cr
[2] = { CR
, NUL
};
750 static unsigned char nl
[2] = { CR
, LF
};
753 if (telnet
->s
== NULL
)
756 p
= (unsigned char *)buf
;
757 end
= (unsigned char *)(buf
+ len
);
759 unsigned char *q
= p
;
761 while (p
< end
&& iswritable(*p
))
763 telnet
->bufsize
= sk_write(telnet
->s
, (char *)q
, p
- q
);
765 while (p
< end
&& !iswritable(*p
)) {
767 sk_write(telnet
->s
, (char *)(*p
== IAC ? iac
: cr
), 2);
772 return telnet
->bufsize
;
776 * Called to query the current socket sendability status.
778 static int telnet_sendbuffer(void *handle
)
780 Telnet telnet
= (Telnet
) handle
;
781 return telnet
->bufsize
;
785 * Called to set the size of the window from Telnet's POV.
787 static void telnet_size(void *handle
, int width
, int height
)
789 Telnet telnet
= (Telnet
) handle
;
794 telnet
->term_width
= width
;
795 telnet
->term_height
= height
;
797 if (telnet
->s
== NULL
|| telnet
->opt_states
[o_naws
.index
] != ACTIVE
)
802 b
[n
++] = TELOPT_NAWS
;
803 b
[n
++] = telnet
->term_width
>> 8;
804 if (b
[n
-1] == IAC
) b
[n
++] = IAC
; /* duplicate any IAC byte occurs */
805 b
[n
++] = telnet
->term_width
& 0xFF;
806 if (b
[n
-1] == IAC
) b
[n
++] = IAC
; /* duplicate any IAC byte occurs */
807 b
[n
++] = telnet
->term_height
>> 8;
808 if (b
[n
-1] == IAC
) b
[n
++] = IAC
; /* duplicate any IAC byte occurs */
809 b
[n
++] = telnet
->term_height
& 0xFF;
810 if (b
[n
-1] == IAC
) b
[n
++] = IAC
; /* duplicate any IAC byte occurs */
813 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, n
);
814 logbuf
= dupprintf("client:\tSB NAWS %d,%d",
815 telnet
->term_width
, telnet
->term_height
);
816 logevent(telnet
->frontend
, logbuf
);
821 * Send Telnet special codes.
823 static void telnet_special(void *handle
, Telnet_Special code
)
825 Telnet telnet
= (Telnet
) handle
;
828 if (telnet
->s
== NULL
)
835 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
839 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
843 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
847 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
851 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
855 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
859 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
863 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
867 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
871 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
875 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
879 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
882 /* In BINARY mode, CR-LF becomes just CR. */
883 if (telnet
->opt_states
[o_we_bin
.index
] == ACTIVE
)
884 telnet
->bufsize
= sk_write(telnet
->s
, "\r", 2);
886 telnet
->bufsize
= sk_write(telnet
->s
, "\r\n", 2);
890 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 1);
891 telnet
->bufsize
= sk_write_oob(telnet
->s
, (char *)(b
+ 1), 1);
894 if (telnet
->opt_states
[o_echo
.index
] == INACTIVE
||
895 telnet
->opt_states
[o_echo
.index
] == REALLY_INACTIVE
) {
896 telnet
->opt_states
[o_echo
.index
] = REQUESTED
;
897 send_opt(telnet
, o_echo
.send
, o_echo
.option
);
901 if (telnet
->opt_states
[o_echo
.index
] == ACTIVE
) {
902 telnet
->opt_states
[o_echo
.index
] = REQUESTED
;
903 send_opt(telnet
, o_echo
.nsend
, o_echo
.option
);
907 if (telnet
->opt_states
[o_they_sga
.index
] == ACTIVE
) {
909 telnet
->bufsize
= sk_write(telnet
->s
, (char *)b
, 2);
915 static Socket
telnet_socket(void *handle
)
917 Telnet telnet
= (Telnet
) handle
;
921 static int telnet_sendok(void *handle
)
923 /* Telnet telnet = (Telnet) handle; */
927 static void telnet_unthrottle(void *handle
, int backlog
)
929 Telnet telnet
= (Telnet
) handle
;
930 sk_set_frozen(telnet
->s
, backlog
> TELNET_MAX_BACKLOG
);
933 static int telnet_ldisc(void *handle
, int option
)
935 Telnet telnet
= (Telnet
) handle
;
936 if (option
== LD_ECHO
)
937 return telnet
->echoing
;
938 if (option
== LD_EDIT
)
939 return telnet
->editing
;
943 static void telnet_provide_ldisc(void *handle
, void *ldisc
)
945 Telnet telnet
= (Telnet
) handle
;
946 telnet
->ldisc
= ldisc
;
949 static void telnet_provide_logctx(void *handle
, void *logctx
)
951 /* This is a stub. */
954 static int telnet_exitcode(void *handle
)
956 /* Telnet telnet = (Telnet) handle; */
957 /* Telnet doesn't transmit exit codes back to the client */
961 Backend telnet_backend
= {
971 telnet_provide_ldisc
,
972 telnet_provide_logctx
,