summaryrefslogtreecommitdiffstats
path: root/usr.bin/telnet
diff options
context:
space:
mode:
authoritojun <itojun@FreeBSD.org>2000-07-05 10:15:23 +0000
committeritojun <itojun@FreeBSD.org>2000-07-05 10:15:23 +0000
commita1d6ff0136a2fc434aa7e2bd6205897cc61b3eba (patch)
tree40976c4426f2ba565ff68dbc185cd093c38ba41f /usr.bin/telnet
parente041633352d9b2beac4692186d590f04c5d371ae (diff)
downloadFreeBSD-src-a1d6ff0136a2fc434aa7e2bd6205897cc61b3eba.zip
FreeBSD-src-a1d6ff0136a2fc434aa7e2bd6205897cc61b3eba.tar.gz
simplify and correct name resolution in tn().
XXX what is the goal of af_switch()? it seems to me it is not necessary any more with getaddrinfo(3) fix for correct name-resolution ordering. comments? >shin
Diffstat (limited to 'usr.bin/telnet')
-rw-r--r--usr.bin/telnet/commands.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c
index c0c6b2c..7adddd6 100644
--- a/usr.bin/telnet/commands.c
+++ b/usr.bin/telnet/commands.c
@@ -2292,7 +2292,19 @@ tn(argc, argv)
hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(hostname, portp, &hints, &res);
- if (error == 0) {
+ if (error) {
+ hints.ai_flags = AI_CANONNAME;
+ error = getaddrinfo(hostname, portp, &hints, &res);
+ }
+ if (error != 0) {
+ fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error));
+ if (error == EAI_SYSTEM)
+ fprintf(stderr, "%s: %s\n", hostname, strerror(errno));
+ setuid(getuid());
+ goto fail;
+ }
+ if (hints.ai_flags == AI_NUMERICHOST) {
+ /* hostname has numeric */
int gni_err = 1;
if (doaddrlookup)
@@ -2300,19 +2312,11 @@ tn(argc, argv)
_hostname, sizeof(_hostname) - 1, NULL, 0,
NI_NAMEREQD);
if (gni_err != 0)
- (void) strncpy(_hostname, hostp, sizeof(_hostname) - 1);
+ (void) strncpy(_hostname, hostp, sizeof(_hostname) - 1);
_hostname[sizeof(_hostname)-1] = '\0';
hostname = _hostname;
- } else if (error == EAI_NONAME) {
- hints.ai_flags = AI_CANONNAME;
- error = getaddrinfo(hostname, portp, &hints, &res);
- if (error != 0) {
- fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error));
- if (error == EAI_SYSTEM)
- fprintf(stderr, "%s: %s\n", hostname, strerror(errno));
- setuid(getuid());
- goto fail;
- }
+ } else {
+ /* hostname has FQDN */
if (srcroute != 0)
(void) strncpy(_hostname, hostname, sizeof(_hostname) - 1);
else if (res->ai_canonname != NULL)
@@ -2321,12 +2325,6 @@ tn(argc, argv)
(void) strncpy(_hostname, hostp, sizeof(_hostname) - 1);
_hostname[sizeof(_hostname)-1] = '\0';
hostname = _hostname;
- } else if (error != 0) {
- fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error));
- if (error == EAI_SYSTEM)
- fprintf(stderr, "%s: %s\n", hostname, strerror(errno));
- setuid(getuid());
- goto fail;
}
res0 = res;
af_again:
OpenPOWER on IntegriCloud