From dc1c5732bd846c46f907265c0fc046b53d0d8959 Mon Sep 17 00:00:00 2001 From: itojun Date: Sat, 13 May 2000 03:17:33 +0000 Subject: [PATCH] correct extremely user-unfriendly error message on bad port ("telnet localhost foo" when foo is invalid). suggested by openbsd camp. --- freebsd2/usr.bin/telnet/commands.c | 6 +++++- freebsd3/usr.bin/telnet/commands.c | 6 +++++- netbsd/usr.bin/telnet/commands.c | 5 ++++- openbsd/usr.bin/telnet/commands.c | 8 +++++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/freebsd2/usr.bin/telnet/commands.c b/freebsd2/usr.bin/telnet/commands.c index 8fa9be1ad9..003632e92f 100644 --- a/freebsd2/usr.bin/telnet/commands.c +++ b/freebsd2/usr.bin/telnet/commands.c @@ -2287,7 +2287,11 @@ tn(argc, argv) hints.ai_protocol = 0; hints.ai_flags = AI_CANONNAME; error = getaddrinfo(hostname, portp, &hints, &res0); - if (error) { + if (error == EAI_SERVICE) { + fprintf(stderr, "tcp/%s: unknown service\n", portp); + setuid(getuid()); + return 0; + } else if (error) { fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error)); setuid(getuid()); return 0; diff --git a/freebsd3/usr.bin/telnet/commands.c b/freebsd3/usr.bin/telnet/commands.c index 5913959554..25e00bcef6 100644 --- a/freebsd3/usr.bin/telnet/commands.c +++ b/freebsd3/usr.bin/telnet/commands.c @@ -2312,7 +2312,11 @@ tn(argc, argv) hints.ai_protocol = 0; hints.ai_flags = AI_CANONNAME; error = getaddrinfo(hostname, portp, &hints, &res0); - if (error) { + if (error == EAI_SERVICE) { + fprintf(stderr, "tcp/%s: unknown service\n", portp); + setuid(getuid()); + return 0; + } else if (error) { fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error)); setuid(getuid()); return 0; diff --git a/netbsd/usr.bin/telnet/commands.c b/netbsd/usr.bin/telnet/commands.c index 8f57ab9b10..96943707ff 100644 --- a/netbsd/usr.bin/telnet/commands.c +++ b/netbsd/usr.bin/telnet/commands.c @@ -2328,7 +2328,10 @@ tn(argc, argv) hints.ai_protocol = 0; hints.ai_flags = AI_CANONNAME; error = getaddrinfo(hostname, portp, &hints, &res0); - if (error) { + if (error == EAI_SERVICE) { + fprintf(stderr, "tcp/%s: unknown service\n", portp); + return 0; + } else if (error) { fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error)); return 0; } diff --git a/openbsd/usr.bin/telnet/commands.c b/openbsd/usr.bin/telnet/commands.c index 791eb44e40..fcf22db0a7 100644 --- a/openbsd/usr.bin/telnet/commands.c +++ b/openbsd/usr.bin/telnet/commands.c @@ -2384,7 +2384,13 @@ tn(argc, argv) telnetport = 1; } error = getaddrinfo(hostp, portp, &hints, &res0); - if (error) { + if (error == EAI_SERVICE) { + warn("tcp/%s: unknown service\n", portp); + herror(hostp); + seteuid(getuid()); + setuid(getuid()); + return 0; + } else if (error) { warn("%s: %s", hostp, gai_strerror(error)); herror(hostp); seteuid(getuid());