Module Name: src
Committed By: martin
Date: Sun Aug 2 09:15:03 UTC 2020
Modified Files:
src/usr.bin/w [netbsd-8]: w.c
Log Message:
Pull up following revision(s) (requested by kim in ticket #1583):
usr.bin/w/w.c: revision 1.88
usr.bin/w/w.c: revision 1.89
usr.bin/w/w.c: revision 1.90
Handle hostname from DISPLAY="[2001:db8::dead:beef]:0" or similar.
Restore ']' if not using a result from an address lookup.
Skip bracket processing if -n is used.
XXX: This could be improved to skip even more processing.
To generate a diff of this commit:
cvs rdiff -u -r1.83.6.2 -r1.83.6.3 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.83.6.2 src/usr.bin/w/w.c:1.83.6.3
--- src/usr.bin/w/w.c:1.83.6.2 Tue Jul 7 10:44:11 2020
+++ src/usr.bin/w/w.c Sun Aug 2 09:15:03 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: w.c,v 1.83.6.2 2020/07/07 10:44:11 martin Exp $ */
+/* $NetBSD: w.c,v 1.83.6.3 2020/08/02 09:15:03 martin 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.83.6.2 2020/07/07 10:44:11 martin Exp $");
+__RCSID("$NetBSD: w.c,v 1.83.6.3 2020/08/02 09:15:03 martin Exp $");
#endif
#endif /* not lint */
@@ -621,7 +621,7 @@ static void
fixhost(struct entry *ep)
{
char host_buf[sizeof(ep->host)];
- char *p, *r, *x, *m;
+ char *b, *m, *p, *r, *x;
struct hostent *hp;
union {
struct in_addr l4;
@@ -650,13 +650,35 @@ fixhost(struct entry *ep)
x = NULL;
}
+ /*
+ * Leading '[' indicates an IP address inside brackets.
+ */
+ b = NULL;
+ if (!nflag && (*p == '[')) {
+ for (b = p++; b < &host_buf[sizeof(host_buf)]; b++)
+ if (*b == '\0' || *b == ']')
+ break;
+ if (b < &host_buf[sizeof(host_buf)] && *b == ']') {
+ *b = '\0';
+ for (x = b + 1; x < &host_buf[sizeof(host_buf)]; x++)
+ if (*x == '\0' || *x == ':')
+ break;
+ if (x < &host_buf[sizeof(host_buf)] && *x == ':')
+ *x++ = '\0';
+ } else
+ b = 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)))
r = hp->h_name;
- else
+ else {
+ if (b)
+ *b = ']';
r = host_buf;
+ }
if (domain[0] != '\0') {
p = r;