telnet/telnet-0.17-force-ipv6-ipv4.patch
2016-01-25 16:04:33 +01:00

133 lines
3.4 KiB
Diff

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