CVS commit: [netbsd-8] src/usr.bin/w
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 < _buf[sizeof(host_buf)]; b++) + if (*b == '\0' || *b == ']') +break; + if (b < _buf[sizeof(host_buf)] && *b == ']') { + *b = '\0'; + for (x = b + 1; x < _buf[sizeof(host_buf)]; x++) +if (*x == '\0' || *x == ':') + break; + if (x < _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, ) && (hp = gethostbyaddr((char *), alen, af))) r = hp->h_name; - else + else { + if (b) + *b = ']'; r = host_buf; + } if (domain[0] != '\0') { p = r;
CVS commit: [netbsd-8] src/usr.bin/w
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.
CVS commit: [netbsd-8] src/usr.bin/w
Module Name:src Committed By: martin Date: Tue Jul 7 10:44:11 UTC 2020 Modified Files: src/usr.bin/w [netbsd-8]: w.c Log Message: Pull up following revision(s) (requested by kim in ticket #1565): usr.bin/w/w.c: revision 1.87 Don't overwrite host_buf as x might be pointing to wanted data in it To generate a diff of this commit: cvs rdiff -u -r1.83.6.1 -r1.83.6.2 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.1 src/usr.bin/w/w.c:1.83.6.2 --- src/usr.bin/w/w.c:1.83.6.1 Tue Jun 30 18:50:05 2020 +++ src/usr.bin/w/w.c Tue Jul 7 10:44:11 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: w.c,v 1.83.6.1 2020/06/30 18:50:05 martin Exp $ */ +/* $NetBSD: w.c,v 1.83.6.2 2020/07/07 10:44:11 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.1 2020/06/30 18:50:05 martin Exp $"); +__RCSID("$NetBSD: w.c,v 1.83.6.2 2020/07/07 10:44:11 martin Exp $"); #endif #endif /* not lint */ @@ -621,7 +621,7 @@ static void fixhost(struct entry *ep) { char host_buf[sizeof(ep->host)]; - char *p, *x, *m; + char *p, *r, *x, *m; struct hostent *hp; union { struct in_addr l4; @@ -649,26 +649,28 @@ fixhost(struct entry *ep) } 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, ) && (hp = gethostbyaddr((char *), alen, af))) - strlcpy(host_buf, hp->h_name, sizeof(host_buf)); + r = hp->h_name; + else + r = host_buf; if (domain[0] != '\0') { - p = host_buf; - p += strlen(host_buf); + p = r; + p += strlen(r); p -= strlen(domain); - if (p > host_buf && + if (p > r && strcasecmp(p, domain) == 0) *p = '\0'; } if (x) - (void)snprintf(ep->host, sizeof(ep->host), "%s:%s", host_buf, - x); + (void)snprintf(ep->host, sizeof(ep->host), "%s:%s", r, x); else - strlcpy(ep->host, host_buf, sizeof(ep->host)); + strlcpy(ep->host, r, sizeof(ep->host)); } static void
CVS commit: [netbsd-8] src/usr.bin/w
Module Name:src Committed By: martin Date: Tue Jul 7 10:44:11 UTC 2020 Modified Files: src/usr.bin/w [netbsd-8]: w.c Log Message: Pull up following revision(s) (requested by kim in ticket #1565): usr.bin/w/w.c: revision 1.87 Don't overwrite host_buf as x might be pointing to wanted data in it To generate a diff of this commit: cvs rdiff -u -r1.83.6.1 -r1.83.6.2 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.
CVS commit: [netbsd-8] src/usr.bin/w
Module Name:src Committed By: martin Date: Tue Jun 30 18:50:05 UTC 2020 Modified Files: src/usr.bin/w [netbsd-8]: w.c Log Message: Pull up following revision(s) (requested by kim in ticket #1564): usr.bin/w/w.c: revision 1.86 usr.bin/w/w.c: revision 1.85 Compute a value for domain before comparing against it Remove local domain always, not just when looking up addresses To generate a diff of this commit: cvs rdiff -u -r1.83 -r1.83.6.1 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 src/usr.bin/w/w.c:1.83.6.1 --- src/usr.bin/w/w.c:1.83 Wed Nov 16 02:03:30 2016 +++ src/usr.bin/w/w.c Tue Jun 30 18:50:05 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: w.c,v 1.83 2016/11/16 02:03:30 christos Exp $ */ +/* $NetBSD: w.c,v 1.83.6.1 2020/06/30 18:50:05 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 2016/11/16 02:03:30 christos Exp $"); +__RCSID("$NetBSD: w.c,v 1.83.6.1 2020/06/30 18:50:05 martin Exp $"); #endif #endif /* not lint */ @@ -205,6 +205,18 @@ main(int argc, char **argv) curtain = 0; } + if (!nflag) { + int rv; + char *p; + + rv = gethostname(domain, sizeof(domain)); + domain[sizeof(domain) - 1] = '\0'; + if (rv < 0 || (p = strchr(domain, '.')) == 0) + domain[0] = '\0'; + else + memmove(domain, p, strlen(p) + 1); + } + #ifdef SUPPORT_UTMPX setutxent(); #endif @@ -388,18 +400,6 @@ main(int argc, char **argv) } #endif - if (!nflag) { - int rv; - char *p; - - rv = gethostname(domain, sizeof(domain)); - domain[sizeof(domain) - 1] = '\0'; - if (rv < 0 || (p = strchr(domain, '.')) == 0) - domain[0] = '\0'; - else - memmove(domain, p, strlen(p) + 1); - } - for (ep = ehead; ep != NULL; ep = ep->next) { if (ep->tp != NULL) kp = ep->tp; @@ -652,23 +652,23 @@ fixhost(struct entry *ep) int af = m ? AF_INET6 : AF_INET; size_t alen = m ? sizeof(l.l6) : sizeof(l.l4); if (!nflag && inet_pton(af, p, ) && - (hp = gethostbyaddr((char *), alen, af))) { - if (domain[0] != '\0') { - p = hp->h_name; - p += strlen(hp->h_name); - p -= strlen(domain); - if (p > hp->h_name && - strcasecmp(p, domain) == 0) -*p = '\0'; - } - p = hp->h_name; + (hp = gethostbyaddr((char *), alen, af))) + strlcpy(host_buf, hp->h_name, sizeof(host_buf)); + + if (domain[0] != '\0') { + p = host_buf; + p += strlen(host_buf); + p -= strlen(domain); + if (p > host_buf && + strcasecmp(p, domain) == 0) + *p = '\0'; } if (x) - (void)snprintf(ep->host, sizeof(ep->host), "%s:%s", p, x); + (void)snprintf(ep->host, sizeof(ep->host), "%s:%s", host_buf, + x); else - - strlcpy(ep->host, p, sizeof(ep->host)); + strlcpy(ep->host, host_buf, sizeof(ep->host)); } static void
CVS commit: [netbsd-8] src/usr.bin/w
Module Name:src Committed By: martin Date: Tue Jun 30 18:50:05 UTC 2020 Modified Files: src/usr.bin/w [netbsd-8]: w.c Log Message: Pull up following revision(s) (requested by kim in ticket #1564): usr.bin/w/w.c: revision 1.86 usr.bin/w/w.c: revision 1.85 Compute a value for domain before comparing against it Remove local domain always, not just when looking up addresses To generate a diff of this commit: cvs rdiff -u -r1.83 -r1.83.6.1 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.