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
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.
10 +Resolve hostnames only to IPv4 addresses.
13 +Resolve hostnames only to IPv6 addresses.
15 .SH "DEFAULT KEY BINDINGS"
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))
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;
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");
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;
50 struct win *console_window;
53 +#ifdef BUILTIN_TELNET
59 @@ -507,6 +508,9 @@ char **av;
61 nwin_options = nwin_undef;
62 strcpy(screenterm, "screen");
63 +#ifdef BUILTIN_TELNET
67 logreopen_register(lf_secreopen);
69 @@ -541,6 +545,14 @@ char **av;
73 +#ifdef BUILTIN_TELNET
82 nwin_options.aflag = 1;
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
88 #include <sys/socket.h>
95 @@ -42,12 +43,13 @@ extern struct win *fore;
96 extern struct layer *flayer;
97 extern int visual_bell;
98 extern char screenterm[];
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 *));
105 -#define TEL_DEFPORT 23
106 +// why TEL_DEFPORT has "
107 +#define TEL_DEFPORT "23"
108 #define TEL_CONNECTING (-2)
111 @@ -105,86 +107,78 @@ char *data;
121 - if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
123 - Msg(errno, "TelOpen: socket");
126 - if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)))
127 - Msg(errno, "TelOpen: setsockopt SO_OOBINLINE");
135 - int port = TEL_DEFPORT;
136 - struct hostent *hp;
138 +TelOpenAndConnect(struct win *p) {
142 - args = p->w_cmdargs + 1;
146 - Msg(0, "Usage: screen //telnet host [port]");
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)
154 - if ((hp = gethostbyname(*args)) == NULL)
156 - Msg(0, "unknown host: %s", *args);
159 - if (hp->h_length != sizeof(p->w_telsa.sin_addr.s_addr) || hp->h_addrtype != AF_INET)
161 - Msg(0, "Bad address type for %s", hp->h_name);
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;
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);
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)))
175 - if (errno == EINPROGRESS)
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);
188 - Msg(errno, "TelOpen: connect");
193 - WriteString(p, "connected.\r\n", 12);
194 - if (port == TEL_DEFPORT)
195 - TelReply(p, (char *)tn_init, sizeof(tn_init));
197 + struct addrinfo hints, *res0, *res;
199 + if (!(p->w_cmdargs[1])) {
200 + Msg(0, "Usage: screen //telnet host [port]");
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,
210 + Msg(0, "unknown host: %s", p->w_cmdargs[1]);
214 + for(res = res0; res; res = res->ai_next) {
215 + if((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
219 + Msg(errno, "TelOpenAndConnect: socket");
220 + freeaddrinfo(res0);
225 + if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)))
226 + Msg(errno, "TelOpenAndConnect: setsockopt SO_OOBINLINE");
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]);
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);
249 + Msg(errno, "TelOpenAndConnect: connect");
250 + freeaddrinfo(res0);
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));
260 + memcpy(&p->w_telsa, &res->ai_addr, sizeof(res->ai_addr));
261 + freeaddrinfo(res0);
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;
273 debug1("Makewin creating %d\n", n);
275 +#ifdef BUILTIN_TELNET
276 + if(!strcmp(nwin.args[0], "//telnet")) {
277 + type = W_TYPE_TELNET;
278 + TtyName = "telnet";
282 if ((f = OpenDevice(nwin.args, nwin.lflag, &type, &TtyName)) < 0)
284 if (type == W_TYPE_GROUP)
285 @@ -766,7 +773,7 @@ struct NewWindow *newwin;
286 #ifdef BUILTIN_TELNET
287 if (type == W_TYPE_TELNET)
290 + if (TelOpenAndConnect(p))
294 @@ -878,6 +885,13 @@ struct win *p;
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";
305 if ((f = OpenDevice(p->w_cmdargs, lflag, &p->w_type, &TtyName)) < 0)
308 @@ -909,7 +923,7 @@ struct win *p;
309 #ifdef BUILTIN_TELNET
310 if (p->w_type == W_TYPE_TELNET)
313 + if (TelOpenAndConnect(p))
317 @@ -1068,16 +1082,6 @@ char **namep;
321 -#ifdef BUILTIN_TELNET
322 - if (strcmp(arg, "//telnet") == 0)
324 - f = TelOpen(args + 1);
326 - *typep = W_TYPE_TELNET;
331 if (strncmp(arg, "//", 2) == 0)
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;
340 #ifdef BUILTIN_TELNET
341 - struct sockaddr_in w_telsa;
342 + struct sockaddr_storage w_telsa;
343 char w_telbuf[IOSIZE];
345 char w_telmopts[256];