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