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