Module Name:    src
Committed By:   kim
Date:           Sat Aug  1 15:52:50 UTC 2020

Modified Files:
        src/usr.bin/w: w.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/w/w.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/w/w.c
diff -u src/usr.bin/w/w.c:1.87 src/usr.bin/w/w.c:1.88
--- src/usr.bin/w/w.c:1.87	Sat Jul  4 23:30:31 2020
+++ src/usr.bin/w/w.c	Sat Aug  1 15:52:50 2020
@@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
 #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 @@ fixhost(struct entry *ep)
 			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) &&

Reply via email to