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