Module Name:    src
Committed By:   christos
Date:           Sat Oct 19 00:28:38 UTC 2013

Modified Files:
        src/usr.bin/fstat: fstat.c
        src/usr.bin/netstat: if.c inet6.c show.c

Log Message:
use new scopeid functions


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/fstat/fstat.c
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/netstat/show.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/fstat/fstat.c
diff -u src/usr.bin/fstat/fstat.c:1.101 src/usr.bin/fstat/fstat.c:1.102
--- src/usr.bin/fstat/fstat.c:1.101	Fri Oct 18 16:18:42 2013
+++ src/usr.bin/fstat/fstat.c	Fri Oct 18 20:28:38 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: fstat.c,v 1.101 2013/10/18 20:18:42 christos Exp $	*/
+/*	$NetBSD: fstat.c,v 1.102 2013/10/19 00:28:38 christos Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
 #if 0
 static char sccsid[] = "@(#)fstat.c	8.3 (Berkeley) 5/2/95";
 #else
-__RCSID("$NetBSD: fstat.c,v 1.101 2013/10/18 20:18:42 christos Exp $");
+__RCSID("$NetBSD: fstat.c,v 1.102 2013/10/19 00:28:38 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -88,6 +88,7 @@ __RCSID("$NetBSD: fstat.c,v 1.101 2013/1
 
 #ifdef INET6
 #include <netinet/ip6.h>
+#include <netinet6/in6.h>
 #include <netinet6/ip6_var.h>
 #include <netinet6/in6_pcb.h>
 #endif
@@ -895,7 +896,6 @@ inet6_addrstr(char *buf, size_t len, con
 {
 	char addr[256], serv[256];
 	struct sockaddr_in6 sin6;
-	uint16_t ad2;
 	const int niflags = nflg ? (NI_NUMERICHOST|NI_NUMERICSERV) : 0;
 
 	(void)memset(&sin6, 0, sizeof(sin6));
@@ -904,13 +904,7 @@ inet6_addrstr(char *buf, size_t len, con
 	sin6.sin6_addr = *a;
 	sin6.sin6_port = htons(p);
 
-	memcpy(&ad2, &sin6.sin6_addr.s6_addr[2], sizeof(ad2));
-	if (IN6_IS_ADDR_LINKLOCAL(a) && ad2 != 0) {
-		sin6.sin6_scope_id = ntohs(ad2);
-		sin6.sin6_addr.s6_addr[2] = 0;
-		sin6.sin6_addr.s6_addr[3] = 0;
-	}
-
+	inet6_putscopeid(&sin6, 1);
 	serv[0] = '\0';
 
 	if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.77 src/usr.bin/netstat/if.c:1.78
--- src/usr.bin/netstat/if.c:1.77	Fri Oct 18 16:26:45 2013
+++ src/usr.bin/netstat/if.c	Fri Oct 18 20:28:38 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.77 2013/10/18 20:26:45 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.78 2013/10/19 00:28:38 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.77 2013/10/18 20:26:45 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.78 2013/10/19 00:28:38 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -399,18 +399,10 @@ print_addr(struct sockaddr *sa, struct s
 #ifdef INET6
 	case AF_INET6:
 		sin6 = (struct sockaddr_in6 *)sa;
+		inet6_putscopeid(sin6, 1);
 #ifdef __KAME__
-		if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
-			uint16_t scope;
-			memcpy(&scope, &sin6->sin6_addr.s6_addr[2],
-			    sizeof(scope));
-			sin6->sin6_scope_id = ntohs(scope);
-			/* too little width */
-			if (!vflag)
-				sin6->sin6_scope_id = 0;
-			sin6->sin6_addr.s6_addr[2] = 0;
-			sin6->sin6_addr.s6_addr[3] = 0;
-		}
+		if (!vflag)
+			sin6->sin6_scope_id = 0;
 #endif
 
 		if (use_sysctl) {
@@ -454,17 +446,7 @@ print_addr(struct sockaddr *sa, struct s
 				as6.sin6_len = sizeof(struct sockaddr_in6);
 				as6.sin6_family = AF_INET6;
 				as6.sin6_addr = inm.in6m_addr;
-#ifdef __KAME__
-				if (IN6_IS_ADDR_MC_LINKLOCAL(&as6.sin6_addr)) {
-					uint16_t scope;
-					memcpy(&scope,
-					    &sin6->sin6_addr.s6_addr[2],
-					    sizeof(scope));
-					as6.sin6_scope_id = ntohs(scope);
-					as6.sin6_addr.s6_addr[2] = 0;
-					as6.sin6_addr.s6_addr[3] = 0;
-				}
-#endif
+				inet6_putscopeid(&as6, 2);
 				if (getnameinfo((struct sockaddr *)&as6,
 				    as6.sin6_len, hbuf,
 				    sizeof(hbuf), NULL, 0,

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.63 src/usr.bin/netstat/inet6.c:1.64
--- src/usr.bin/netstat/inet6.c:1.63	Fri Oct 18 16:26:45 2013
+++ src/usr.bin/netstat/inet6.c	Fri Oct 18 20:28:38 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.63 2013/10/18 20:26:45 christos Exp $	*/
+/*	$NetBSD: inet6.c,v 1.64 2013/10/19 00:28:38 christos Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.63 2013/10/18 20:26:45 christos Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.64 2013/10/19 00:28:38 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -1420,17 +1420,7 @@ inet6name(const struct in6_addr *in6p)
 		sin6.sin6_len = sizeof(sin6);
 		sin6.sin6_family = AF_INET6;
 		sin6.sin6_addr = *in6p;
-#ifdef __KAME__
-		if (IN6_IS_ADDR_LINKLOCAL(in6p) ||
-		    IN6_IS_ADDR_MC_LINKLOCAL(in6p)) {
-			uint16_t scope;
-			memcpy(&scope, &sin6.sin6_addr.s6_addr[2],
-			    sizeof(scope));
-			sin6.sin6_scope_id = ntohs(scope);
-			sin6.sin6_addr.s6_addr[2] = 0;
-			sin6.sin6_addr.s6_addr[3] = 0;
-		}
-#endif
+		inet6_putscopeid(&sin6, 3);
 		if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
 				hbuf, sizeof(hbuf), NULL, 0, niflag) != 0)
 			strlcpy(hbuf, "?", sizeof(hbuf));

Index: src/usr.bin/netstat/show.c
diff -u src/usr.bin/netstat/show.c:1.16 src/usr.bin/netstat/show.c:1.17
--- src/usr.bin/netstat/show.c:1.16	Fri Oct 18 16:26:45 2013
+++ src/usr.bin/netstat/show.c	Fri Oct 18 20:28:38 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: show.c,v 1.16 2013/10/18 20:26:45 christos Exp $	*/
+/*	$NetBSD: show.c,v 1.17 2013/10/19 00:28:38 christos Exp $	*/
 /*	$OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $	*/
 
 /*
@@ -330,22 +330,12 @@ p_sockaddr(struct sockaddr *sa, struct s
 	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? */
-			uint16_t scope;
-			memcpy(&scope, &sa6->sin6_addr.s6_addr[2],
-			    sizeof(scope));
-			sa6->sin6_scope_id = ntohs(scope);
-			in6->s6_addr[2] = 0;
-			in6->s6_addr[3] = 0;
-		}
+		inet6_putscopeid(sa6, 3);
 		if (flags & RTF_HOST)
 			cp = routename((struct sockaddr *)sa6);
 		else
@@ -435,17 +425,8 @@ routename(struct sockaddr *sa)
 		memcpy(&sin6, sa, sa->sa_len);
 		sin6.sin6_len = sizeof(struct sockaddr_in6);
 		sin6.sin6_family = AF_INET6;
-		if (sa->sa_len == sizeof(struct sockaddr_in6) &&
-		    (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr) ||
-		     IN6_IS_ADDR_MC_LINKLOCAL(&sin6.sin6_addr)) &&
-		    sin6.sin6_scope_id == 0) {
-			uint16_t scope;
-			memcpy(&scope, &sin6.sin6_addr.s6_addr[2],
-			    sizeof(scope));
-			sin6.sin6_scope_id = ntohs(scope);
-			sin6.sin6_addr.s6_addr[2] = 0;
-			sin6.sin6_addr.s6_addr[3] = 0;
-		}
+		if (sa->sa_len == sizeof(struct sockaddr_in6))
+			inet6_putscopeid(&sin6, 3);
 		return (routename6(&sin6));
 	    }
 

Reply via email to