1999-11-01 19:40:40 +03:00
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
|
|
|
|
#ifndef FALSE
|
|
|
|
#define FALSE 0
|
|
|
|
#endif
|
|
|
|
#ifndef TRUE
|
|
|
|
#define TRUE 1
|
|
|
|
#endif
|
|
|
|
|
2001-08-25 21:09:23 +04:00
|
|
|
#define RAW_MAX_BACKLOG 4096
|
|
|
|
|
2000-10-23 14:32:37 +04:00
|
|
|
static Socket s = NULL;
|
2001-08-25 21:09:23 +04:00
|
|
|
static int raw_bufsize;
|
1999-11-01 19:40:40 +03:00
|
|
|
|
|
|
|
static void raw_size(void);
|
|
|
|
|
2001-05-06 18:35:20 +04:00
|
|
|
static void c_write(char *buf, int len)
|
|
|
|
{
|
2001-08-25 21:09:23 +04:00
|
|
|
int backlog = from_backend(0, buf, len);
|
|
|
|
sk_set_frozen(s, backlog > RAW_MAX_BACKLOG);
|
1999-11-01 19:40:40 +03:00
|
|
|
}
|
|
|
|
|
2001-05-06 18:35:20 +04:00
|
|
|
static int raw_closing(Plug plug, char *error_msg, int error_code,
|
|
|
|
int calling_back)
|
|
|
|
{
|
2001-07-31 18:23:21 +04:00
|
|
|
if (s) {
|
|
|
|
sk_close(s);
|
|
|
|
s = NULL;
|
|
|
|
}
|
2001-03-13 13:22:45 +03:00
|
|
|
if (error_msg) {
|
2001-05-06 18:35:20 +04:00
|
|
|
/* A socket error has occurred. */
|
|
|
|
connection_fatal(error_msg);
|
|
|
|
} /* Otherwise, the remote side closed the connection normally. */
|
2001-03-13 13:22:45 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-05-06 18:35:20 +04:00
|
|
|
static int raw_receive(Plug plug, int urgent, char *data, int len)
|
|
|
|
{
|
2000-10-23 14:32:37 +04:00
|
|
|
c_write(data, len);
|
|
|
|
return 1;
|
1999-11-01 19:40:40 +03:00
|
|
|
}
|
|
|
|
|
2001-09-08 02:39:01 +04:00
|
|
|
static void raw_sent(Plug plug, int bufsize)
|
|
|
|
{
|
|
|
|
raw_bufsize = bufsize;
|
|
|
|
}
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
/*
|
2000-10-23 14:32:37 +04:00
|
|
|
* Called to set up the raw connection.
|
|
|
|
*
|
1999-11-01 19:40:40 +03:00
|
|
|
* Returns an error message, or NULL on success.
|
|
|
|
*
|
2001-05-09 18:01:15 +04:00
|
|
|
* Also places the canonical host name into `realhost'. It must be
|
|
|
|
* freed by the caller.
|
1999-11-01 19:40:40 +03:00
|
|
|
*/
|
2001-11-30 00:47:11 +03:00
|
|
|
static char *raw_init(char *host, int port, char **realhost, int nodelay)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2001-03-13 13:22:45 +03:00
|
|
|
static struct plug_function_table fn_table = {
|
|
|
|
raw_closing,
|
2001-09-08 02:39:01 +04:00
|
|
|
raw_receive,
|
|
|
|
raw_sent
|
2001-03-13 13:22:45 +03:00
|
|
|
}, *fn_table_ptr = &fn_table;
|
|
|
|
|
2000-10-23 14:32:37 +04:00
|
|
|
SockAddr addr;
|
|
|
|
char *err;
|
1999-11-01 19:40:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find host.
|
|
|
|
*/
|
2001-09-08 02:39:01 +04:00
|
|
|
{
|
|
|
|
char buf[200];
|
|
|
|
sprintf(buf, "Looking up host \"%.170s\"", host);
|
|
|
|
logevent(buf);
|
|
|
|
}
|
2000-10-23 14:32:37 +04:00
|
|
|
addr = sk_namelookup(host, realhost);
|
2001-05-06 18:35:20 +04:00
|
|
|
if ((err = sk_addr_error(addr)))
|
2000-10-23 14:32:37 +04:00
|
|
|
return err;
|
1999-11-01 19:40:40 +03:00
|
|
|
|
|
|
|
if (port < 0)
|
|
|
|
port = 23; /* default telnet port */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open socket.
|
|
|
|
*/
|
2001-09-08 02:39:01 +04:00
|
|
|
{
|
|
|
|
char buf[200], addrbuf[100];
|
|
|
|
sk_getaddr(addr, addrbuf, 100);
|
|
|
|
sprintf(buf, "Connecting to %.100s port %d", addrbuf, port);
|
|
|
|
logevent(buf);
|
|
|
|
}
|
2002-03-23 20:47:21 +03:00
|
|
|
s = new_connection(addr, *realhost, port, 0, 1, nodelay, &fn_table_ptr);
|
2001-05-06 18:35:20 +04:00
|
|
|
if ((err = sk_socket_error(s)))
|
2000-10-23 14:32:37 +04:00
|
|
|
return err;
|
1999-11-01 19:40:40 +03:00
|
|
|
|
2000-10-23 14:32:37 +04:00
|
|
|
sk_addr_free(addr);
|
1999-11-01 19:40:40 +03:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to send data down the raw connection.
|
|
|
|
*/
|
2001-08-25 21:09:23 +04:00
|
|
|
static int raw_send(char *buf, int len)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2000-10-23 14:32:37 +04:00
|
|
|
if (s == NULL)
|
2001-08-27 19:55:44 +04:00
|
|
|
return 0;
|
1999-11-01 19:40:40 +03:00
|
|
|
|
2001-08-25 21:09:23 +04:00
|
|
|
raw_bufsize = sk_write(s, buf, len);
|
|
|
|
|
|
|
|
return raw_bufsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to query the current socket sendability status.
|
|
|
|
*/
|
|
|
|
static int raw_sendbuffer(void)
|
|
|
|
{
|
|
|
|
return raw_bufsize;
|
1999-11-01 19:40:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to set the size of the window
|
|
|
|
*/
|
2001-05-06 18:35:20 +04:00
|
|
|
static void raw_size(void)
|
|
|
|
{
|
1999-11-01 19:40:40 +03:00
|
|
|
/* Do nothing! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send raw special codes.
|
|
|
|
*/
|
2001-05-06 18:35:20 +04:00
|
|
|
static void raw_special(Telnet_Special code)
|
|
|
|
{
|
1999-11-01 19:40:40 +03:00
|
|
|
/* Do nothing! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-05-06 18:35:20 +04:00
|
|
|
static Socket raw_socket(void)
|
|
|
|
{
|
|
|
|
return s;
|
|
|
|
}
|
2000-09-08 20:42:11 +04:00
|
|
|
|
2001-05-06 18:35:20 +04:00
|
|
|
static int raw_sendok(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2000-09-08 18:45:20 +04:00
|
|
|
|
2001-08-25 21:09:23 +04:00
|
|
|
static void raw_unthrottle(int backlog)
|
|
|
|
{
|
|
|
|
sk_set_frozen(s, backlog > RAW_MAX_BACKLOG);
|
|
|
|
}
|
|
|
|
|
2001-05-06 18:35:20 +04:00
|
|
|
static int raw_ldisc(int option)
|
|
|
|
{
|
2001-01-24 17:08:20 +03:00
|
|
|
if (option == LD_EDIT || option == LD_ECHO)
|
2001-05-06 18:35:20 +04:00
|
|
|
return 1;
|
2001-01-24 17:08:20 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-12-29 18:31:42 +03:00
|
|
|
static int raw_exitcode(void)
|
|
|
|
{
|
|
|
|
/* Exit codes are a meaningless concept in the Raw protocol */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
Backend raw_backend = {
|
|
|
|
raw_init,
|
|
|
|
raw_send,
|
2001-08-25 21:09:23 +04:00
|
|
|
raw_sendbuffer,
|
1999-11-01 19:40:40 +03:00
|
|
|
raw_size,
|
2000-09-08 18:45:20 +04:00
|
|
|
raw_special,
|
2000-09-08 20:42:11 +04:00
|
|
|
raw_socket,
|
2001-12-29 18:31:42 +03:00
|
|
|
raw_exitcode,
|
2000-10-04 18:35:15 +04:00
|
|
|
raw_sendok,
|
2001-01-24 17:08:20 +03:00
|
|
|
raw_ldisc,
|
2001-08-25 21:09:23 +04:00
|
|
|
raw_unthrottle,
|
2000-10-04 18:35:15 +04:00
|
|
|
1
|
1999-11-01 19:40:40 +03:00
|
|
|
};
|