2 ; IPv6 enabled finger client/server for PLD GNU Linux
3 ; Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
5 diff -urN bsd-finger-0.16.org/finger/net.c bsd-finger-0.16/finger/net.c
6 --- bsd-finger-0.16.org/finger/net.c Tue Sep 12 21:34:24 2000
7 +++ bsd-finger-0.16/finger/net.c Tue Sep 12 21:34:50 2000
10 void netfinger(const char *name) {
12 - struct in_addr defaddr;
13 register int c, sawret, ateol;
14 - struct hostent *hp, def;
16 - struct sockaddr_in sn;
18 - char *alist[1], *host;
20 + char hbuf[NI_MAXHOST];
21 + struct addrinfo hints, *res, *res0;
24 host = strrchr(name, '@');
28 - memset(&sn, 0, sizeof(sn));
30 - sp = getservbyname("finger", "tcp");
32 - eprintf("finger: tcp/finger: unknown service\n");
33 + memset(&hints, 0, sizeof(hints));
34 + hints.ai_family = AF_UNSPEC;
35 + hints.ai_socktype = SOCK_STREAM;
36 + if (getaddrinfo(host, "finger", &hints, &res0)) {
37 + eprintf("finger: unknown host: %s\n", host);
40 - sn.sin_port = sp->s_port;
42 - hp = gethostbyname(host);
44 - if (!inet_aton(host, &defaddr)) {
45 - eprintf("finger: unknown host: %s\n", host);
47 + for (res = res0; res; res = res->ai_next) {
48 + s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
53 + eprintf("finger: socket: %s\n", strerror(errno));
58 - def.h_addr_list = alist;
59 - def.h_addr = (char *)&defaddr;
60 - def.h_length = sizeof(struct in_addr);
61 - def.h_addrtype = AF_INET;
65 - sn.sin_family = hp->h_addrtype;
66 - if (hp->h_length > (int)sizeof(sn.sin_addr)) {
67 - hp->h_length = sizeof(sn.sin_addr);
69 - memcpy(&sn.sin_addr, hp->h_addr, hp->h_length);
71 - if ((s = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) {
72 - eprintf("finger: socket: %s\n", strerror(errno));
76 - /* print hostname before connecting, in case it takes a while */
77 - xprintf("[%s]\n", hp->h_name);
78 - if (connect(s, (struct sockaddr *)&sn, sizeof(sn)) < 0) {
79 - eprintf("finger: connect: %s\n", strerror(errno));
82 + getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
84 + /* print hostname before connecting, in case it takes a while */
85 + xprintf("[%s]\n", hbuf);
86 + if (connect(s, res->ai_addr, res->ai_addrlen) < 0) {
91 + eprintf("finger: connect: %s\n", strerror(errno));
100 /* -l flag for remote fingerd */
101 if (lflag) write(s, "/W ", 3);