NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/38093: netstat shows server sockets when not asked



>Number:         38093
>Category:       bin
>Synopsis:       netstat shows server sockets when not asked
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 23 21:20:00 +0000 2008
>Originator:     dieter roelants
>Release:        NetBSD 4.99.54, NetBSD 4.0_STABLE
>Organization:
>Environment:
System: NetBSD simult.amelgem.be 4.99.54 NetBSD 4.99.54 (SIMULT) #57: Wed Feb 
13 20:48:11 CET 2008 
dieter%simult.amelgem.be@localhost:/build/obj.i386.current/sys/arch/i386/compile/SIMULT
 i386
Architecture: i386
Machine: i386
>Description:
        According to the man page, netstat doesn't show server
        sockets unless the -a option is used. This is not the case.
        When sysctl is used to gather the information from the
        kernel, all sockets are displayed. When the info comes from
        /dev/kmem, server sockets not bound to the any addr are
        also shown.
>How-To-Repeat:
        Run netstat without -a on a machine with listening sockets.
        See them being displayed.
>Fix:

(The patch to iso.c is compile-tested only.)

Index: inet.c
===================================================================
RCS file: /cvsroot/src/usr.bin/netstat/inet.c,v
retrieving revision 1.78
diff -u -r1.78 inet.c
--- inet.c      10 Jul 2007 21:12:33 -0000      1.78
+++ inet.c      23 Feb 2008 21:10:03 -0000
@@ -222,6 +222,9 @@
                                first = 0;
                        }
 
+                       if (!aflag && inet_lnaof(dst.sin_addr) == INADDR_ANY)
+                               continue;
+
                        protopr0((intptr_t) pcblist[i].ki_ppcbaddr,
                                 pcblist[i].ki_rcvq, pcblist[i].ki_sndq,
                                 &src.sin_addr, src.sin_port,
@@ -254,7 +257,7 @@
                        continue;
 
                if (!aflag &&
-                   inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)
+                   inet_lnaof(inpcb.inp_faddr) == INADDR_ANY)
                        continue;
                kread((u_long)inpcb.inp_socket, (char *)&sockb, sizeof (sockb));
                if (istcp) {
Index: inet6.c
===================================================================
RCS file: /cvsroot/src/usr.bin/netstat/inet6.c,v
retrieving revision 1.42
diff -u -r1.42 inet6.c
--- inet6.c     7 Mar 2007 22:22:50 -0000       1.42
+++ inet6.c     23 Feb 2008 21:10:18 -0000
@@ -280,6 +280,9 @@
                                first = 0;
                        }
 
+                       if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&dst.sin6_addr))
+                               continue;
+
                        ip6protopr0((intptr_t) pcblist[i].ki_ppcbaddr,
                            pcblist[i].ki_rcvq, pcblist[i].ki_sndq,
                            &src.sin6_addr, src.sin6_port,
@@ -311,7 +314,7 @@
                if (in6pcb.in6p_af != AF_INET6)
                        continue;
 
-               if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_laddr))
+               if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_faddr))
                        continue;
                kread((u_long)in6pcb.in6p_socket, (char *)&sockb, 
                    sizeof (sockb));
Index: iso.c
===================================================================
RCS file: /cvsroot/src/usr.bin/netstat/iso.c,v
retrieving revision 1.27
diff -u -r1.27 iso.c
--- iso.c       18 Feb 2007 01:56:17 -0000      1.27
+++ iso.c       23 Feb 2008 21:10:18 -0000
@@ -376,7 +376,7 @@
        struct inpcb inpcb;
 
        kget(tpcb.tp_npcb, inpcb);
-       if (!aflag && inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)
+       if (!aflag && inet_lnaof(inpcb.inp_faddr) == INADDR_ANY)
                return;
        if (Aflag)
                printf("%8lx ", pcb);



Home | Main Index | Thread Index | Old Index