Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/finger dual-stack finger.
details: https://anonhg.NetBSD.org/src/rev/7dd956022e04
branches: trunk
changeset: 474243:7dd956022e04
user: itojun <itojun%NetBSD.org@localhost>
date: Fri Jul 02 06:01:22 1999 +0000
description:
dual-stack finger.
% finger itojun@::1
% finger itojun@127.0.0.1
% finger itojun@localhost
tries all addresses listed on DNS, uses first one with successful
connect(2).
diffstat:
usr.bin/finger/Makefile | 4 ++-
usr.bin/finger/net.c | 63 +++++++++++++++++++++++++++---------------------
2 files changed, 38 insertions(+), 29 deletions(-)
diffs (118 lines):
diff -r c85df623a8c3 -r 7dd956022e04 usr.bin/finger/Makefile
--- a/usr.bin/finger/Makefile Fri Jul 02 06:00:06 1999 +0000
+++ b/usr.bin/finger/Makefile Fri Jul 02 06:01:22 1999 +0000
@@ -1,7 +1,9 @@
-# $NetBSD: Makefile,v 1.4 1997/10/19 08:13:23 mrg Exp $
+# $NetBSD: Makefile,v 1.5 1999/07/02 06:01:22 itojun Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= finger
SRCS= finger.c lprint.c net.c sprint.c util.c
+CPPFLAGS+=-DINET6
+
.include <bsd.prog.mk>
diff -r c85df623a8c3 -r 7dd956022e04 usr.bin/finger/net.c
--- a/usr.bin/finger/net.c Fri Jul 02 06:00:06 1999 +0000
+++ b/usr.bin/finger/net.c Fri Jul 02 06:01:22 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: net.c,v 1.12 1998/08/10 03:11:07 perry Exp $ */
+/* $NetBSD: net.c,v 1.13 1999/07/02 06:01:23 itojun Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)net.c 8.4 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: net.c,v 1.12 1998/08/10 03:11:07 perry Exp $");
+__RCSID("$NetBSD: net.c,v 1.13 1999/07/02 06:01:23 itojun Exp $");
#endif
#endif /* not lint */
@@ -61,6 +61,7 @@
#include <string.h>
#include <ctype.h>
#include <unistd.h>
+#include <err.h>
#include "finger.h"
#include "extern.h"
@@ -71,45 +72,51 @@
{
FILE *fp;
int c, lastc;
- struct hostent *hp;
- struct servent *sp;
- struct sockaddr_in sin;
int s;
char *host;
+ struct addrinfo hints, *res, *res0;
+ int error;
+ char *emsg = NULL;
lastc = 0;
if (!(host = strrchr(name, '@')))
return;
*host++ = '\0';
- if (inet_aton(host, &sin.sin_addr) == 0) {
- hp = gethostbyname(host);
- if (hp == 0) {
- (void)fprintf(stderr,
- "finger: unknown host: %s\n", host);
- return;
- }
- sin.sin_family = hp->h_addrtype;
- memcpy((char *)&sin.sin_addr, hp->h_addr, hp->h_length);
- host = hp->h_name;
- } else
- sin.sin_family = AF_INET;
- if (!(sp = getservbyname("finger", "tcp"))) {
- (void)fprintf(stderr, "finger: tcp/finger: unknown service\n");
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_CANONNAME;
+ error = getaddrinfo(host, "finger", &hints, &res0);
+ if (error) {
+ warnx("%s: %s", gai_strerror(error), host);
return;
}
- sin.sin_port = sp->s_port;
- if ((s = socket(sin.sin_family, SOCK_STREAM, 0)) < 0) {
- perror("finger: socket");
+
+ s = -1;
+ for (res = res0; res; res = res->ai_next) {
+ s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+ if (s < 0) {
+ emsg = "socket";
+ continue;
+ }
+
+ if (connect(s, res->ai_addr, res->ai_addrlen)) {
+ close(s);
+ s = -1;
+ emsg = "connect";
+ continue;
+ }
+
+ break;
+ }
+ if (s < 0) {
+ if (emsg != NULL)
+ warn(emsg);
return;
}
/* have network connection; identify the host connected with */
- (void)printf("[%s]\n", host);
- if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
- perror("finger: connect");
- (void)close(s);
- return;
- }
+ (void)printf("[%s]\n", res0->ai_canonname ? res0->ai_canonname : host);
/* -l flag for remote fingerd */
if (lflag)
Home |
Main Index |
Thread Index |
Old Index