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

Re: who/w/finger/last printing ip address


On Wed, Sep 09, 2015 at 01:18:34PM +0100, Michael Grant wrote:
> On Wed, Sep 9, 2015 at 12:24 PM, Reco <recoverym4n@gmail.com> wrote:
>      Hi.
>     On Wed, Sep 09, 2015 at 10:46:53AM +0100, Michael Grant wrote:
>     > (I of course edited my own host's ip address here for
>     >
>     > But yes, getent resolves my host ip to a name.  who/w/finger/last all still do not resolve the host.
>     Ok, then we'll have to do it the hard way.
>     Please post the output of 'strace w'.
> $ getent hosts
>   host10-20-30-40.example.com
> $ w
>  05:46:33 up 3 days, 22:18,  4 users,  load average: 0.04, 0.07, 0.06
> USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
> mgrant   pts/1 Sat07   22:05m  0.09s  0.09s /bin/bash
> mgrant   pts/2 Sat07   22:05m  0.27s  0.05s /bin/bash
> mgrant   pts/3 Sat07    0.00s  6.00s  0.07s /bin/bash
> mgrant   pts/4 Sat07    3days  0.57s  0.57s emacs
> $ strace w
> execve("/usr/bin/w", ["w"], [/* 25 vars */]) = 0
> exit_group(0)                           = ?
> +++ exited with 0 +++

Ok. This strace output clearly shows that 'w' does not even trying to
resolve IPs to hostnames.

Hence, even more hard way should be tried - looking at the source.

'w' you're using should belong to 'procps' package, source of which is


The source file for 'w' is, unsurprisingly, 'w.c', which has this check:

        if (from)
            print_from(u, ip_addresses, fromlen);

So, basically they decide to print hostnames only of 'from' variable is
set to 0, which is set in 'main' function to '1' initially:

    /* switches (defaults) */
    int header = 1;
    int longform = 1;
    int from = 1;

For reasons unknown, 'from' can be set to 0 initially if one is using
W_SHOWFROM compilation flag. This flag is set for squeeze's procps, but
unset starting with wheezy (as far as I can tell):

#ifndef W_SHOWFROM
    from = 0;

'-f' flag for 'w', which, according to the manpage, should enable
IP->hostname resolving, merely inverts 'from' flag:

    while ((ch =
        getopt_long(argc, argv, "husfoVi", longopts, NULL)) != -1)
        switch (ch) {
        case 'h':
            header = 0;
        case 'l':
            longform = 1;
        case 's':
            longform = 0;
        case 'f':
            from = !from;

And, as the cherry on a pie, there's this commit
e14b7c261042020b19f73a032be53d7728b6c29f, dated 6 Jan 2012, aptly named
"Imported Upstream version 3.3.2", which changed default 'from' value
from '0' to '1'.

So, long story short, last version of 'w' which printed hostnames by
default should be squeeze's one, and even then they used compilation
flag to make it do so.


Reply to: