Bug 194755 - w -n does not replace all hostnames with IP-adresses
Summary: w -n does not replace all hostnames with IP-adresses
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-02 09:26 UTC by Kurt Jaeger
Modified: 2018-05-20 23:50 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kurt Jaeger freebsd_committer 2014-11-02 09:26:40 UTC
w displays something like this:

$ w
10:25AM  up 10 days, 22:25, 19 users, load averages: 1.10, 0.74, 0.34
USER       TTY      FROM                      LOGIN@  IDLE WHAT
pi         pts/0    home.opsec.eu            26Oct14 21:53 -bash (bash)
pi         pts/2    complx.nepustil.net      22Oct14     2 mutt
pi         pts/3    complx.nepustil.net      22Oct14    11 ssh home

With the -n option, the FROM fields should be numerical IPs. But:

$ w -n 
10:25AM  up 10 days, 22:25, 19 users, load averages: 1.10, 0.74, 0.34
USER       TTY      FROM                      LOGIN@  IDLE WHAT
pi         pts/0    home.opsec.eu            26Oct14 21:53 -bash (bash)
pi         pts/2    complx.nepustil.net      22Oct14     2 mutt
pi         pts/3    complx.nepustil.net      22Oct14    11 ssh home

Similar on freefall etc.
Comment 1 oliver 2014-11-18 22:12:19 UTC
w does only lookup the IP if there is only one A/AAAA record. if there are multiple records (this means A and A or AAAA and AAAA but also A and AAAA), the lookup is bypassed. You may further call this an IPv6 unawareness of some kind, if there is exactly one IPv4 and one IPv6 entry.

The cause of this is the usage of utmpx. Which means there is only a hostname in the database, no ip address.

You are stranded if you do not have access to the underlying protocol family or have multiple A/AAAA-Records. The user MAY be connected via a totally different IP/Machine instead the IP displayed. So the current strategy is: instead you display wrong data, you display the original data unresolved. 

In fact I believe this is exactly the point why other implementations are missing this parameter.
Comment 2 Kurt Jaeger freebsd_committer 2014-11-18 22:41:57 UTC
(In reply to oliver from comment #1)
> w does only lookup the IP if there is only one A/AAAA record.

Thanks for the explaination. Apparently the man page needs a fix, or the
whole concept needs to be fixed 8-(
Comment 3 Kurt Jaeger freebsd_committer 2016-09-20 16:12:18 UTC
With r285550, more of the IPv6 can be seen, but the problem remains, that it displays IPs only for hostnames that return only one IP on reverse lookup.
Comment 4 Eitan Adler freebsd_committer freebsd_triage 2018-05-20 23:50:27 UTC
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017

Do
- Set Status to "Open"