1999-11-01 16:40:40 +00: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
|
|
|
|
|
2000-10-23 10:32:37 +00:00
|
|
|
static Socket s = NULL;
|
1999-11-01 16:40:40 +00:00
|
|
|
|
|
|
|
static void raw_size(void);
|
|
|
|
|
|
|
|
static int sb_opt, sb_len;
|
|
|
|
static char *sb_buf = NULL;
|
|
|
|
static int sb_size = 0;
|
|
|
|
#define SB_DELTA 1024
|
|
|
|
|
2000-10-23 10:32:37 +00:00
|
|
|
static void c_write (char *buf, int len) {
|
|
|
|
from_backend(0, buf, len);
|
1999-11-01 16:40:40 +00:00
|
|
|
}
|
|
|
|
|
2001-03-13 10:22:45 +00:00
|
|
|
static int raw_closing (Plug plug, char *error_msg, int error_code, int calling_back) {
|
|
|
|
sk_close(s);
|
|
|
|
s = NULL;
|
|
|
|
if (error_msg) {
|
2001-01-24 10:11:18 +00:00
|
|
|
/* A socket error has occurred. */
|
2001-03-13 10:22:45 +00:00
|
|
|
connection_fatal (error_msg);
|
|
|
|
} /* Otherwise, the remote side closed the connection normally. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int raw_receive (Plug plug, int urgent, char *data, int len) {
|
2000-10-23 10:32:37 +00:00
|
|
|
c_write(data, len);
|
|
|
|
return 1;
|
1999-11-01 16:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-10-23 10:32:37 +00:00
|
|
|
* Called to set up the raw connection.
|
|
|
|
*
|
1999-11-01 16:40:40 +00:00
|
|
|
* Returns an error message, or NULL on success.
|
|
|
|
*
|
|
|
|
* Also places the canonical host name into `realhost'.
|
|
|
|
*/
|
2000-10-23 10:32:37 +00:00
|
|
|
static char *raw_init (char *host, int port, char **realhost) {
|
2001-03-13 10:22:45 +00:00
|
|
|
static struct plug_function_table fn_table = {
|
|
|
|
raw_closing,
|
|
|
|
raw_receive
|
|
|
|
}, *fn_table_ptr = &fn_table;
|
|
|
|
|
2000-10-23 10:32:37 +00:00
|
|
|
SockAddr addr;
|
|
|
|
char *err;
|
1999-11-01 16:40:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find host.
|
|
|
|
*/
|
2000-10-23 10:32:37 +00:00
|
|
|
addr = sk_namelookup(host, realhost);
|
|
|
|
if ( (err = sk_addr_error(addr)) )
|
|
|
|
return err;
|
1999-11-01 16:40:40 +00:00
|
|
|
|
|
|
|
if (port < 0)
|
|
|
|
port = 23; /* default telnet port */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open socket.
|
|
|
|
*/
|
2001-03-13 10:22:45 +00:00
|
|
|
s = sk_new(addr, port, 0, 1, &fn_table_ptr);
|
2000-10-23 10:32:37 +00:00
|
|
|
if ( (err = sk_socket_error(s)) )
|
|
|
|
return err;
|
1999-11-01 16:40:40 +00:00
|
|
|
|
2000-10-23 10:32:37 +00:00
|
|
|
sk_addr_free(addr);
|
1999-11-01 16:40:40 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to send data down the raw connection.
|
|
|
|
*/
|
|
|
|
static void raw_send (char *buf, int len) {
|
|
|
|
|
2000-10-23 10:32:37 +00:00
|
|
|
if (s == NULL)
|
1999-11-01 16:40:40 +00:00
|
|
|
return;
|
|
|
|
|
2000-10-23 10:32:37 +00:00
|
|
|
sk_write(s, buf, len);
|
1999-11-01 16:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to set the size of the window
|
|
|
|
*/
|
|
|
|
static void raw_size(void) {
|
|
|
|
/* Do nothing! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send raw special codes.
|
|
|
|
*/
|
|
|
|
static void raw_special (Telnet_Special code) {
|
|
|
|
/* Do nothing! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-10-23 10:32:37 +00:00
|
|
|
static Socket raw_socket(void) { return s; }
|
2000-09-08 16:42:11 +00:00
|
|
|
|
|
|
|
static int raw_sendok(void) { return 1; }
|
2000-09-08 14:45:20 +00:00
|
|
|
|
2001-01-24 14:08:20 +00:00
|
|
|
static int raw_ldisc(int option) {
|
|
|
|
if (option == LD_EDIT || option == LD_ECHO)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-11-01 16:40:40 +00:00
|
|
|
Backend raw_backend = {
|
|
|
|
raw_init,
|
|
|
|
raw_send,
|
|
|
|
raw_size,
|
2000-09-08 14:45:20 +00:00
|
|
|
raw_special,
|
2000-09-08 16:42:11 +00:00
|
|
|
raw_socket,
|
2000-10-04 14:35:15 +00:00
|
|
|
raw_sendok,
|
2001-01-24 14:08:20 +00:00
|
|
|
raw_ldisc,
|
2000-10-04 14:35:15 +00:00
|
|
|
1
|
1999-11-01 16:40:40 +00:00
|
|
|
};
|