Blame SOURCES/screen-ipv6.patch

c18ec5
diff -up screen/src/doc/screen.1.ipv6 screen/src/doc/screen.1
c18ec5
--- screen/src/doc/screen.1.ipv6	2010-11-11 03:47:46.000000000 +0100
c18ec5
+++ screen/src/doc/screen.1	2011-02-03 16:05:35.957087079 +0100
c18ec5
@@ -398,6 +398,12 @@ Send the specified command to a running 
c18ec5
 the \fB-d\fP or \fB-r\fP option to tell screen to look only for
c18ec5
 attached or detached screen sessions. Note that this command doesn't
c18ec5
 work if the session is password protected.
c18ec5
+.TP 5
c18ec5
+.B \-4
c18ec5
+Resolve hostnames only to IPv4 addresses.
c18ec5
+.TP 5
c18ec5
+.B \-6
c18ec5
+Resolve hostnames only to IPv6 addresses.
c18ec5
 
c18ec5
 .SH "DEFAULT KEY BINDINGS"
c18ec5
 .ta 12n 26n
c18ec5
diff -up screen/src/extern.h.ipv6 screen/src/extern.h
c18ec5
--- screen/src/extern.h.ipv6	2010-11-11 03:47:46.000000000 +0100
c18ec5
+++ screen/src/extern.h	2011-02-03 16:04:35.995743620 +0100
c18ec5
@@ -455,8 +455,7 @@ extern void  ExitOverlayPage __P((void))
c18ec5
 
c18ec5
 /* teln.c */
c18ec5
 #ifdef BUILTIN_TELNET
c18ec5
-extern int   TelOpen __P((char **));
c18ec5
-extern int   TelConnect __P((struct win *));
c18ec5
+extern int   TelOpenAndConnect __P((struct win *));
c18ec5
 extern int   TelIsline __P((struct win *p));
c18ec5
 extern void  TelProcessLine __P((char **, int *));
c18ec5
 extern int   DoTelnet __P((char *, int *, int));
