15 #define RLOGIN_MAX_BACKLOG 4096
17 typedef struct rlogin_tag
{
18 const struct plug_function_table
*fn
;
19 /* the above field _must_ be first in the structure */
23 int term_width
, term_height
;
27 static void rlogin_size(void *handle
, int width
, int height
);
29 static void c_write(Rlogin rlogin
, char *buf
, int len
)
31 int backlog
= from_backend(rlogin
->frontend
, 0, buf
, len
);
32 sk_set_frozen(rlogin
->s
, backlog
> RLOGIN_MAX_BACKLOG
);
35 static int rlogin_closing(Plug plug
, char *error_msg
, int error_code
,
38 Rlogin rlogin
= (Rlogin
) plug
;
44 /* A socket error has occurred. */
46 connection_fatal("%s", error_msg
);
47 } /* Otherwise, the remote side closed the connection normally. */
51 static int rlogin_receive(Plug plug
, int urgent
, char *data
, int len
)
53 Rlogin rlogin
= (Rlogin
) plug
;
60 rlogin_size(rlogin
, rlogin
->term_width
, rlogin
->term_height
);
62 * We should flush everything (aka Telnet SYNCH) if we see
63 * 0x02, and we should turn off and on _local_ flow control
64 * on 0x10 and 0x20 respectively. I'm not convinced it's
69 * Main rlogin protocol. This is really simple: the first
70 * byte is expected to be NULL and is ignored, and the rest
73 static int firstbyte
= 1;
75 if (data
[0] == '\0') {
82 c_write(rlogin
, data
, len
);
87 static void rlogin_sent(Plug plug
, int bufsize
)
89 Rlogin rlogin
= (Rlogin
) plug
;
90 rlogin
->bufsize
= bufsize
;
94 * Called to set up the rlogin connection.
96 * Returns an error message, or NULL on success.
98 * Also places the canonical host name into `realhost'. It must be
99 * freed by the caller.
101 static char *rlogin_init(void *frontend_handle
, void **backend_handle
,
102 char *host
, int port
, char **realhost
, int nodelay
)
104 static const struct plug_function_table fn_table
= {
113 rlogin
= smalloc(sizeof(*rlogin
));
114 rlogin
->fn
= &fn_table
;
116 rlogin
->frontend
= frontend_handle
;
117 rlogin
->term_width
= cfg
.width
;
118 rlogin
->term_height
= cfg
.height
;
119 *backend_handle
= rlogin
;
126 sprintf(buf
, "Looking up host \"%.170s\"", host
);
129 addr
= sk_namelookup(host
, realhost
);
130 if ((err
= sk_addr_error(addr
)))
134 port
= 513; /* default rlogin port */
140 char buf
[200], addrbuf
[100];
141 sk_getaddr(addr
, addrbuf
, 100);
142 sprintf(buf
, "Connecting to %.100s port %d", addrbuf
, port
);
145 rlogin
->s
= new_connection(addr
, *realhost
, port
, 1, 0,
146 nodelay
, (Plug
) rlogin
);
147 if ((err
= sk_socket_error(rlogin
->s
)))
153 * Send local username, remote username, terminal/speed
159 sk_write(rlogin
->s
, &z
, 1);
160 sk_write(rlogin
->s
, cfg
.localusername
, strlen(cfg
.localusername
));
161 sk_write(rlogin
->s
, &z
, 1);
162 sk_write(rlogin
->s
, cfg
.username
, strlen(cfg
.username
));
163 sk_write(rlogin
->s
, &z
, 1);
164 sk_write(rlogin
->s
, cfg
.termtype
, strlen(cfg
.termtype
));
165 sk_write(rlogin
->s
, "/", 1);
166 for (p
= cfg
.termspeed
; isdigit(*p
); p
++);
167 sk_write(rlogin
->s
, cfg
.termspeed
, p
- cfg
.termspeed
);
168 rlogin
->bufsize
= sk_write(rlogin
->s
, &z
, 1);
175 * Called to send data down the rlogin connection.
177 static int rlogin_send(void *handle
, char *buf
, int len
)
179 Rlogin rlogin
= (Rlogin
) handle
;
181 if (rlogin
->s
== NULL
)
184 rlogin
->bufsize
= sk_write(rlogin
->s
, buf
, len
);
186 return rlogin
->bufsize
;
190 * Called to query the current socket sendability status.
192 static int rlogin_sendbuffer(void *handle
)
194 Rlogin rlogin
= (Rlogin
) handle
;
195 return rlogin
->bufsize
;
199 * Called to set the size of the window
201 static void rlogin_size(void *handle
, int width
, int height
)
203 Rlogin rlogin
= (Rlogin
) handle
;
204 char b
[12] = { '\xFF', '\xFF', 0x73, 0x73, 0, 0, 0, 0, 0, 0, 0, 0 };
206 rlogin
->term_width
= width
;
207 rlogin
->term_height
= height
;
209 if (rlogin
->s
== NULL
)
212 b
[6] = rlogin
->term_width
>> 8;
213 b
[7] = rlogin
->term_width
& 0xFF;
214 b
[4] = rlogin
->term_height
>> 8;
215 b
[5] = rlogin
->term_height
& 0xFF;
216 rlogin
->bufsize
= sk_write(rlogin
->s
, b
, 12);
221 * Send rlogin special codes.
223 static void rlogin_special(void *handle
, Telnet_Special code
)
229 static Socket
rlogin_socket(void *handle
)
231 Rlogin rlogin
= (Rlogin
) handle
;
235 static int rlogin_sendok(void *handle
)
237 Rlogin rlogin
= (Rlogin
) handle
;
241 static void rlogin_unthrottle(void *handle
, int backlog
)
243 Rlogin rlogin
= (Rlogin
) handle
;
244 sk_set_frozen(rlogin
->s
, backlog
> RLOGIN_MAX_BACKLOG
);
247 static int rlogin_ldisc(void *handle
, int option
)
249 Rlogin rlogin
= (Rlogin
) handle
;
253 static int rlogin_exitcode(void *handle
)
255 Rlogin rlogin
= (Rlogin
) handle
;
256 /* If we ever implement RSH, we'll probably need to do this properly */
260 Backend rlogin_backend
= {