From owner-svn-src-head@FreeBSD.ORG Wed Nov 25 01:19:09 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D5C67106566B; Wed, 25 Nov 2009 01:19:09 +0000 (UTC) (envelope-from juli@clockworksquid.com) Received: from mail-px0-f182.google.com (mail-px0-f182.google.com [209.85.216.182]) by mx1.freebsd.org (Postfix) with ESMTP id A85508FC1A; Wed, 25 Nov 2009 01:19:09 +0000 (UTC) Received: by pxi12 with SMTP id 12so5245721pxi.3 for ; Tue, 24 Nov 2009 17:19:09 -0800 (PST) MIME-Version: 1.0 Sender: juli@clockworksquid.com Received: by 10.142.60.19 with SMTP id i19mr754552wfa.315.1259111949196; Tue, 24 Nov 2009 17:19:09 -0800 (PST) In-Reply-To: <200911221651.nAMGpiIO023873@svn.freebsd.org> References: <200911221651.nAMGpiIO023873@svn.freebsd.org> From: Juli Mallett Date: Tue, 24 Nov 2009 17:18:49 -0800 X-Google-Sender-Auth: d649427cbcafb050 Message-ID: To: Hajimu UMEMOTO Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r199655 - head/usr.bin/w X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2009 01:19:09 -0000 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 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; >