`realhost', passed back from all the backend init functions, was
[u/mdw/putty] / raw.c
... / ...
CommitLineData
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
14static Socket s = NULL;
15
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
23static void c_write(char *buf, int len)
24{
25 from_backend(0, buf, len);
26}
27
28static int raw_closing(Plug plug, char *error_msg, int error_code,
29 int calling_back)
30{
31 sk_close(s);
32 s = NULL;
33 if (error_msg) {
34 /* A socket error has occurred. */
35 connection_fatal(error_msg);
36 } /* Otherwise, the remote side closed the connection normally. */
37 return 0;
38}
39
40static int raw_receive(Plug plug, int urgent, char *data, int len)
41{
42 c_write(data, len);
43 return 1;
44}
45
46/*
47 * Called to set up the raw connection.
48 *
49 * Returns an error message, or NULL on success.
50 *
51 * Also places the canonical host name into `realhost'. It must be
52 * freed by the caller.
53 */
54static char *raw_init(char *host, int port, char **realhost)
55{
56 static struct plug_function_table fn_table = {
57 raw_closing,
58 raw_receive
59 }, *fn_table_ptr = &fn_table;
60
61 SockAddr addr;
62 char *err;
63
64 /*
65 * Try to find host.
66 */
67 addr = sk_namelookup(host, realhost);
68 if ((err = sk_addr_error(addr)))
69 return err;
70
71 if (port < 0)
72 port = 23; /* default telnet port */
73
74 /*
75 * Open socket.
76 */
77 s = sk_new(addr, port, 0, 1, &fn_table_ptr);
78 if ((err = sk_socket_error(s)))
79 return err;
80
81 sk_addr_free(addr);
82
83 return NULL;
84}
85
86/*
87 * Called to send data down the raw connection.
88 */
89static void raw_send(char *buf, int len)
90{
91
92 if (s == NULL)
93 return;
94
95 sk_write(s, buf, len);
96}
97
98/*
99 * Called to set the size of the window
100 */
101static void raw_size(void)
102{
103 /* Do nothing! */
104 return;
105}
106
107/*
108 * Send raw special codes.
109 */
110static void raw_special(Telnet_Special code)
111{
112 /* Do nothing! */
113 return;
114}
115
116static Socket raw_socket(void)
117{
118 return s;
119}
120
121static int raw_sendok(void)
122{
123 return 1;
124}
125
126static int raw_ldisc(int option)
127{
128 if (option == LD_EDIT || option == LD_ECHO)
129 return 1;
130 return 0;
131}
132
133Backend raw_backend = {
134 raw_init,
135 raw_send,
136 raw_size,
137 raw_special,
138 raw_socket,
139 raw_sendok,
140 raw_ldisc,
141 1
142};