Blame SOURCES/telnet-0.17-force-ipv6-ipv4.patch

3521ef
diff --git a/commands.c b/commands.c
3521ef
index 49619ac..636fb5c 100644
3521ef
--- a/telnet/commands.c
3521ef
+++ b/telnet/commands.c
3521ef
@@ -2267,6 +2267,7 @@ tn(int argc, char *argv[])
3521ef
     char *srp = 0;
3521ef
     int srlen;
3521ef
 #endif
3521ef
+    int family = AF_UNSPEC;
3521ef
     char *cmd, *hostp = 0, *portp = 0, *user = 0, *aliasp = 0;
3521ef
     int retry;
3521ef
 #ifdef NI_WITHSCOPEID
3521ef
@@ -2317,6 +2318,21 @@ tn(int argc, char *argv[])
3521ef
 	    autologin = 1;
3521ef
 	    continue;
3521ef
 	}
3521ef
+	
3521ef
+	if (strcmp(*argv, "-6") == 0) {
3521ef
+	    --argc; ++argv;
3521ef
+#ifdef AF_INET6
3521ef
+	    family = AF_INET6;
3521ef
+#else
3521ef
+	    puts("IPv6 unsupported");
3521ef
+#endif
3521ef
+	    continue;
3521ef
+	}
3521ef
+	if (strcmp(*argv, "-4") == 0) {
3521ef
+	    --argc; ++argv;
3521ef
+	    family = AF_INET;
3521ef
+	    continue;
3521ef
+	}
3521ef
 	if (hostp == 0) {
3521ef
 	    hostp = *argv++;
3521ef
 	    --argc;
3521ef
@@ -2355,7 +2371,7 @@ tn(int argc, char *argv[])
3521ef
     {
3521ef
 	hostname = hostp;
3521ef
 	memset(&hints, 0, sizeof(hints));
3521ef
-	hints.ai_family = PF_UNSPEC;
3521ef
+	hints.ai_family = family;
3521ef
 	hints.ai_socktype = SOCK_STREAM;
3521ef
 	hints.ai_flags = AI_CANONNAME;
3521ef
 	if (portp == NULL) {
3521ef
diff --git a/main.c b/main.c
3521ef
index 5fa96e8..599f0af 100644
3521ef
--- a/telnet/main.c
3521ef
+++ b/telnet/main.c
3521ef
@@ -80,10 +80,10 @@ usage(void)
3521ef
 	fprintf(stderr, "Usage: %s %s%s%s%s\n",
3521ef
 	    prompt,
3521ef
 #ifdef	AUTHENTICATION
3521ef
-	    "[-8] [-E] [-K] [-L] [-S tos] [-X atype] [-a] [-c] [-d] [-e char]",
3521ef
+	    "[-4] [-6] [-8] [-E] [-K] [-L] [-S tos] [-X atype] [-a] [-c] [-d] [-e char]",
3521ef
 	    "\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] [-b hostalias ] ",
3521ef
 #else
3521ef
-	    "[-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]",
3521ef
+	    "[-4] [-6] [-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]",
3521ef
 	    "\n\t[-n tracefile] [-b hostalias ] ",
3521ef
 #endif
3521ef
 #if defined(TN3270) && defined(unix)
3521ef
@@ -116,6 +116,7 @@ main(int argc, char *argv[])
3521ef
 #endif
3521ef
 	int ch;
3521ef
 	char *user, *alias;
3521ef
+	int family;
3521ef
 #ifdef	FORWARD
3521ef
 	extern int forward_flags;
3521ef
 #endif	/* FORWARD */
3521ef
@@ -130,7 +131,6 @@ main(int argc, char *argv[])
3521ef
 		prompt = argv[0];
3521ef
 
3521ef
 	user = alias = NULL;
3521ef
-
3521ef
 	rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
3521ef
 
3521ef
 	/* 
3521ef
@@ -139,9 +139,19 @@ main(int argc, char *argv[])
3521ef
 	 * passed 
3521ef
 	 */
3521ef
 	autologin = -1;
3521ef
-
3521ef
-	while ((ch = getopt(argc, argv, "78DEKLS:X:ab:cde:fFk:l:n:rt:x")) != -1) {
3521ef
+	family = 0;
3521ef
+	while ((ch = getopt(argc, argv, "4678DEKLS:X:ab:cde:fFk:l:n:rt:x")) != -1) {
3521ef
 		switch(ch) {
3521ef
+		case '4':
3521ef
+			family = AF_INET;
3521ef
+			break;
3521ef
+		case '6':
3521ef
+#ifdef AF_INET6
3521ef
+			family = AF_INET6;
3521ef
+#else
3521ef
+			fputs("IPv6 unsupported\n", stderr); 
3521ef
+#endif
3521ef
+			break;
3521ef
 		case '8':
3521ef
 			binary = 3;	/* send TELNET BINARY option for output and input */
3521ef
 			break;
3521ef
@@ -340,6 +350,9 @@ main(int argc, char *argv[])
3521ef
 			*argp++ = "-b";
3521ef
 			*argp++ = alias;
3521ef
 		}
3521ef
+		if (family) {
3521ef
+			*argp++ = family == AF_INET ? "-4" : "-6";
3521ef
+		}
3521ef
 		*argp++ = argv[0];		/* host */
3521ef
 		if (argc > 1)
3521ef
 			*argp++ = argv[1];	/* port */
3521ef
diff --git a/telnet.1 b/telnet.1
3521ef
index 50015a6..f30e034 100644
3521ef
--- a/telnet/telnet.1
3521ef
+++ b/telnet/telnet.1
3521ef
@@ -44,7 +44,7 @@
3521ef
 protocol
3521ef
 .Sh SYNOPSIS
3521ef
 .Nm telnet
3521ef
-.Op Fl 8EFKLacdfrx
3521ef
+.Op Fl 468EFKLacdfrx
3521ef
 .Op Fl X Ar authtype
3521ef
 .Op Fl b Ar hostalias
3521ef
 .Op Fl e Ar escapechar
3521ef
@@ -76,6 +76,10 @@ command with those arguments.
3521ef
 .Pp
3521ef
 The options are as follows:
3521ef
 .Bl -tag -width Ds
3521ef
+.It Fl 4
3521ef
+Force IPv4 address resolution.
3521ef
+.It Fl 6
3521ef
+Force IPv6 address resolution.
3521ef
 .It Fl 7
3521ef
 Strip 8th bit on input and output. Telnet is 8-bit clean by default but doesn't send the TELNET BINARY option unless forced.
3521ef
 .It Fl 8