17 #define RAW_MAX_BACKLOG 4096
19 typedef struct raw_backend_data {
20 const struct plug_function_table *fn;
21 /* the above field _must_ be first in the structure */
28 static void raw_size(void *handle, int width, int height);
30 static void c_write(Raw raw, char *buf, int len)
32 int backlog = from_backend(raw->frontend, 0, buf, len);
33 sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
36 static void raw_log(Plug plug, int type, SockAddr addr, int port,
37 const char *error_msg, int error_code)
40 char addrbuf[256], *msg;
42 sk_getaddr(addr, addrbuf, lenof(addrbuf));
45 msg = dupprintf("Connecting to %s port %d", addrbuf, port);
47 msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
49 logevent(raw->frontend, msg);
52 static int raw_closing(Plug plug, const char *error_msg, int error_code,
60 notify_remote_exit(raw->frontend);
63 /* A socket error has occurred. */
64 logevent(raw->frontend, error_msg);
65 connection_fatal(raw->frontend, "%s", error_msg);
66 } /* Otherwise, the remote side closed the connection normally. */
70 static int raw_receive(Plug plug, int urgent, char *data, int len)
73 c_write(raw, data, len);
77 static void raw_sent(Plug plug, int bufsize)
80 raw->bufsize = bufsize;
84 * Called to set up the raw connection.
86 * Returns an error message, or NULL on success.
88 * Also places the canonical host name into `realhost'. It must be
89 * freed by the caller.
91 static const char *raw_init(void *frontend_handle, void **backend_handle,
93 char *host, int port, char **realhost, int nodelay,
96 static const struct plug_function_table fn_table = {
106 raw = snew(struct raw_backend_data);
109 *backend_handle = raw;
111 raw->frontend = frontend_handle;
118 buf = dupprintf("Looking up host \"%s\"%s", host,
119 (cfg->addressfamily == ADDRTYPE_IPV4 ? " (IPv4)" :
120 (cfg->addressfamily == ADDRTYPE_IPV6 ? " (IPv6)" :
122 logevent(raw->frontend, buf);
125 addr = name_lookup(host, port, realhost, cfg, cfg->addressfamily);
126 if ((err = sk_addr_error(addr)) != NULL) {
132 port = 23; /* default telnet port */
137 raw->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive,
139 if ((err = sk_socket_error(raw->s)) != NULL)
146 *realhost = dupstr(cfg->loghost);
147 colon = strrchr(*realhost, ':');
150 * FIXME: if we ever update this aspect of ssh.c for
151 * IPv6 literal management, this should change in line
161 static void raw_free(void *handle)
163 Raw raw = (Raw) handle;
171 * Stub routine (we don't have any need to reconfigure this backend).
173 static void raw_reconfig(void *handle, Config *cfg)
178 * Called to send data down the raw connection.
180 static int raw_send(void *handle, char *buf, int len)
182 Raw raw = (Raw) handle;
187 raw->bufsize = sk_write(raw->s, buf, len);
193 * Called to query the current socket sendability status.
195 static int raw_sendbuffer(void *handle)
197 Raw raw = (Raw) handle;
202 * Called to set the size of the window
204 static void raw_size(void *handle, int width, int height)
211 * Send raw special codes.
213 static void raw_special(void *handle, Telnet_Special code)
220 * Return a list of the special codes that make sense in this
223 static const struct telnet_special *raw_get_specials(void *handle)
228 static int raw_connected(void *handle)
230 Raw raw = (Raw) handle;
231 return raw->s != NULL;
234 static int raw_sendok(void *handle)
239 static void raw_unthrottle(void *handle, int backlog)
241 Raw raw = (Raw) handle;
242 sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
245 static int raw_ldisc(void *handle, int option)
247 if (option == LD_EDIT || option == LD_ECHO)
252 static void raw_provide_ldisc(void *handle, void *ldisc)
254 /* This is a stub. */
257 static void raw_provide_logctx(void *handle, void *logctx)
259 /* This is a stub. */
262 static int raw_exitcode(void *handle)
264 Raw raw = (Raw) handle;
266 return -1; /* still connected */
268 /* Exit codes are a meaningless concept in the Raw protocol */
273 * cfg_info for Raw does nothing at all.
275 static int raw_cfg_info(void *handle)
280 Backend raw_backend = {