clarify socket-connect trial loop. fix freeaddrinfo().
adjust indentation (commands.c uses sw=4 ts=8).
This commit is contained in:
parent
6703225f00
commit
6ae77d03dc
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: commands.c,v 1.28 1999/07/12 22:10:52 thorpej Exp $ */
|
||||
/* $NetBSD: commands.c,v 1.29 1999/07/14 20:47:41 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1997 and 1998 WIDE Project.
|
||||
@ -67,7 +67,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: commands.c,v 1.28 1999/07/12 22:10:52 thorpej Exp $");
|
||||
__RCSID("$NetBSD: commands.c,v 1.29 1999/07/14 20:47:41 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -2185,7 +2185,8 @@ tn(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
struct addrinfo hints, *res;
|
||||
struct addrinfo hints, *res, *res0;
|
||||
char *cause = "telnet: unknown";
|
||||
int error;
|
||||
#if defined(IP_OPTIONS) && defined(IPPROTO_IP)
|
||||
char *srp = 0;
|
||||
@ -2274,23 +2275,23 @@ tn(argc, argv)
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = 0;
|
||||
error = getaddrinfo(hostname, portp, &hints, &res);
|
||||
error = getaddrinfo(hostname, portp, &hints, &res0);
|
||||
if (!error) {
|
||||
/*numeric*/
|
||||
freeaddrinfo(res);
|
||||
freeaddrinfo(res0);
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = 0;
|
||||
error = getaddrinfo(hostname, portp, &hints, &res);
|
||||
error = getaddrinfo(hostname, portp, &hints, &res0);
|
||||
} else {
|
||||
/*non-numeric*/
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = 0;
|
||||
error = getaddrinfo(hostname, portp, &hints, &res);
|
||||
error = getaddrinfo(hostname, portp, &hints, &res0);
|
||||
}
|
||||
if (error) {
|
||||
fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error));
|
||||
@ -2298,21 +2299,22 @@ tn(argc, argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (res->ai_canonname)
|
||||
(void) strcpy(_hostname, res->ai_canonname);
|
||||
if (res0->ai_canonname)
|
||||
(void) strcpy(_hostname, res0->ai_canonname);
|
||||
hostname = _hostname;
|
||||
|
||||
do {
|
||||
net = -1;
|
||||
for (res = res0; res; res = res->ai_next) {
|
||||
printf("Trying %s...\n", sockaddr_ntop(res->ai_addr));
|
||||
net = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||
setuid(getuid());
|
||||
if (net < 0) {
|
||||
perror("telnet: socket");
|
||||
return 0;
|
||||
cause = "telnet: socket";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (debug && SetSockOpt(net, SOL_SOCKET, SO_DEBUG, 1) < 0) {
|
||||
perror("setsockopt (SO_DEBUG)");
|
||||
perror("setsockopt (SO_DEBUG)");
|
||||
}
|
||||
if (hostp[0] == '@' || hostp[0] == '!') {
|
||||
if ((srlen = sourceroute(res, hostp, &srp, &proto, &opt)) < 0)
|
||||
@ -2322,30 +2324,34 @@ tn(argc, argv)
|
||||
}
|
||||
#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
|
||||
if (ipsec_policy) {
|
||||
int len;
|
||||
char *buf;
|
||||
int level;
|
||||
int optname;
|
||||
int len;
|
||||
char *buf;
|
||||
int level;
|
||||
int optname;
|
||||
|
||||
if ((len = ipsec_get_policylen(ipsec_policy)) < 0) {
|
||||
printf("%s\n", ipsec_strerror());
|
||||
return 0;
|
||||
}
|
||||
if ((buf = (char *)malloc(len)) == NULL) {
|
||||
perror("malloc");
|
||||
return 0;
|
||||
}
|
||||
if ((len = ipsec_set_policy(buf, len, ipsec_policy)) < 0) {
|
||||
printf("%s\n", ipsec_strerror());
|
||||
return 0;
|
||||
}
|
||||
level = res->ai_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
|
||||
optname = res->ai_family == AF_INET ? IP_IPSEC_POLICY : IPV6_IPSEC_POLICY;
|
||||
if (setsockopt(net, level, optname, buf, len) < 0){
|
||||
perror("setsockopt");
|
||||
return 0;
|
||||
}
|
||||
free(buf);
|
||||
if ((len = ipsec_get_policylen(ipsec_policy)) < 0) {
|
||||
printf("%s\n", ipsec_strerror());
|
||||
freeaddrinfo(res0);
|
||||
return 0;
|
||||
}
|
||||
if ((buf = (char *)malloc(len)) == NULL) {
|
||||
perror("malloc");
|
||||
freeaddrinfo(res0);
|
||||
return 0;
|
||||
}
|
||||
if ((len = ipsec_set_policy(buf, len, ipsec_policy)) < 0) {
|
||||
printf("%s\n", ipsec_strerror());
|
||||
freeaddrinfo(res0);
|
||||
return 0;
|
||||
}
|
||||
level = res->ai_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
|
||||
optname = res->ai_family == AF_INET ? IP_IPSEC_POLICY : IPV6_IPSEC_POLICY;
|
||||
if (setsockopt(net, level, optname, buf, len) < 0){
|
||||
perror("setsockopt");
|
||||
freeaddrinfo(res0);
|
||||
return 0;
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -2357,18 +2363,25 @@ tn(argc, argv)
|
||||
sockaddr_ntop(res->ai_addr));
|
||||
errno = oerrno;
|
||||
perror((char *)0);
|
||||
res = res->ai_next;
|
||||
(void) NetClose(net);
|
||||
continue;
|
||||
}
|
||||
perror("telnet: Unable to connect to remote host");
|
||||
return 0;
|
||||
cause = "telnet: Unable to connect to remote host";
|
||||
(void) NetClose(net);
|
||||
net = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
connected++;
|
||||
#if defined(AUTHENTICATION)
|
||||
auth_encrypt_connect(connected);
|
||||
#endif /* defined(AUTHENTICATION) */
|
||||
} while (connected == 0);
|
||||
break;
|
||||
}
|
||||
freeaddrinfo(res0);
|
||||
if (net < 0 || connected == 0) {
|
||||
perror(cause);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cmdrc(hostp, hostname);
|
||||
if (autologin && user == NULL) {
|
||||
struct passwd *pw;
|
||||
|
Loading…
Reference in New Issue
Block a user