15 #define RLOGIN_MAX_BACKLOG 4096
17 static Socket s = NULL;
18 static int rlogin_bufsize;
19 static int rlogin_term_width, rlogin_term_height;
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;
106 rlogin_term_width = cfg.width;
107 rlogin_term_height = cfg.height;
114 sprintf(buf, "Looking up host \"%.170s\"", host);
117 addr = sk_namelookup(host, realhost);
118 if ((err = sk_addr_error(addr)))
122 port = 513; /* default rlogin port */
128 char buf[200], addrbuf[100];
129 sk_getaddr(addr, addrbuf, 100);
130 sprintf(buf, "Connecting to %.100s port %d", addrbuf, port);
133 s = new_connection(addr, *realhost, port, 1, 0, nodelay, &fn_table_ptr);
134 if ((err = sk_socket_error(s)))
140 * Send local username, remote username, terminal/speed
147 sk_write(s, cfg.localusername, strlen(cfg.localusername));
149 sk_write(s, cfg.username, strlen(cfg.username));
151 sk_write(s, cfg.termtype, strlen(cfg.termtype));
153 for (p = cfg.termspeed; isdigit(*p); p++);
154 sk_write(s, cfg.termspeed, p - cfg.termspeed);
155 rlogin_bufsize = sk_write(s, &z, 1);
162 * Called to send data down the rlogin connection.
164 static int rlogin_send(char *buf, int len)
169 rlogin_bufsize = sk_write(s, buf, len);
171 return rlogin_bufsize;
175 * Called to query the current socket sendability status.
177 static int rlogin_sendbuffer(void)
179 return rlogin_bufsize;
183 * Called to set the size of the window
185 static void rlogin_size(int width, int height)
187 char b[12] = { '\xFF', '\xFF', 0x73, 0x73, 0, 0, 0, 0, 0, 0, 0, 0 };
189 rlogin_term_width = width;
190 rlogin_term_height = height;
195 b[6] = rlogin_term_width >> 8;
196 b[7] = rlogin_term_width & 0xFF;
197 b[4] = rlogin_term_height >> 8;
198 b[5] = rlogin_term_height & 0xFF;
199 rlogin_bufsize = sk_write(s, b, 12);
204 * Send rlogin special codes.
206 static void rlogin_special(Telnet_Special code)
212 static Socket rlogin_socket(void)
217 static int rlogin_sendok(void)
222 static void rlogin_unthrottle(int backlog)
224 sk_set_frozen(s, backlog > RLOGIN_MAX_BACKLOG);
227 static int rlogin_ldisc(int option)
232 static int rlogin_exitcode(void)
234 /* If we ever implement RSH, we'll probably need to do this properly */
238 Backend rlogin_backend = {