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
= {
108 raw
= snew(struct raw_backend_data
);
111 *backend_handle
= raw
;
113 raw
->frontend
= frontend_handle
;
115 addressfamily
= conf_get_int(conf
, CONF_addressfamily
);
121 buf
= dupprintf("Looking up host \"%s\"%s", host
,
122 (addressfamily
== ADDRTYPE_IPV4 ?
" (IPv4)" :
123 (addressfamily
== ADDRTYPE_IPV6 ?
" (IPv6)" :
125 logevent(raw
->frontend
, buf
);
128 addr
= name_lookup(host
, port
, realhost
, conf
, addressfamily
);
129 if ((err
= sk_addr_error(addr
)) != NULL
) {
135 port
= 23; /* default telnet port */
140 raw
->s
= new_connection(addr
, *realhost
, port
, 0, 1, nodelay
, keepalive
,
142 if ((err
= sk_socket_error(raw
->s
)) != NULL
)
145 loghost
= conf_get_str(conf
, CONF_loghost
);
150 *realhost
= dupstr(loghost
);
151 colon
= strrchr(*realhost
, ':');
154 * FIXME: if we ever update this aspect of ssh.c for
155 * IPv6 literal management, this should change in line
165 static void raw_free(void *handle
)
167 Raw raw
= (Raw
) handle
;
175 * Stub routine (we don't have any need to reconfigure this backend).
177 static void raw_reconfig(void *handle
, Conf
*conf
)
182 * Called to send data down the raw connection.
184 static int raw_send(void *handle
, char *buf
, int len
)
186 Raw raw
= (Raw
) handle
;
191 raw
->bufsize
= sk_write(raw
->s
, buf
, len
);
197 * Called to query the current socket sendability status.
199 static int raw_sendbuffer(void *handle
)
201 Raw raw
= (Raw
) handle
;
206 * Called to set the size of the window
208 static void raw_size(void *handle
, int width
, int height
)
215 * Send raw special codes.
217 static void raw_special(void *handle
, Telnet_Special code
)
224 * Return a list of the special codes that make sense in this
227 static const struct telnet_special
*raw_get_specials(void *handle
)
232 static int raw_connected(void *handle
)
234 Raw raw
= (Raw
) handle
;
235 return raw
->s
!= NULL
;
238 static int raw_sendok(void *handle
)
243 static void raw_unthrottle(void *handle
, int backlog
)
245 Raw raw
= (Raw
) handle
;
246 sk_set_frozen(raw
->s
, backlog
> RAW_MAX_BACKLOG
);
249 static int raw_ldisc(void *handle
, int option
)
251 if (option
== LD_EDIT
|| option
== LD_ECHO
)
256 static void raw_provide_ldisc(void *handle
, void *ldisc
)
258 /* This is a stub. */
261 static void raw_provide_logctx(void *handle
, void *logctx
)
263 /* This is a stub. */
266 static int raw_exitcode(void *handle
)
268 Raw raw
= (Raw
) handle
;
270 return -1; /* still connected */
272 /* Exit codes are a meaningless concept in the Raw protocol */
277 * cfg_info for Raw does nothing at all.
279 static int raw_cfg_info(void *handle
)
284 Backend raw_backend
= {