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 |
14 | static Socket s = NULL; |
5e1a8e27 |
15 | |
5e1a8e27 |
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 | |
8df7a775 |
23 | static void c_write (char *buf, int len) { |
24 | from_backend(0, buf, len); |
5e1a8e27 |
25 | } |
26 | |
7dbb9f56 |
27 | static int raw_receive (Socket skt, int urgent, char *data, int len) { |
2c94fd1c |
28 | if (urgent==3) { |
29 | /* A socket error has occurred. */ |
7dbb9f56 |
30 | s = NULL; |
2c94fd1c |
31 | connection_fatal(data); |
32 | len = 0; |
33 | } |
8df7a775 |
34 | if (!len) { |
35 | /* Connection has closed. */ |
36 | sk_close(s); |
37 | s = NULL; |
38 | return 0; |
5e1a8e27 |
39 | } |
8df7a775 |
40 | c_write(data, len); |
41 | return 1; |
5e1a8e27 |
42 | } |
43 | |
44 | /* |
8df7a775 |
45 | * Called to set up the raw connection. |
46 | * |
5e1a8e27 |
47 | * Returns an error message, or NULL on success. |
48 | * |
49 | * Also places the canonical host name into `realhost'. |
50 | */ |
8df7a775 |
51 | static char *raw_init (char *host, int port, char **realhost) { |
52 | SockAddr addr; |
53 | char *err; |
5e1a8e27 |
54 | |
55 | /* |
56 | * Try to find host. |
57 | */ |
8df7a775 |
58 | addr = sk_namelookup(host, realhost); |
59 | if ( (err = sk_addr_error(addr)) ) |
60 | return err; |
5e1a8e27 |
61 | |
62 | if (port < 0) |
63 | port = 23; /* default telnet port */ |
64 | |
65 | /* |
66 | * Open socket. |
67 | */ |
c91409da |
68 | s = sk_new(addr, port, 0, raw_receive); |
8df7a775 |
69 | if ( (err = sk_socket_error(s)) ) |
70 | return err; |
5e1a8e27 |
71 | |
8df7a775 |
72 | sk_addr_free(addr); |
5e1a8e27 |
73 | |
74 | return NULL; |
75 | } |
76 | |
77 | /* |
5e1a8e27 |
78 | * Called to send data down the raw connection. |
79 | */ |
80 | static void raw_send (char *buf, int len) { |
81 | |
8df7a775 |
82 | if (s == NULL) |
5e1a8e27 |
83 | return; |
84 | |
8df7a775 |
85 | sk_write(s, buf, len); |
5e1a8e27 |
86 | } |
87 | |
88 | /* |
89 | * Called to set the size of the window |
90 | */ |
91 | static void raw_size(void) { |
92 | /* Do nothing! */ |
93 | return; |
94 | } |
95 | |
96 | /* |
97 | * Send raw special codes. |
98 | */ |
99 | static void raw_special (Telnet_Special code) { |
100 | /* Do nothing! */ |
101 | return; |
102 | } |
103 | |
8df7a775 |
104 | static Socket raw_socket(void) { return s; } |
8ccc75b0 |
105 | |
106 | static int raw_sendok(void) { return 1; } |
4017be6d |
107 | |
0965bee0 |
108 | static int raw_ldisc(int option) { |
109 | if (option == LD_EDIT || option == LD_ECHO) |
110 | return 1; |
111 | return 0; |
112 | } |
113 | |
5e1a8e27 |
114 | Backend raw_backend = { |
115 | raw_init, |
5e1a8e27 |
116 | raw_send, |
117 | raw_size, |
4017be6d |
118 | raw_special, |
8ccc75b0 |
119 | raw_socket, |
97db3be4 |
120 | raw_sendok, |
0965bee0 |
121 | raw_ldisc, |
97db3be4 |
122 | 1 |
5e1a8e27 |
123 | }; |