NetBSD Problem Report #9199

Received: (qmail 10791 invoked from network); 15 Jan 2000 17:46:06 -0000
Message-Id: <200001151745.CAA02211@uzuki.hiru.aoba.yokohama.jp>
Date: 2000年1月16日 02:45:31 +0900 (JST)
From: ura@hiru.aoba.yokohama.jp
Reply-To: ura@hiru.aoba.yokohama.jp
To: gnats-bugs@gnats.netbsd.org
Subject: fstat(1) lacks IPv6 support
X-Send-Pr-Version: 3.95
>Number: 9199
>Category: bin
>Synopsis: fstat(1) lacks IPv6 support
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: itojun
>State: closed
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sat Jan 15 13:09:04 +0000 2000
>Closed-Date: Mon Jan 17 16:14:51 +0000 2000
>Last-Modified: Mon Jan 17 16:15:22 +0000 2000
>Originator: URA Hiroshi
>Release: NetBSD-current 1.4P (1999年12月17日)
>Organization:
URA Hiroshi		E-mail: ura@hiru.aoba.yokohama.jp
>Environment:
System: NetBSD uzuki.hiru.aoba.yokohama.jp 1.4P NetBSD 1.4P (UZUKI) #26: Fri Dec 17 18:55:34 JST 1999 root@:/usr/local/src/NetBSD/current/src/sys/arch/sparc/compile/UZUKI sparc
>Description:
 When the file discriptor points the internet socket, fstat(1) indicates
the IPv4 address and port for the local end and/or the remote. But, when
the file discriptor points the internet6 socket, fstat(1) doesn't indicate.
If the IPv6 address specfies, the IPv6 address is wrapped in square bracket
(e.g. [2345:678:9ab:1000::1]). If the IPv6 address doesn't specfiy, a ``*''
is used for indication. 
>How-To-Repeat:
 Try the following commands.
 # fstat | egrep internet6
>Fix:
 Apply this patch.
Index: fstat.c
===================================================================
RCS file: /cvsroot/netbsd/basesrc/usr.bin/fstat/fstat.c,v
retrieving revision 1.37
diff -u -u -r1.37 fstat.c
--- fstat.c	1999年08月02日 17:39:13	1.37
+++ fstat.c	2000年01月15日 10:42:49
@@ -81,6 +81,10 @@
 #include <netinet/ip.h>
 #include <netinet/in_pcb.h>
+#include <netinet/ip6.h>
+#include <netinet6/in6_systm.h>
+#include <netinet6/in6_pcb.h>
+
 #include <arpa/inet.h>
 #include <ctype.h>
@@ -618,9 +622,12 @@
 	struct protosw	proto;
 	struct domain	dom;
 	struct inpcb	inpcb;
+	struct in6pcb	in6pcb;
 	struct unpcb	unpcb;
 	int len;
 	char dname[32];
+	char addrbuf[INET6_ADDRSTRLEN];
+	char xaddrbuf[INET6_ADDRSTRLEN + 2];
 	PREFIX(i);
@@ -682,8 +689,7 @@
 			 inpcb.inp_laddr.s_addr == INADDR_ANY ? "*" :
 			 inet_ntoa(inpcb.inp_laddr), ntohs(inpcb.inp_lport));
 			if (inpcb.inp_fport) {
-				printf(" <-> ");
-				printf("%s:%d",
+				printf(" <-> %s:%d",
 				 inpcb.inp_faddr.s_addr == INADDR_ANY ? "*" :
 				 inet_ntoa(inpcb.inp_faddr),
 				 ntohs(inpcb.inp_fport));
@@ -705,6 +711,61 @@
 				 inpcb.inp_faddr.s_addr == INADDR_ANY ? "*" :
 				 inet_ntoa(inpcb.inp_faddr),
 				 ntohs(inpcb.inp_fport));
+		} else if (so.so_pcb)
+			printf(" %lx", (long)so.so_pcb);
+		break;
+	case AF_INET6:
+		getinetproto(proto.pr_protocol);
+		if (proto.pr_protocol == IPPROTO_TCP) {
+			if (so.so_pcb == NULL)
+				break;
+			if (kvm_read(kd, (u_long)so.so_pcb, (char *)&in6pcb,
+			 sizeof(struct in6pcb)) != sizeof(struct in6pcb)) {
+				dprintf("can't read in6pcb at %p", so.so_pcb);
+				goto bad;
+			}
+			printf(" %lx", (long)in6pcb.in6p_ppcb);
+			sprintf(xaddrbuf, "[%s]", 
+ 			 inet_ntop(AF_INET6, &in6pcb.in6p_laddr,
+				addrbuf, sizeof(addrbuf)));
+			printf(" %s:%d",
+			 IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_laddr) ? "*" :
+			 xaddrbuf,
+			 ntohs(in6pcb.in6p_lport));
+			if (in6pcb.in6p_fport) {
+				sprintf(xaddrbuf, "[%s]", 
+				 inet_ntop(AF_INET6, &in6pcb.in6p_faddr,
+					addrbuf, sizeof(addrbuf)));
+				printf(" <-> %s:%d",
+			 IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_faddr) ? "*" :
+				 xaddrbuf,
+				 ntohs(in6pcb.in6p_fport));
+			}
+		} else if (proto.pr_protocol == IPPROTO_UDP) {
+			if (so.so_pcb == NULL)
+				break;
+			if (kvm_read(kd, (u_long)so.so_pcb, (char *)&in6pcb,
+			 sizeof(struct in6pcb)) != sizeof(struct in6pcb)) {
+				dprintf("can't read inpcb at %p", so.so_pcb);
+				goto bad;
+			}
+			printf(" %lx", (long)so.so_pcb);
+			sprintf(xaddrbuf, "[%s]", 
+			 inet_ntop(AF_INET6, &in6pcb.in6p_laddr,
+				addrbuf, sizeof(addrbuf)));
+			printf(" %s:%d",
+		 IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_laddr) ? "*" :
+			 xaddrbuf,
+			 ntohs(in6pcb.in6p_lport));
+			if (in6pcb.in6p_fport) {
+				sprintf(xaddrbuf, "[%s]", 
+				 inet_ntop(AF_INET6, &in6pcb.in6p_faddr,
+					addrbuf, sizeof(addrbuf)));
+				printf(" <-> %s:%d",
+			 IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_faddr) ? "*" :
+				 xaddrbuf,
+				 ntohs(in6pcb.in6p_fport));
+			}
 		} else if (so.so_pcb)
 			printf(" %lx", (long)so.so_pcb);
 		break;
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: bin-bug-people->itojun 
Responsible-Changed-By: itojun 
Responsible-Changed-When: Sun Jan 16 04:49:48 PST 2000 
Responsible-Changed-Why: 
mine. will commit after some cleanups 
State-Changed-From-To: open->closed 
State-Changed-By: itojun 
State-Changed-When: Mon Jan 17 08:14:51 PST 2000 
State-Changed-Why: 
committed with minor change (use getnameinfo for scope friendliness). 
>Unformatted:


(Contact us) $NetBSD: query-full-pr,v 1.39 2013年11月01日 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006年05月07日 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.

AltStyle によって変換されたページ (->オリジナル) /