Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Feb 2011 20:04:14 +0000 (UTC)
From:      Hajimu UMEMOTO <ume@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r219062 - stable/8/usr.bin/netstat
Message-ID:  <201102262004.p1QK4EMT091975@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ume
Date: Sat Feb 26 20:04:14 2011
New Revision: 219062
URL: http://svn.freebsd.org/changeset/base/219062

Log:
  MFC r217642:
    - Hide the internal scope address representation of the KAME IPv6
      stack from the output of `netstat -ani'.
    - The node-local multicast address in the output of `netstat -rn'
      should be handled as well.

Modified:
  stable/8/usr.bin/netstat/if.c
  stable/8/usr.bin/netstat/netstat.h
  stable/8/usr.bin/netstat/route.c
Directory Properties:
  stable/8/usr.bin/netstat/   (props changed)

Modified: stable/8/usr.bin/netstat/if.c
==============================================================================
--- stable/8/usr.bin/netstat/if.c	Sat Feb 26 18:54:54 2011	(r219061)
+++ stable/8/usr.bin/netstat/if.c	Sat Feb 26 20:04:14 2011	(r219062)
@@ -63,6 +63,9 @@ __FBSDID("$FreeBSD$");
 #include <err.h>
 #include <errno.h>
 #include <libutil.h>
+#ifdef INET6
+#include <netdb.h>
+#endif
 #include <signal.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -79,7 +82,7 @@ static void sidewaysintpr(int, u_long);
 static void catchalarm(int);
 
 #ifdef INET6
-static char ntop_buf[INET6_ADDRSTRLEN];		/* for inet_ntop() */
+static char addr_buf[NI_MAXHOST];		/* for getnameinfo() */
 #endif
 
 /*
@@ -347,13 +350,14 @@ intpr(int interval1, u_long ifnetaddr, v
 #ifdef INET6
 			case AF_INET6:
 				sockin6 = (struct sockaddr_in6 *)sa;
+				in6_fillscopeid(&ifaddr.in6.ia_addr);
 				printf("%-13.13s ",
 				       netname6(&ifaddr.in6.ia_addr,
 						&ifaddr.in6.ia_prefixmask.sin6_addr));
-				printf("%-17.17s ",
-				    inet_ntop(AF_INET6,
-					&sockin6->sin6_addr,
-					ntop_buf, sizeof(ntop_buf)));
+				in6_fillscopeid(sockin6);
+				getnameinfo(sa, sa->sa_len, addr_buf,
+				    sizeof(addr_buf), 0, 0, NI_NUMERICHOST);
+				printf("%-17.17s ", addr_buf);
 
 				network_layer = 1;
 				break;
@@ -475,13 +479,13 @@ intpr(int interval1, u_long ifnetaddr, v
 					break;
 #ifdef INET6
 				case AF_INET6:
+					in6_fillscopeid(&msa.in6);
+					getnameinfo(&msa.sa, msa.sa.sa_len,
+					    addr_buf, sizeof(addr_buf), 0, 0,
+					    NI_NUMERICHOST);
 					printf("%*s %-19.19s(refs: %d)\n",
 					       Wflag ? 27 : 25, "",
-					       inet_ntop(AF_INET6,
-							 &msa.in6.sin6_addr,
-							 ntop_buf,
-							 sizeof(ntop_buf)),
-					       ifma.ifma_refcount);
+					       addr_buf, ifma.ifma_refcount);
 					break;
 #endif /* INET6 */
 				case AF_LINK:

Modified: stable/8/usr.bin/netstat/netstat.h
==============================================================================
--- stable/8/usr.bin/netstat/netstat.h	Sat Feb 26 18:54:54 2011	(r219061)
+++ stable/8/usr.bin/netstat/netstat.h	Sat Feb 26 20:04:14 2011	(r219062)
@@ -106,6 +106,7 @@ void	mrt6_stats(u_long);
 
 struct sockaddr_in6;
 struct in6_addr;
+void in6_fillscopeid(struct sockaddr_in6 *);
 char *routename6(struct sockaddr_in6 *);
 const char *netname6(struct sockaddr_in6 *, struct in6_addr *);
 void	inet6print(struct in6_addr *, int, const char *, int);

Modified: stable/8/usr.bin/netstat/route.c
==============================================================================
--- stable/8/usr.bin/netstat/route.c	Sat Feb 26 18:54:54 2011	(r219061)
+++ stable/8/usr.bin/netstat/route.c	Sat Feb 26 20:04:14 2011	(r219062)
@@ -637,18 +637,8 @@ fmt_sockaddr(struct sockaddr *sa, struct
 	case AF_INET6:
 	    {
 		struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
-		struct in6_addr *in6 = &sa6->sin6_addr;
 
-		/*
-		 * XXX: This is a special workaround for KAME kernels.
-		 * sin6_scope_id field of SA should be set in the future.
-		 */
-		if (IN6_IS_ADDR_LINKLOCAL(in6) ||
-		    IN6_IS_ADDR_MC_LINKLOCAL(in6)) {
-		    /* XXX: override is ok? */
-		    sa6->sin6_scope_id = (u_int32_t)ntohs(*(u_short *)&in6->s6_addr[2]);
-		    *(u_short *)&in6->s6_addr[2] = 0;
-		}
+		in6_fillscopeid(sa6);
 
 		if (flags & RTF_HOST)
 		    cp = routename6(sa6);
@@ -899,6 +889,25 @@ netname(in_addr_t in, u_long mask)
 #undef NSHIFT
 
 #ifdef INET6
+void
+in6_fillscopeid(struct sockaddr_in6 *sa6)
+{
+#if defined(__KAME__)
+	/*
+	 * XXX: This is a special workaround for KAME kernels.
+	 * sin6_scope_id field of SA should be set in the future.
+	 */
+	if (IN6_IS_ADDR_LINKLOCAL(&sa6->sin6_addr) ||
+	    IN6_IS_ADDR_MC_NODELOCAL(&sa6->sin6_addr) ||
+	    IN6_IS_ADDR_MC_LINKLOCAL(&sa6->sin6_addr)) {
+		/* XXX: override is ok? */
+		sa6->sin6_scope_id =
+		    ntohs(*(u_int16_t *)&sa6->sin6_addr.s6_addr[2]);
+		sa6->sin6_addr.s6_addr[2] = sa6->sin6_addr.s6_addr[3] = 0;
+	}
+#endif
+}
+
 const char *
 netname6(struct sockaddr_in6 *sa6, struct in6_addr *mask)
 {



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