15 #define RLOGIN_MAX_BACKLOG 4096
17 static Socket s
= NULL
;
18 static int rlogin_bufsize
;
20 static void rlogin_size(void);
22 static void c_write(char *buf
, int len
)
24 int backlog
= from_backend(0, buf
, len
);
25 sk_set_frozen(s
, backlog
> RLOGIN_MAX_BACKLOG
);
28 static int rlogin_closing(Plug plug
, char *error_msg
, int error_code
,
36 /* A socket error has occurred. */
37 connection_fatal(error_msg
);
38 } /* Otherwise, the remote side closed the connection normally. */
42 static int rlogin_receive(Plug plug
, int urgent
, char *data
, int len
)
52 * We should flush everything (aka Telnet SYNCH) if we see
53 * 0x02, and we should turn off and on _local_ flow control
54 * on 0x10 and 0x20 respectively. I'm not convinced it's
59 * Main rlogin protocol. This is really simple: the first
60 * byte is expected to be NULL and is ignored, and the rest
63 static int firstbyte
= 1;
65 if (data
[0] == '\0') {
76 static void rlogin_sent(Plug plug
, int bufsize
)
78 rlogin_bufsize
= bufsize
;
82 * Called to set up the rlogin connection.
84 * Returns an error message, or NULL on success.
86 * Also places the canonical host name into `realhost'. It must be
87 * freed by the caller.
89 static char *rlogin_init(char *host
, int port
, char **realhost
)
91 static struct plug_function_table fn_table
= {
95 }, *fn_table_ptr
= &fn_table
;
105 sprintf(buf
, "Looking up host \"%.170s\"", host
);
108 addr
= sk_namelookup(host
, realhost
);
109 if ((err
= sk_addr_error(addr
)))
113 port
= 513; /* default rlogin port */
119 char buf
[200], addrbuf
[100];
120 sk_getaddr(addr
, addrbuf
, 100);
121 sprintf(buf
, "Connecting to %.100s port %d", addrbuf
, port
);
124 s
= sk_new(addr
, port
, 1, 0, &fn_table_ptr
);
125 if ((err
= sk_socket_error(s
)))
131 * Send local username, remote username, terminal/speed
138 sk_write(s
, cfg
.localusername
, strlen(cfg
.localusername
));
140 sk_write(s
, cfg
.username
, strlen(cfg
.username
));
142 sk_write(s
, cfg
.termtype
, strlen(cfg
.termtype
));
144 for (p
= cfg
.termspeed
; isdigit(*p
); p
++);
145 sk_write(s
, cfg
.termspeed
, p
- cfg
.termspeed
);
146 rlogin_bufsize
= sk_write(s
, &z
, 1);
153 * Called to send data down the rlogin connection.
155 static int rlogin_send(char *buf
, int len
)
160 rlogin_bufsize
= sk_write(s
, buf
, len
);
162 return rlogin_bufsize
;
166 * Called to query the current socket sendability status.
168 static int rlogin_sendbuffer(void)
170 return rlogin_bufsize
;
174 * Called to set the size of the window
176 static void rlogin_size(void)
178 char b
[12] = { '\xFF', '\xFF', 0x73, 0x73, 0, 0, 0, 0, 0, 0, 0, 0 };
187 rlogin_bufsize
= sk_write(s
, b
, 12);
192 * Send rlogin special codes.
194 static void rlogin_special(Telnet_Special code
)
200 static Socket
rlogin_socket(void)
205 static int rlogin_sendok(void)
210 static void rlogin_unthrottle(int backlog
)
212 sk_set_frozen(s
, backlog
> RLOGIN_MAX_BACKLOG
);
215 static int rlogin_ldisc(int option
)
220 Backend rlogin_backend
= {