Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Nov 2009 17:18:49 -0800
From:      Juli Mallett <jmallett@FreeBSD.org>
To:        Hajimu UMEMOTO <ume@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r199655 - head/usr.bin/w
Message-ID:  <eaa228be0911241718i10795347hdd0f5735adee51e4@mail.gmail.com>
In-Reply-To: <200911221651.nAMGpiIO023873@svn.freebsd.org>
References:  <200911221651.nAMGpiIO023873@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
I'm not sure this is right.  While the manpage implies that doing no
resolution means that it will show numeric addresses, since that is
not correct, there are two ways to go.  As you have done, you can
choose to try to resolve hostnames to IP addresses.  You could also do
as the code before did and do no resolution.  I frequently use 'w -n'
on systems with slow nameservers to see who is logged in without
triggering a bunch of DNS traffic that I then have to wait for.
Trying to resolve the name to a numeric address presents that problem.
 Since it is not possible to always show a numeric address (if, for
example, the hostname is no longer valid) I'm not sure that this is
the right direction to try to go with 'w -n'.

On Sun, Nov 22, 2009 at 08:51, Hajimu UMEMOTO <ume@freebsd.org> wrote:
> Author: ume
> Date: Sun Nov 22 16:51:44 2009
> New Revision: 199655
> URL: http://svn.freebsd.org/changeset/base/199655
>
> Log:
> =A0When -n is specified, attempt to turn hostnames found in utmp into IP
> =A0addresses, again. =A0However, change a hostname into an IP address, on=
ly
> =A0when a host has just one A/AAAA RR.
>
> =A0Requested by: candy__at__kgc.co.jp
> =A0MFC after: =A0 =A02 weeks
>
> Modified:
> =A0head/usr.bin/w/w.c
>
> Modified: head/usr.bin/w/w.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/usr.bin/w/w.c =A0Sun Nov 22 16:13:16 2009 =A0 =A0 =A0 =A0(r19965=
4)
> +++ head/usr.bin/w/w.c =A0Sun Nov 22 16:51:44 2009 =A0 =A0 =A0 =A0(r19965=
5)
> @@ -348,6 +348,7 @@ main(int argc, char *argv[])
>
> =A0 =A0 =A0 =A0for (ep =3D ehead; ep !=3D NULL; ep =3D ep->next) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0char host_buf[UT_HOSTSIZE + 1];
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct addrinfo hints, *res;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct sockaddr_storage ss;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct sockaddr *sa =3D (struct sockaddr *=
)&ss;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct sockaddr_in *lsin =3D (struct socka=
ddr_in *)&ss;
> @@ -365,23 +366,42 @@ main(int argc, char *argv[])
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0x_suffix =
=3D NULL;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 isaddr =3D 0;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 memset(&ss, '\0', sizeof(ss));
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (inet_pton(AF_INET6, p, &lsin6->sin6_add=
r) =3D=3D 1) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lsin6->sin6_len =3D sizeof(=
*lsin6);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lsin6->sin6_family =3D AF_I=
NET6;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 isaddr =3D 1;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } else if (inet_pton(AF_INET, p, &lsin->sin=
_addr) =3D=3D 1) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lsin->sin_len =3D sizeof(*l=
sin);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lsin->sin_family =3D AF_INE=
T;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 isaddr =3D 1;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (!nflag) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* Attempt to change an IP=
 address into a name */
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 isaddr =3D 0;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 memset(&ss, '\0', sizeof(ss=
));
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (inet_pton(AF_INET6, p, =
&lsin6->sin6_addr) =3D=3D 1) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lsin6->sin6=
_len =3D sizeof(*lsin6);
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lsin6->sin6=
_family =3D AF_INET6;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 isaddr =3D =
1;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } else if (inet_pton(AF_INE=
T, p, &lsin->sin_addr) =3D=3D 1) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lsin->sin_l=
en =3D sizeof(*lsin);
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lsin->sin_f=
amily =3D AF_INET;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 isaddr =3D =
1;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (isaddr && realhostname=
_sa(fn, sizeof(fn), sa,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0sa->sa_len) =3D=3D=
 HOSTNAME_FOUND)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0p =3D fn;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } else if (!isaddr) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /*
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* If a host has only one=
 A/AAAA RR, change a
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* name into an IP addres=
s
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 memset(&hints, 0, sizeof(hi=
nts));
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 hints.ai_flags =3D AI_PASSI=
VE;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 hints.ai_family =3D AF_UNSP=
EC;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 hints.ai_socktype =3D SOCK_=
STREAM;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (getaddrinfo(p, NULL, &h=
ints, &res) =3D=3D 0) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (res->ai=
_next =3D=3D NULL &&
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 get=
nameinfo(res->ai_addr, res->ai_addrlen,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 fn, sizeof(fn), NULL, 0,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 NI_NUMERICHOST) =3D=3D 0)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 p =3D fn;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 freeaddrinf=
o(res);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> +
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (x_suffix) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(void)snprintf(buf, sizeof=
(buf), "%s:%s", p, x_suffix);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0p =3D buf;
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?eaa228be0911241718i10795347hdd0f5735adee51e4>