Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/w if there is more than one : it is not an X display...



details:   https://anonhg.NetBSD.org/src/rev/2c686d05ea68
branches:  trunk
changeset: 819068:2c686d05ea68
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Nov 16 02:03:30 2016 +0000

description:
if there is more than one : it is not an X display, it is a v6 address

diffstat:

 usr.bin/w/w.c |  35 +++++++++++++++++++++++------------
 1 files changed, 23 insertions(+), 12 deletions(-)

diffs (67 lines):

diff -r 238ff6debb5a -r 2c686d05ea68 usr.bin/w/w.c
--- a/usr.bin/w/w.c     Wed Nov 16 00:50:12 2016 +0000
+++ b/usr.bin/w/w.c     Wed Nov 16 02:03:30 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: w.c,v 1.82 2014/12/22 15:24:14 dennis Exp $    */
+/*     $NetBSD: w.c,v 1.83 2016/11/16 02:03:30 christos Exp $  */
 
 /*-
  * Copyright (c) 1980, 1991, 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)w.c        8.6 (Berkeley) 6/30/94";
 #else
-__RCSID("$NetBSD: w.c,v 1.82 2014/12/22 15:24:14 dennis Exp $");
+__RCSID("$NetBSD: w.c,v 1.83 2016/11/16 02:03:30 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -621,27 +621,38 @@
 fixhost(struct entry *ep)
 {
        char host_buf[sizeof(ep->host)];
-       char *p, *x;
+       char *p, *x, *m;
        struct hostent *hp;
-       struct in_addr l;
+       union {
+               struct in_addr l4;
+               struct in6_addr l6;
+       } l;
 
        strlcpy(host_buf, *ep->host ? ep->host : "-", sizeof(host_buf));
        p = host_buf;
 
        /*
-        * XXX: Historical behavior, ':' in hostname means X display number,
-        * IPv6 not handled.
+        * One ':' in hostname means X display number, more is IPv6.
         */
        for (x = p; x < &host_buf[sizeof(host_buf)]; x++)
                if (*x == '\0' || *x == ':')
                        break;
        if (x == p + sizeof(host_buf) || *x != ':')
-               x = NULL;
-       else
-               *x++ = '\0';
-
-       if (!nflag && inet_aton(p, &l) &&
-           (hp = gethostbyaddr((char *)&l, sizeof(l), AF_INET))) {
+               m = x = NULL;
+       else {
+               for (m = x + 1; m < &host_buf[sizeof(host_buf)]; m++)
+                       if (*m == '\0' || *m == ':')
+                               break;
+               if (m == p + sizeof(host_buf) || *m != ':') {
+                       *x++ = '\0';
+                       m = NULL;
+               } else
+                       x = NULL;
+       }
+       int af = m ? AF_INET6 : AF_INET;
+       size_t alen = m ? sizeof(l.l6) : sizeof(l.l4);
+       if (!nflag && inet_pton(af, p, &l) &&
+           (hp = gethostbyaddr((char *)&l, alen, af))) {
                if (domain[0] != '\0') {
                        p = hp->h_name;
                        p += strlen(hp->h_name);



Home | Main Index | Thread Index | Old Index