Experimental Rlogin support, thanks to Delian Delchev. Local flow
[u/mdw/putty] / raw.c
CommitLineData
5e1a8e27 1#include <windows.h>
2#include <stdio.h>
3#include <stdlib.h>
5e1a8e27 4
5#include "putty.h"
6
7#ifndef FALSE
8#define FALSE 0
9#endif
10#ifndef TRUE
11#define TRUE 1
12#endif
13
8df7a775 14static Socket s = NULL;
5e1a8e27 15
5e1a8e27 16static void raw_size(void);
17
18static int sb_opt, sb_len;
19static char *sb_buf = NULL;
20static int sb_size = 0;
21#define SB_DELTA 1024
22
8df7a775 23static void c_write (char *buf, int len) {
24 from_backend(0, buf, len);
5e1a8e27 25}
26
8df7a775 27static int raw_receive (Socket s, int urgent, char *data, int len) {
28 if (!len) {
29 /* Connection has closed. */
30 sk_close(s);
31 s = NULL;
32 return 0;
5e1a8e27 33 }
8df7a775 34 c_write(data, len);
35 return 1;
5e1a8e27 36}
37
38/*
8df7a775 39 * Called to set up the raw connection.
40 *
5e1a8e27 41 * Returns an error message, or NULL on success.
42 *
43 * Also places the canonical host name into `realhost'.
44 */
8df7a775 45static char *raw_init (char *host, int port, char **realhost) {
46 SockAddr addr;
47 char *err;
5e1a8e27 48
49 /*
50 * Try to find host.
51 */
8df7a775 52 addr = sk_namelookup(host, realhost);
53 if ( (err = sk_addr_error(addr)) )
54 return err;
5e1a8e27 55
56 if (port < 0)
57 port = 23; /* default telnet port */
58
59 /*
60 * Open socket.
61 */
c91409da 62 s = sk_new(addr, port, 0, raw_receive);
8df7a775 63 if ( (err = sk_socket_error(s)) )
64 return err;
5e1a8e27 65
8df7a775 66 sk_addr_free(addr);
5e1a8e27 67
6f34e365 68 /*
69 * We have no pre-session phase.
70 */
71 begin_session();
72
5e1a8e27 73 return NULL;
74}
75
76/*
5e1a8e27 77 * Called to send data down the raw connection.
78 */
79static void raw_send (char *buf, int len) {
80
8df7a775 81 if (s == NULL)
5e1a8e27 82 return;
83
8df7a775 84 sk_write(s, buf, len);
5e1a8e27 85}
86
87/*
88 * Called to set the size of the window
89 */
90static void raw_size(void) {
91 /* Do nothing! */
92 return;
93}
94
95/*
96 * Send raw special codes.
97 */
98static void raw_special (Telnet_Special code) {
99 /* Do nothing! */
100 return;
101}
102
8df7a775 103static Socket raw_socket(void) { return s; }
8ccc75b0 104
105static int raw_sendok(void) { return 1; }
4017be6d 106
5e1a8e27 107Backend raw_backend = {
108 raw_init,
5e1a8e27 109 raw_send,
110 raw_size,
4017be6d 111 raw_special,
8ccc75b0 112 raw_socket,
97db3be4 113 raw_sendok,
114 1
5e1a8e27 115};