]>
Commit | Line | Data |
---|---|---|
6580a72d MT |
1 | --- screen-4.0.3/window.h.ipv6 2003-08-21 16:57:30.000000000 +0200 |
2 | +++ screen-4.0.3/window.h 2006-11-15 13:36:57.000000000 +0100 | |
3 | @@ -254,7 +254,7 @@ | |
4 | struct display *w_zdisplay; | |
5 | #endif | |
6 | #ifdef BUILTIN_TELNET | |
7 | - struct sockaddr_in w_telsa; | |
8 | + struct sockaddr_storage w_telsa; | |
9 | char w_telbuf[IOSIZE]; | |
10 | int w_telbufl; | |
11 | char w_telmopts[256]; | |
12 | --- screen-4.0.3/window.c.ipv6 2003-12-05 14:45:41.000000000 +0100 | |
13 | +++ screen-4.0.3/window.c 2006-11-15 13:39:27.000000000 +0100 | |
14 | @@ -582,6 +582,13 @@ | |
15 | n = pp - wtab; | |
16 | debug1("Makewin creating %d\n", n); | |
17 | ||
18 | +#ifdef BUILTIN_TELNET | |
19 | + if(!strcmp(nwin.args[0], "//telnet")) { | |
20 | + type = W_TYPE_TELNET; | |
21 | + TtyName = "telnet"; | |
22 | + } | |
23 | + else | |
24 | +#endif | |
25 | if ((f = OpenDevice(nwin.args, nwin.lflag, &type, &TtyName)) < 0) | |
26 | return -1; | |
27 | ||
28 | @@ -736,7 +743,7 @@ | |
29 | #ifdef BUILTIN_TELNET | |
30 | if (type == W_TYPE_TELNET) | |
31 | { | |
32 | - if (TelConnect(p)) | |
33 | + if (TelOpenAndConnect(p)) | |
34 | { | |
35 | FreeWindow(p); | |
36 | return -1; | |
37 | @@ -834,6 +841,13 @@ | |
38 | int lflag, f; | |
39 | ||
40 | lflag = nwin_default.lflag; | |
41 | +#ifdef BUILTIN_TELNET | |
42 | + if(!strcmp(p->w_cmdargs[0], "//telnet")) { | |
43 | + p->w_type = W_TYPE_TELNET; | |
44 | + TtyName = "telnet"; | |
45 | + } | |
46 | + else | |
47 | +#endif | |
48 | if ((f = OpenDevice(p->w_cmdargs, lflag, &p->w_type, &TtyName)) < 0) | |
49 | return -1; | |
50 | ||
51 | @@ -864,7 +878,7 @@ | |
52 | #ifdef BUILTIN_TELNET | |
53 | if (p->w_type == W_TYPE_TELNET) | |
54 | { | |
55 | - if (TelConnect(p)) | |
56 | + if (TelOpenAndConnect(p)) | |
57 | return -1; | |
58 | } | |
59 | else | |
60 | @@ -1007,16 +1021,6 @@ | |
61 | ||
62 | if (!arg) | |
63 | return -1; | |
64 | -#ifdef BUILTIN_TELNET | |
65 | - if (strcmp(arg, "//telnet") == 0) | |
66 | - { | |
67 | - f = TelOpen(args + 1); | |
68 | - lflag = 0; | |
69 | - *typep = W_TYPE_TELNET; | |
70 | - *namep = "telnet"; | |
71 | - } | |
72 | - else | |
73 | -#endif | |
74 | if ((stat(arg, &st)) == 0 && S_ISCHR(st.st_mode)) | |
75 | { | |
76 | if (access(arg, R_OK | W_OK) == -1) | |
77 | --- screen-4.0.3/teln.c.ipv6 2003-09-08 16:26:56.000000000 +0200 | |
78 | +++ screen-4.0.3/teln.c 2006-11-15 13:36:57.000000000 +0100 | |
79 | @@ -25,6 +25,7 @@ | |
80 | #include <sys/socket.h> | |
81 | #include <fcntl.h> | |
82 | #include <netdb.h> | |
83 | +#include <stdio.h> | |
84 | ||
85 | #include "config.h" | |
86 | ||
87 | @@ -37,12 +38,13 @@ | |
88 | extern struct layer *flayer; | |
89 | extern int visual_bell; | |
90 | extern char screenterm[]; | |
91 | +extern int af; | |
92 | ||
93 | static void TelReply __P((struct win *, char *, int)); | |
94 | static void TelDocmd __P((struct win *, int, int)); | |
95 | static void TelDosub __P((struct win *)); | |
96 | - | |
97 | -#define TEL_DEFPORT 23 | |
98 | +// why TEL_DEFPORT has " | |
99 | +#define TEL_DEFPORT "23" | |
100 | #define TEL_CONNECTING (-2) | |
101 | ||
102 | #define TC_IAC 255 | |
103 | @@ -99,86 +101,78 @@ | |
104 | } | |
105 | ||
106 | int | |
107 | -TelOpen(args) | |
108 | -char **args; | |
109 | -{ | |
110 | - int fd; | |
111 | - int on = 1; | |
112 | - | |
113 | - if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) | |
114 | - { | |
115 | - Msg(errno, "TelOpen: socket"); | |
116 | - return -1; | |
117 | - } | |
118 | - if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on))) | |
119 | - Msg(errno, "TelOpen: setsockopt SO_OOBINLINE"); | |
120 | - return fd; | |
121 | -} | |
122 | - | |
123 | -int | |
124 | -TelConnect(p) | |
125 | -struct win *p; | |
126 | -{ | |
127 | - int port = TEL_DEFPORT; | |
128 | - struct hostent *hp; | |
129 | - char **args; | |
130 | +TelOpenAndConnect(struct win *p) { | |
131 | + int fd, on = 1; | |
132 | char buf[256]; | |
133 | ||
134 | - args = p->w_cmdargs + 1; | |
135 | - | |
136 | - if (!*args) | |
137 | - { | |
138 | - Msg(0, "Usage: screen //telnet host [port]"); | |
139 | - return -1; | |
140 | - } | |
141 | - if (args[1]) | |
142 | - port = atoi(args[1]); | |
143 | - p->w_telsa.sin_family = AF_INET; | |
144 | - if((p->w_telsa.sin_addr.s_addr = inet_addr(*args)) == -1) | |
145 | - { | |
146 | - if ((hp = gethostbyname(*args)) == NULL) | |
147 | - { | |
148 | - Msg(0, "unknown host: %s", *args); | |
149 | - return -1; | |
150 | - } | |
151 | - if (hp->h_length != sizeof(p->w_telsa.sin_addr.s_addr) || hp->h_addrtype != AF_INET) | |
152 | - { | |
153 | - Msg(0, "Bad address type for %s", hp->h_name); | |
154 | - return -1; | |
155 | - } | |
156 | - bcopy((char *)hp->h_addr,(char *)&p->w_telsa.sin_addr.s_addr, hp->h_length); | |
157 | - p->w_telsa.sin_family = hp->h_addrtype; | |
158 | - } | |
159 | - p->w_telsa.sin_port = htons(port); | |
160 | - if (port != TEL_DEFPORT) | |
161 | - sprintf(buf, "Trying %s %d...", inet_ntoa(p->w_telsa.sin_addr), port); | |
162 | - else | |
163 | - sprintf(buf, "Trying %s...", inet_ntoa(p->w_telsa.sin_addr)); | |
164 | - WriteString(p, buf, strlen(buf)); | |
165 | - if (connect(p->w_ptyfd, (struct sockaddr *)&p->w_telsa, sizeof(p->w_telsa))) | |
166 | - { | |
167 | - if (errno == EINPROGRESS) | |
168 | - { | |
169 | - p->w_telstate = TEL_CONNECTING; | |
170 | - p->w_telconnev.fd = p->w_ptyfd; | |
171 | - p->w_telconnev.handler = tel_connev_fn; | |
172 | - p->w_telconnev.data = (char *)p; | |
173 | - p->w_telconnev.type = EV_WRITE; | |
174 | - p->w_telconnev.pri = 1; | |
175 | - debug("telnet connect in progress...\n"); | |
176 | - evenq(&p->w_telconnev); | |
177 | - } | |
178 | - else | |
179 | - { | |
180 | - Msg(errno, "TelOpen: connect"); | |
181 | - return -1; | |
182 | - } | |
183 | - } | |
184 | - else | |
185 | - WriteString(p, "connected.\r\n", 12); | |
186 | - if (port == TEL_DEFPORT) | |
187 | - TelReply(p, (char *)tn_init, sizeof(tn_init)); | |
188 | - return 0; | |
189 | + struct addrinfo hints, *res0, *res; | |
190 | + | |
191 | + if (!(p->w_cmdargs[1])) { | |
192 | + Msg(0, "Usage: screen //telnet host [port]"); | |
193 | + return -1; | |
194 | + } | |
195 | + | |
196 | + memset(&hints, 0, sizeof(hints)); | |
197 | + hints.ai_family = af; | |
198 | + hints.ai_socktype = SOCK_STREAM; | |
199 | + hints.ai_protocol = IPPROTO_TCP; | |
200 | + if(getaddrinfo(p->w_cmdargs[1], p->w_cmdargs[2] ? p->w_cmdargs[2] : TEL_DEFPORT, | |
201 | + &hints, &res0)) { | |
202 | + Msg(0, "unknown host: %s", p->w_cmdargs[1]); | |
203 | + return -1; | |
204 | + } | |
205 | + | |
206 | + for(res = res0; res; res = res->ai_next) { | |
207 | + if((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) { | |
208 | + if(res->ai_next) | |
209 | + continue; | |
210 | + else { | |
211 | + Msg(errno, "TelOpenAndConnect: socket"); | |
212 | + freeaddrinfo(res0); | |
213 | + return -1; | |
214 | + } | |
215 | + } | |
216 | + | |
217 | + if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on))) | |
218 | + Msg(errno, "TelOpenAndConnect: setsockopt SO_OOBINLINE"); | |
219 | + | |
220 | + if (p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT)) | |
221 | + snprintf(buf, 256, "Trying %s %s...", p->w_cmdargs[1], p->w_cmdargs[2]); | |
222 | + else | |
223 | + snprintf(buf, 256, "Trying %s...", p->w_cmdargs[1]); | |
224 | + WriteString(p, buf, strlen(buf)); | |
225 | + if (connect(fd, res->ai_addr, res->ai_addrlen)) { | |
226 | + if (errno == EINPROGRESS) { | |
227 | + p->w_telstate = TEL_CONNECTING; | |
228 | + p->w_telconnev.fd = fd; | |
229 | + p->w_telconnev.handler = tel_connev_fn; | |
230 | + p->w_telconnev.data = (char *)p; | |
231 | + p->w_telconnev.type = EV_WRITE; | |
232 | + p->w_telconnev.pri = 1; | |
233 | + debug("telnet connect in progress...\n"); | |
234 | + evenq(&p->w_telconnev); | |
235 | + } | |
236 | + else { | |
237 | + close(fd); | |
238 | + if(res->ai_next) | |
239 | + continue; | |
240 | + else { | |
241 | + Msg(errno, "TelOpenAndConnect: connect"); | |
242 | + freeaddrinfo(res0); | |
243 | + return -1; | |
244 | + } | |
245 | + } | |
246 | + } | |
247 | + else | |
248 | + WriteString(p, "connected.\r\n", 12); | |
249 | + if (!(p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT))) | |
250 | + TelReply(p, (char *)tn_init, sizeof(tn_init)); | |
251 | + p->w_ptyfd = fd; | |
252 | + memcpy(&p->w_telsa, &res->ai_addr, sizeof(res->ai_addr)); | |
253 | + freeaddrinfo(res0); | |
254 | + return 0; | |
255 | + } | |
256 | + return -1; | |
257 | } | |
258 | ||
259 | int | |
260 | --- screen-4.0.3/help.c.ipv6 2003-09-08 16:25:33.000000000 +0200 | |
261 | +++ screen-4.0.3/help.c 2006-11-15 13:36:57.000000000 +0100 | |
262 | @@ -49,6 +49,10 @@ | |
263 | { | |
264 | printf("Use: %s [-opts] [cmd [args]]\n", myname); | |
265 | printf(" or: %s -r [host.tty]\n\nOptions:\n", myname); | |
266 | +#ifdef BUILTIN_TELNET | |
267 | + printf("-4 Use IPv4.\n"); | |
268 | + printf("-6 Use IPv6.\n"); | |
269 | +#endif | |
270 | printf("-a Force all capabilities into each window's termcap.\n"); | |
271 | printf("-A -[r|R] Adapt all windows to the new display width & height.\n"); | |
272 | printf("-c file Read configuration file instead of '.screenrc'.\n"); | |
273 | --- screen-4.0.3/screen.c.ipv6 2003-09-08 16:26:41.000000000 +0200 | |
274 | +++ screen-4.0.3/screen.c 2006-11-15 13:36:57.000000000 +0100 | |
275 | @@ -231,8 +231,9 @@ | |
276 | struct win *fore; | |
277 | struct win *windows; | |
278 | struct win *console_window; | |
279 | - | |
280 | - | |
281 | +#ifdef BUILTIN_TELNET | |
282 | +int af; | |
283 | +#endif | |
284 | ||
285 | /* | |
286 | * Do this last | |
287 | @@ -471,6 +472,9 @@ | |
288 | nwin = nwin_undef; | |
289 | nwin_options = nwin_undef; | |
290 | strcpy(screenterm, "screen"); | |
291 | +#ifdef BUILTIN_TELNET | |
292 | + af = AF_UNSPEC; | |
293 | +#endif | |
294 | ||
295 | logreopen_register(lf_secreopen); | |
296 | ||
297 | @@ -505,6 +509,14 @@ | |
298 | { | |
299 | switch (*ap) | |
300 | { | |
301 | +#ifdef BUILTIN_TELNET | |
302 | + case '4': | |
303 | + af = AF_INET; | |
304 | + break; | |
305 | + case '6': | |
306 | + af = AF_INET6; | |
307 | + break; | |
308 | +#endif | |
309 | case 'a': | |
310 | nwin_options.aflag = 1; | |
311 | break; | |
312 | --- screen-4.0.3/extern.h.ipv6 2003-08-22 14:27:57.000000000 +0200 | |
313 | +++ screen-4.0.3/extern.h 2006-11-15 13:36:57.000000000 +0100 | |
314 | @@ -446,8 +446,7 @@ | |
315 | ||
316 | /* teln.c */ | |
317 | #ifdef BUILTIN_TELNET | |
318 | -extern int TelOpen __P((char **)); | |
319 | -extern int TelConnect __P((struct win *)); | |
320 | +extern int TelOpenAndConnect __P((struct win *)); | |
321 | extern int TelIsline __P((struct win *p)); | |
322 | extern void TelProcessLine __P((char **, int *)); | |
323 | extern int DoTelnet __P((char *, int *, int)); |