16 #define RLOGIN_MAX_BACKLOG 4096
18 static Socket s
= NULL
;
19 static int rlogin_bufsize
;
20 static void *frontend
;
22 static void rlogin_size(void);
24 static void c_write(char *buf
, int len
)
26 int backlog
= from_backend(frontend
, 0, buf
, len
);
27 sk_set_frozen(s
, backlog
> RLOGIN_MAX_BACKLOG
);
30 static int rlogin_closing(Plug plug
, char *error_msg
, int error_code
,
38 /* A socket error has occurred. */
40 connection_fatal("%s", error_msg
);
41 } /* Otherwise, the remote side closed the connection normally. */
45 static int rlogin_receive(Plug plug
, int urgent
, char *data
, int len
)
55 * We should flush everything (aka Telnet SYNCH) if we see
56 * 0x02, and we should turn off and on _local_ flow control
57 * on 0x10 and 0x20 respectively. I'm not convinced it's
62 * Main rlogin protocol. This is really simple: the first
63 * byte is expected to be NULL and is ignored, and the rest
66 static int firstbyte
= 1;
68 if (data
[0] == '\0') {
80 static void rlogin_sent(Plug plug
, int bufsize
)
82 rlogin_bufsize
= bufsize
;
86 * Called to set up the rlogin connection.
88 * Returns an error message, or NULL on success.
90 * Also places the canonical host name into `realhost'. It must be
91 * freed by the caller.
93 static char *rlogin_init(void *frontend_handle
,
94 char *host
, int port
, char **realhost
, int nodelay
)
96 static struct plug_function_table fn_table
= {
100 }, *fn_table_ptr
= &fn_table
;
105 frontend
= frontend_handle
;
112 sprintf(buf
, "Looking up host \"%.170s\"", host
);
115 addr
= sk_namelookup(host
, realhost
);
116 if ((err
= sk_addr_error(addr
)))
120 port
= 513; /* default rlogin port */
126 char buf
[200], addrbuf
[100];
127 sk_getaddr(addr
, addrbuf
, 100);
128 sprintf(buf
, "Connecting to %.100s port %d", addrbuf
, port
);
131 s
= new_connection(addr
, *realhost
, port
, 1, 0, nodelay
, &fn_table_ptr
);
132 if ((err
= sk_socket_error(s
)))
138 * Send local username, remote username, terminal/speed
145 sk_write(s
, cfg
.localusername
, strlen(cfg
.localusername
));
147 sk_write(s
, cfg
.username
, strlen(cfg
.username
));
149 sk_write(s
, cfg
.termtype
, strlen(cfg
.termtype
));
151 for (p
= cfg
.termspeed
; isdigit(*p
); p
++);
152 sk_write(s
, cfg
.termspeed
, p
- cfg
.termspeed
);
153 rlogin_bufsize
= sk_write(s
, &z
, 1);
160 * Called to send data down the rlogin connection.
162 static int rlogin_send(char *buf
, int len
)
167 rlogin_bufsize
= sk_write(s
, buf
, len
);
169 return rlogin_bufsize
;
173 * Called to query the current socket sendability status.
175 static int rlogin_sendbuffer(void)
177 return rlogin_bufsize
;
181 * Called to set the size of the window
183 static void rlogin_size(void)
185 char b
[12] = { '\xFF', '\xFF', 0x73, 0x73, 0, 0, 0, 0, 0, 0, 0, 0 };
187 if (s
== NULL
|| term
== NULL
)
190 b
[6] = term
->cols
>> 8;
191 b
[7] = term
->cols
& 0xFF;
192 b
[4] = term
->rows
>> 8;
193 b
[5] = term
->rows
& 0xFF;
194 rlogin_bufsize
= sk_write(s
, b
, 12);
199 * Send rlogin special codes.
201 static void rlogin_special(Telnet_Special code
)
207 static Socket
rlogin_socket(void)
212 static int rlogin_sendok(void)
217 static void rlogin_unthrottle(int backlog
)
219 sk_set_frozen(s
, backlog
> RLOGIN_MAX_BACKLOG
);
222 static int rlogin_ldisc(int option
)
227 static int rlogin_exitcode(void)
229 /* If we ever implement RSH, we'll probably need to do this properly */
233 Backend rlogin_backend
= {