Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/w Handle hostname from DISPLAY="[2001:db8::dead:beef...



details:   https://anonhg.NetBSD.org/src/rev/8be07fdf7f05
branches:  trunk
changeset: 974495:8be07fdf7f05
user:      kim <kim%NetBSD.org@localhost>
date:      Sat Aug 01 15:52:50 2020 +0000

description:
Handle hostname from DISPLAY="[2001:db8::dead:beef]:0" or similar.

diffstat:

 usr.bin/w/w.c |  22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diffs (43 lines):

diff -r 666dd00305e7 -r 8be07fdf7f05 usr.bin/w/w.c
--- a/usr.bin/w/w.c     Sat Aug 01 15:28:28 2020 +0000
+++ b/usr.bin/w/w.c     Sat Aug 01 15:52:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: w.c,v 1.87 2020/07/04 23:30:31 kim Exp $       */
+/*     $NetBSD: w.c,v 1.88 2020/08/01 15:52:50 kim 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.87 2020/07/04 23:30:31 kim Exp $");
+__RCSID("$NetBSD: w.c,v 1.88 2020/08/01 15:52:50 kim Exp $");
 #endif
 #endif /* not lint */
 
@@ -650,6 +650,24 @@
                        x = NULL;
        }
 
+       /*
+        * Leading '[' indicates an IP address inside brackets.
+        */
+       if (*p == '[') {
+               for (p++; p < &host_buf[sizeof(host_buf)]; p++)
+                       if (*p == '\0' || *p == ']')
+                               break;
+               if (p < &host_buf[sizeof(host_buf)] && *p == ']') {
+                       *p = '\0';
+                       for (x = ++p; x < &host_buf[sizeof(host_buf)]; x++)
+                               if (*x == '\0' || *x == ':')
+                                       break;
+                       if (x < &host_buf[sizeof(host_buf)] && *x == ':')
+                               *x++ = '\0';
+               }
+               p = host_buf + 1;
+       }
+
        int af = m ? AF_INET6 : AF_INET;
        size_t alen = m ? sizeof(l.l6) : sizeof(l.l4);
        if (!nflag && inet_pton(af, p, &l) &&



Home | Main Index | Thread Index | Old Index