]> git.pld-linux.org Git - packages/bsd-finger.git/blob - bsd-finger-0.16-20000912.patch
- store patches in decompressed files
[packages/bsd-finger.git] / bsd-finger-0.16-20000912.patch
1 ;
2 ; IPv6 enabled finger client/server for PLD GNU Linux
3 ;               Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
4 ;
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
8 @@ -53,59 +53,50 @@
9  
10  void netfinger(const char *name) {
11         register FILE *fp;
12 -       struct in_addr defaddr;
13         register int c, sawret, ateol;
14 -       struct hostent *hp, def;
15 -       struct servent *sp;
16 -       struct sockaddr_in sn;
17 -       int s;
18 -       char *alist[1], *host;
19 +       char *host;
20 +       char hbuf[NI_MAXHOST];
21 +       struct addrinfo hints, *res, *res0;
22 +       int s = -1;
23  
24         host = strrchr(name, '@');
25         if (!host) return;
26         *host++ = '\0';
27  
28 -       memset(&sn, 0, sizeof(sn));
29 -
30 -       sp = getservbyname("finger", "tcp");
31 -       if (!sp) {
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);
38                 return;
39         }
40 -       sn.sin_port = sp->s_port;
41 -
42 -       hp = gethostbyname(host);
43 -       if (!hp) {
44 -               if (!inet_aton(host, &defaddr)) {
45 -                       eprintf("finger: unknown host: %s\n", host);
46 -                       return;
47 +       for (res = res0; res; res = res->ai_next) {
48 +               s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
49 +               if (s < 0) {
50 +                       if (res->ai_next)
51 +                               continue;
52 +                       else {
53 +                               eprintf("finger: socket: %s\n", strerror(errno));
54 +                               return;
55 +                       }
56                 }
57 -               def.h_name = host;
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;
62 -               def.h_aliases = 0;
63 -               hp = &def;
64 -       }
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);
68 -       }
69 -       memcpy(&sn.sin_addr, hp->h_addr, hp->h_length);
70 -
71 -       if ((s = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) {
72 -               eprintf("finger: socket: %s\n", strerror(errno));
73 -               return;
74 -       }
75 -
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));
80 -               close(s);
81 -               return;
82 +               getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
83 +                               NULL, 0, 0);
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) {
87 +                       if (res->ai_next) {
88 +                               close(s);
89 +                               continue;
90 +                       } else {
91 +                               eprintf("finger: connect: %s\n", strerror(errno));
92 +                               close(s);
93 +                               return;
94 +                       }
95 +               }
96 +               break;
97         }
98 +       freeaddrinfo(res0);
99  
100         /* -l flag for remote fingerd  */
101         if (lflag) write(s, "/W ", 3);
This page took 0.092674 seconds and 3 git commands to generate.