version 1.6, 1998/07/10 15:45:16 |
version 1.7, 1999/12/11 10:05:04 |
|
|
{ |
{ |
FILE *fp; |
FILE *fp; |
int c, lastc; |
int c, lastc; |
struct hostent *hp; |
|
struct servent *sp; |
|
struct sockaddr_in sin; |
|
int s; |
int s; |
char *host; |
char *host; |
|
struct addrinfo hints, *res0, *res; |
|
int error; |
|
char hbuf[NI_MAXHOST]; |
|
|
lastc = 0; |
lastc = 0; |
if (!(host = strrchr(name, '@'))) |
if (!(host = strrchr(name, '@'))) |
return; |
return; |
*host++ = '\0'; |
*host++ = '\0'; |
if (inet_aton(host, &sin.sin_addr) == 0) { |
memset(&hints, 0, sizeof(hints)); |
hp = gethostbyname(host); |
hints.ai_family = PF_UNSPEC; |
if (hp == 0) { |
hints.ai_socktype = SOCK_STREAM; |
warnx("unknown host: %s", host); |
error = getaddrinfo(host, "finger", &hints, &res0); |
return; |
if (error) { |
} |
warnx("%s", gai_strerror(error)); |
sin.sin_family = hp->h_addrtype; |
|
bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length); |
|
host = hp->h_name; |
|
} else |
|
sin.sin_family = AF_INET; |
|
if (!(sp = getservbyname("finger", "tcp"))) { |
|
warnx("tcp/finger: unknown service\n"); |
|
return; |
return; |
} |
} |
sin.sin_port = sp->s_port; |
|
if ((s = socket(sin.sin_family, SOCK_STREAM, 0)) < 0) { |
s = -1; |
perror("finger: socket"); |
for (res = res0; res; res = res->ai_next) { |
|
if ((s = socket(res->ai_family, res->ai_socktype, |
|
res->ai_protocol)) < 0) { |
|
continue; |
|
} |
|
if (connect(s, res->ai_addr, res->ai_addrlen) < 0) { |
|
(void)close(s); |
|
s = -1; |
|
continue; |
|
} |
|
|
|
break; |
|
} |
|
|
|
if (s < 0) { |
|
perror("finger"); |
|
freeaddrinfo(res0); |
return; |
return; |
} |
} |
|
|
/* have network connection; identify the host connected with */ |
/* have network connection; identify the host connected with */ |
(void)printf("[%s]\n", host); |
if (getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf), |
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { |
NULL, 0, NI_NUMERICHOST) != 0) { |
perror("finger: connect"); |
strcpy(hbuf, "(invalid)"); |
(void)close(s); |
|
return; |
|
} |
} |
|
(void)printf("[%s/%s]\n", host, hbuf); |
|
|
|
freeaddrinfo(res0); |
|
|
/* -l flag for remote fingerd */ |
/* -l flag for remote fingerd */ |
if (lflag) |
if (lflag) |