From owner-svn-src-all@FreeBSD.ORG Sat Aug 17 17:23:43 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 9BD0A622; Sat, 17 Aug 2013 17:23:43 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 6F477222F; Sat, 17 Aug 2013 17:23:43 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7HHNhJ6033894; Sat, 17 Aug 2013 17:23:43 GMT (envelope-from hrs@svn.freebsd.org) Received: (from hrs@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r7HHNhFC033893; Sat, 17 Aug 2013 17:23:43 GMT (envelope-from hrs@svn.freebsd.org) Message-Id: <201308171723.r7HHNhFC033893@svn.freebsd.org> From: Hiroki Sato Date: Sat, 17 Aug 2013 17:23:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r254459 - head/usr.bin/netstat X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Aug 2013 17:23:43 -0000 Author: hrs Date: Sat Aug 17 17:23:42 2013 New Revision: 254459 URL: http://svnweb.freebsd.org/changeset/base/254459 Log: - Use getnameinfo(3) instead of gethostbyaddr(3) or inet_ntop(3). - Fill sin6_scope_id from in6p.sin6_addr.s6_addr[2]. struct inpcb has struct in6_addr for the endpoint addresses, so sin6_scope_id must be filled. Modified: head/usr.bin/netstat/inet6.c Modified: head/usr.bin/netstat/inet6.c ============================================================================== --- head/usr.bin/netstat/inet6.c Sat Aug 17 17:09:26 2013 (r254458) +++ head/usr.bin/netstat/inet6.c Sat Aug 17 17:23:42 2013 (r254459) @@ -1120,12 +1120,17 @@ inet6print(struct in6_addr *in6, int por char * inet6name(struct in6_addr *in6p) { - char *cp; + struct sockaddr_in6 sin6; + char hbuf[NI_MAXHOST], *cp; static char line[50]; - struct hostent *hp; static char domain[MAXHOSTNAMELEN]; static int first = 1; + int flags, error; + if (IN6_IS_ADDR_UNSPECIFIED(in6p)) { + strcpy(line, "*"); + return (line); + } if (first && !numeric_addr) { first = 0; if (gethostname(domain, MAXHOSTNAMELEN) == 0 && @@ -1134,24 +1139,26 @@ inet6name(struct in6_addr *in6p) else domain[0] = 0; } - cp = 0; - if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) { - hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6); - if (hp) { - if ((cp = strchr(hp->h_name, '.')) && - !strcmp(cp + 1, domain)) - *cp = 0; - cp = hp->h_name; - } - } - if (IN6_IS_ADDR_UNSPECIFIED(in6p)) - strcpy(line, "*"); - else if (cp) - strcpy(line, cp); - else + memset(&sin6, 0, sizeof(sin6)); + memcpy(&sin6.sin6_addr, in6p, sizeof(*in6p)); + sin6.sin6_family = AF_INET6; + /* XXX: in6p.s6_addr[2] can contain scopeid. */ + in6_fillscopeid(&sin6); + flags = (numeric_addr) ? NI_NUMERICHOST : 0; + error = getnameinfo((struct sockaddr *)&sin6, sizeof(sin6), hbuf, + sizeof(hbuf), NULL, 0, flags); + if (error == 0) { + if ((flags & NI_NUMERICHOST) == 0 && + (cp = strchr(hbuf, '.')) && + !strcmp(cp + 1, domain)) + *cp = 0; + strcpy(line, hbuf); + } else { + /* XXX: this should not happen. */ sprintf(line, "%s", - inet_ntop(AF_INET6, (void *)in6p, ntop_buf, + inet_ntop(AF_INET6, (void *)&sin6.sin6_addr, ntop_buf, sizeof(ntop_buf))); + } return (line); } #endif /*INET6*/