c18ec5
diff -up screen/src/help.c.ipv6 screen/src/help.c
c18ec5
--- screen/src/help.c.ipv6	2010-11-11 03:47:46.000000000 +0100
c18ec5
+++ screen/src/help.c	2011-02-03 16:04:35.992744154 +0100
c18ec5
@@ -66,6 +66,10 @@ char *myname, *message, *arg;
c18ec5
 {
c18ec5
   printf("Use: %s [-opts] [cmd [args]]\n", myname);
c18ec5
   printf(" or: %s -r [host.tty]\n\nOptions:\n", myname);
c18ec5
+#ifdef BUILTIN_TELNET
c18ec5
+  printf("-4            Resolve hostnames only to IPv4 addresses.\n");
c18ec5
+  printf("-6            Resolve hostnames only to IPv6 addresses.\n");
c18ec5
+#endif
c18ec5
   printf("-a            Force all capabilities into each window's termcap.\n");
c18ec5
   printf("-A -[r|R]     Adapt all windows to the new display width & height.\n");
c18ec5
   printf("-c file       Read configuration file instead of '.screenrc'.\n");
c18ec5
diff -up screen/src/screen.c.ipv6 screen/src/screen.c
c18ec5
--- screen/src/screen.c.ipv6	2010-11-11 03:47:46.000000000 +0100
c18ec5
+++ screen/src/screen.c	2011-02-03 16:04:35.994743798 +0100
c18ec5
@@ -248,8 +248,9 @@ struct layer *flayer;
c18ec5
 struct win *fore;
c18ec5
 struct win *windows;
c18ec5
 struct win *console_window;
c18ec5
-
c18ec5
-
c18ec5
+#ifdef BUILTIN_TELNET
c18ec5
+int af;
c18ec5
+#endif
c18ec5
 
c18ec5
 /*
c18ec5
  * Do this last
c18ec5
@@ -507,6 +508,9 @@ char **av;
c18ec5
   nwin = nwin_undef;
c18ec5
   nwin_options = nwin_undef;
c18ec5
   strcpy(screenterm, "screen");
c18ec5
+#ifdef BUILTIN_TELNET
c18ec5
+  af = AF_UNSPEC;
c18ec5
+#endif
c18ec5
 
c18ec5
   logreopen_register(lf_secreopen);
c18ec5
 
c18ec5
@@ -541,6 +545,14 @@ char **av;
c18ec5
 	    {
c18ec5
 	      switch (*ap)
c18ec5
 		{
c18ec5
+#ifdef BUILTIN_TELNET
c18ec5
+               case '4':
c18ec5
+                 af = AF_INET;
c18ec5
+                 break;
c18ec5
+               case '6':
c18ec5
+                 af = AF_INET6;
c18ec5
+                 break;
c18ec5
+#endif
c18ec5
 		case 'a':
c18ec5
 		  nwin_options.aflag = 1;
c18ec5
 		  break;
c18ec5
diff -up screen/src/teln.c.ipv6 screen/src/teln.c
c18ec5
--- screen/src/teln.c.ipv6	2010-11-11 03:47:46.000000000 +0100
c18ec5
+++ screen/src/teln.c	2011-02-03 16:04:35.992744154 +0100
c18ec5
@@ -30,6 +30,7 @@
c18ec5
 #include <sys/socket.h>
c18ec5
 #include <fcntl.h>
c18ec5
 #include <netdb.h>
c18ec5
+#include <stdio.h>
c18ec5
 
c18ec5
 #include "config.h"
c18ec5
 
c18ec5
@@ -42,12 +43,13 @@ extern struct win *fore;
c18ec5
 extern struct layer *flayer;
c18ec5
 extern int visual_bell;
c18ec5
 extern char screenterm[];
c18ec5
+extern int af;
c18ec5
 
c18ec5
 static void TelReply __P((struct win *, char *, int));
c18ec5
 static void TelDocmd __P((struct win *, int, int));
c18ec5
 static void TelDosub __P((struct win *));
c18ec5
-
c18ec5
-#define TEL_DEFPORT	23
c18ec5
+// why TEL_DEFPORT has "
c18ec5
+#define TEL_DEFPORT	"23"
c18ec5
 #define TEL_CONNECTING	(-2)
c18ec5
 
c18ec5
 #define TC_IAC          255
c18ec5
@@ -105,86 +107,78 @@ char *data;
c18ec5
 }
c18ec5
 
c18ec5
 int
c18ec5
-TelOpen(args)
c18ec5
-char **args;
c18ec5
-{
c18ec5
-  int fd;
c18ec5
-  int on = 1;
c18ec5
-
c18ec5
-  if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
c18ec5
-    {
c18ec5
-      Msg(errno, "TelOpen: socket");
c18ec5
-      return -1;
c18ec5
-    }
c18ec5
-  if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)))
c18ec5
-    Msg(errno, "TelOpen: setsockopt SO_OOBINLINE");
c18ec5
-  return fd;
c18ec5
-}
c18ec5
-
c18ec5
-int
c18ec5
-TelConnect(p)
c18ec5
-struct win *p;
c18ec5
-{
c18ec5
-  int port = TEL_DEFPORT;
c18ec5
-  struct hostent *hp;
c18ec5
-  char **args;
c18ec5
+TelOpenAndConnect(struct win *p) {
c18ec5
+  int fd, on = 1;
c18ec5
   char buf[256];
c18ec5
 
c18ec5
-  args = p->w_cmdargs + 1;
c18ec5
-
c18ec5
-  if (!*args)
c18ec5
-    {
c18ec5
-      Msg(0, "Usage: screen //telnet host [port]");
c18ec5
-      return -1;
c18ec5
-    }
c18ec5
-  if (args[1])
c18ec5
-    port = atoi(args[1]);
c18ec5
-  p->w_telsa.sin_family = AF_INET;
c18ec5
-  if((p->w_telsa.sin_addr.s_addr = inet_addr(*args)) == -1)
c18ec5
-    {
c18ec5
-      if ((hp = gethostbyname(*args)) == NULL)
c18ec5
-        {
c18ec5
-	  Msg(0, "unknown host: %s", *args);
c18ec5
-	  return -1;
c18ec5
-        }
c18ec5
-      if (hp->h_length != sizeof(p->w_telsa.sin_addr.s_addr) || hp->h_addrtype != AF_INET)
c18ec5
-	{
c18ec5
-	  Msg(0, "Bad address type for %s", hp->h_name);
c18ec5
-	  return -1;
c18ec5
-	}
c18ec5
-      bcopy((char *)hp->h_addr,(char *)&p->w_telsa.sin_addr.s_addr, hp->h_length);
c18ec5
-      p->w_telsa.sin_family = hp->h_addrtype;
c18ec5
-    }
c18ec5
-  p->w_telsa.sin_port = htons(port);
c18ec5
-  if (port != TEL_DEFPORT)
c18ec5
-    sprintf(buf, "Trying %s %d...", inet_ntoa(p->w_telsa.sin_addr), port);
c18ec5
-  else
c18ec5
-    sprintf(buf, "Trying %s...", inet_ntoa(p->w_telsa.sin_addr));
c18ec5
-  WriteString(p, buf, strlen(buf));
c18ec5
-  if (connect(p->w_ptyfd, (struct sockaddr *)&p->w_telsa, sizeof(p->w_telsa)))
c18ec5
-    {
c18ec5
-      if (errno == EINPROGRESS)
c18ec5
-        {
c18ec5
-	  p->w_telstate = TEL_CONNECTING;
c18ec5
-	  p->w_telconnev.fd = p->w_ptyfd;
c18ec5
-	  p->w_telconnev.handler = tel_connev_fn;
c18ec5
-	  p->w_telconnev.data = (char *)p;
c18ec5
-	  p->w_telconnev.type = EV_WRITE;
c18ec5
-	  p->w_telconnev.pri = 1;
c18ec5
-	  debug("telnet connect in progress...\n");
c18ec5
-	  evenq(&p->w_telconnev);
c18ec5
-	}
c18ec5
-      else
c18ec5
-        {
c18ec5
-	  Msg(errno, "TelOpen: connect");
c18ec5
-	  return -1;
c18ec5
-	}
c18ec5
-    }
c18ec5
-  else
c18ec5
-    WriteString(p, "connected.\r\n", 12);
c18ec5
-  if (port == TEL_DEFPORT)
c18ec5
-    TelReply(p, (char *)tn_init, sizeof(tn_init));
c18ec5
-  return 0;
c18ec5
+  struct addrinfo hints, *res0, *res;
c18ec5
+
c18ec5
+  if (!(p->w_cmdargs[1])) {
c18ec5
+    Msg(0, "Usage: screen //telnet host [port]");
c18ec5
+    return -1;
c18ec5
+  }
c18ec5
+
c18ec5
+  memset(&hints, 0, sizeof(hints));
c18ec5
+  hints.ai_family = af;
c18ec5
+  hints.ai_socktype = SOCK_STREAM;
c18ec5
+  hints.ai_protocol = IPPROTO_TCP;
c18ec5
+  if(getaddrinfo(p->w_cmdargs[1], p->w_cmdargs[2] ? p->w_cmdargs[2] : TEL_DEFPORT,
c18ec5
+                 &hints, &res0)) {
c18ec5
+     Msg(0, "unknown host: %s", p->w_cmdargs[1]);
c18ec5
+     return -1;
c18ec5
+  }
c18ec5
+
c18ec5
+  for(res = res0; res; res = res->ai_next) {
c18ec5
+    if((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
c18ec5
+      if(res->ai_next)
c18ec5
+        continue;
c18ec5
+      else {
c18ec5
+        Msg(errno, "TelOpenAndConnect: socket");
c18ec5
+        freeaddrinfo(res0);
c18ec5
+        return -1;
c18ec5
+      }
c18ec5
+    }
c18ec5
+
c18ec5
+    if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)))
c18ec5
+      Msg(errno, "TelOpenAndConnect: setsockopt SO_OOBINLINE");
c18ec5
+
c18ec5
+    if (p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT))
c18ec5
+      snprintf(buf, 256, "Trying %s %s...", p->w_cmdargs[1], p->w_cmdargs[2]);
c18ec5
+    else
c18ec5
+      snprintf(buf, 256, "Trying %s...", p->w_cmdargs[1]);
c18ec5
+    WriteString(p, buf, strlen(buf));
c18ec5
+    if (connect(fd, res->ai_addr, res->ai_addrlen)) {
c18ec5
+      if (errno == EINPROGRESS) {
c18ec5
+       p->w_telstate = TEL_CONNECTING;
c18ec5
+       p->w_telconnev.fd = fd;
c18ec5
+       p->w_telconnev.handler = tel_connev_fn;
c18ec5
+       p->w_telconnev.data = (char *)p;
c18ec5
+       p->w_telconnev.type = EV_WRITE;
c18ec5
+       p->w_telconnev.pri = 1;
c18ec5
+       debug("telnet connect in progress...\n");
c18ec5
+       evenq(&p->w_telconnev);
c18ec5
+      }
c18ec5
+      else {
c18ec5
+        close(fd);
c18ec5
+       if(res->ai_next)
c18ec5
+         continue;
c18ec5
+       else {
c18ec5
+          Msg(errno, "TelOpenAndConnect: connect");
c18ec5
+          freeaddrinfo(res0);
c18ec5
+          return -1;
c18ec5
+       }
c18ec5
+      }
c18ec5
+    }
c18ec5
+    else
c18ec5
+      WriteString(p, "connected.\r\n", 12);
c18ec5
+    if (!(p->w_cmdargs[2] && strcmp(p->w_cmdargs[2], TEL_DEFPORT)))
c18ec5
+      TelReply(p, (char *)tn_init, sizeof(tn_init));
c18ec5
+    p->w_ptyfd = fd;
c18ec5
+    memcpy(&p->w_telsa, &res->ai_addr, sizeof(res->ai_addr));
c18ec5
+    freeaddrinfo(res0);
c18ec5
+    return 0;
c18ec5
+  }
c18ec5
+  return -1;
c18ec5
 }
c18ec5
 
c18ec5
 int
c18ec5
diff -up screen/src/window.c.ipv6 screen/src/window.c
c18ec5
--- screen/src/window.c.ipv6	2010-11-11 03:47:46.000000000 +0100
c18ec5
+++ screen/src/window.c	2011-02-03 16:30:56.900750293 +0100
c18ec5
@@ -605,6 +605,13 @@ struct NewWindow *newwin;
c18ec5
   n = pp - wtab;
c18ec5
   debug1("Makewin creating %d\n", n);
c18ec5
 
c18ec5
+#ifdef BUILTIN_TELNET
c18ec5
+  if(!strcmp(nwin.args[0], "//telnet")) {
c18ec5
+         type = W_TYPE_TELNET;
c18ec5
+         TtyName = "telnet";
c18ec5
+  }
c18ec5
+  else
c18ec5
+#endif
c18ec5
   if ((f = OpenDevice(nwin.args, nwin.lflag, &type, &TtyName)) < 0)
c18ec5
     return -1;
c18ec5
   if (type == W_TYPE_GROUP)
c18ec5
@@ -766,7 +773,7 @@ struct NewWindow *newwin;
c18ec5
 #ifdef BUILTIN_TELNET
c18ec5
   if (type == W_TYPE_TELNET)
c18ec5
     {
c18ec5
-      if (TelConnect(p))
c18ec5
+      if (TelOpenAndConnect(p))
c18ec5
 	{
c18ec5
 	  FreeWindow(p);
c18ec5
 	  return -1;
c18ec5
@@ -878,6 +885,13 @@ struct win *p;
c18ec5
   int lflag, f;
c18ec5
 
c18ec5
   lflag = nwin_default.lflag;
c18ec5
+#ifdef BUILTIN_TELNET
c18ec5
+  if(!strcmp(p->w_cmdargs[0], "//telnet")) {
c18ec5
+         p->w_type = W_TYPE_TELNET;
c18ec5
+         TtyName = "telnet";
c18ec5
+  }
c18ec5
+  else
c18ec5
+#endif
c18ec5
   if ((f = OpenDevice(p->w_cmdargs, lflag, &p->w_type, &TtyName)) < 0)
c18ec5
     return -1;
c18ec5
 
c18ec5
@@ -909,7 +923,7 @@ struct win *p;
c18ec5
 #ifdef BUILTIN_TELNET
c18ec5
   if (p->w_type == W_TYPE_TELNET)
c18ec5
     {
c18ec5
-      if (TelConnect(p))
c18ec5
+      if (TelOpenAndConnect(p))
c18ec5
         return -1;
c18ec5
     }
c18ec5
   else
c18ec5
@@ -1068,16 +1082,6 @@ char **namep;
c18ec5
       *namep = "telnet";
c18ec5
       return 0;
c18ec5
     }
c18ec5
-#ifdef BUILTIN_TELNET
c18ec5
-  if (strcmp(arg, "//telnet") == 0)
c18ec5
-    {
c18ec5
-      f = TelOpen(args + 1);
c18ec5
-      lflag = 0;
c18ec5
-      *typep = W_TYPE_TELNET;
c18ec5
-      *namep = "telnet";
c18ec5
-    }
c18ec5
-  else
c18ec5
-#endif
c18ec5
   if (strncmp(arg, "//", 2) == 0)
c18ec5
     {
c18ec5
       Msg(0, "Invalid argument '%s'", arg);
c18ec5
diff -up screen/src/window.h.ipv6 screen/src/window.h
c18ec5
--- screen/src/window.h.ipv6	2010-11-11 03:47:46.000000000 +0100
c18ec5
+++ screen/src/window.h	2011-02-03 16:04:35.989744687 +0100
c18ec5
@@ -268,7 +268,7 @@ struct win
c18ec5
   struct display *w_zdisplay;
c18ec5
 #endif
c18ec5
 #ifdef BUILTIN_TELNET
c18ec5
-  struct sockaddr_in w_telsa;
c18ec5
+  struct sockaddr_storage w_telsa;
c18ec5
   char   w_telbuf[IOSIZE];
c18ec5
   int    w_telbufl;
c18ec5
   char   w_telmopts[256];