Date: Mon, 8 Feb 1999 14:52:52 +0200 (EET) From: Ruslan Ermilov <ru@ucb.crimea.ua> To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/9963: [PATCH,31-WANTED] netstat(1) and fstat(1) are no longer compatible Message-ID: <199902081252.OAA88956@relay.ucb.crimea.ua>
next in thread | raw e-mail | index | archive | help
>Number: 9963 >Category: bin >Synopsis: [PATCH,31-WANTED] netstat(1) and fstat(1) are no longer compatible >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Feb 8 05:00:00 PST 1999 >Closed-Date: >Last-Modified: >Originator: Ruslan Ermilov >Release: FreeBSD 3.0-STABLE i386 >Organization: United Commercial Bank >Environment: RELENG_3 HEAD >Description: On 2.2.X fstat(1) could be used in conjunction with netstat(1) to check ownership of particular socket. For example: # fstat -p 17714 USER CMD PID FD MOUNT INUM MODE SZ|DV R/W root telnetd 17714 root / 2 drwxr-xr-x 512 r root telnetd 17714 wd / 2 drwxr-xr-x 512 r root telnetd 17714 text /usr 299554 -r-xr-xr-x 35360 r root telnetd 17714 0* internet stream tcp f4060de0 root telnetd 17714 1* internet stream tcp f4060de0 root telnetd 17714 2* internet stream tcp f4060de0 root telnetd 17714 3 / 527 crw-rw-rw- ptyp0 rw root telnetd 17714 14* pipe f4200e80 <-> f4200f20 0 rw # netstat -An | grep f4060de0 f4060de0 tcp 0 0 192.168.1.1.23 192.168.1.250.1025 ESTABLISHED This doesn't work for tcp sockets on 3.0-STABLE. The problem first appeared in src/usr.bin/netstat/inet.c, revision 1.27: ---------------------------- revision 1.27 date: 1998/05/15 20:19:15; author: wollman; state: Exp; lines: +115 -62 mbuf, inet, and unix modules no longer read kvm. ============================================================================= In particular, the following change caused problem: { 142,147c174,176 { < if (istcp) { < printf("%8x ", (int)inpcb.inp_ppcb); { < else { < printf("%8x ", (int)next); { < printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc, { < sockb.so_snd.sb_cc); { --- { > printf("%8lx ", (u_long)so->so_pcb); { > printf("%-5.5s %6ld %6ld ", name, so->so_rcv.sb_cc, { > so->so_snd.sb_cc); >How-To-Repeat: Repeat the example above on 3.0-STABLE or 4.0-CURRENT. >Fix: Either netstat or fstat (NOT BOTH) should be patched to make them compatible. The first patch is for netstat, it restores the functionality that was lost in revision 1.27: Index: inet.c =================================================================== RCS file: /usr/FreeBSD-CVS/src/usr.bin/netstat/inet.c,v retrieving revision 1.30 diff -u -r1.30 inet.c --- inet.c 1998/07/06 21:01:23 1.30 +++ inet.c 1999/02/08 11:42:30 @@ -170,8 +170,12 @@ "Local Address", "Foreign Address", "(state)"); first = 0; } - if (Aflag) - printf("%8lx ", (u_long)so->so_pcb); + if (Aflag) { + if (istcp) + printf("%8lx ", (u_long)inp->inp_ppcb); + else + printf("%8lx ", (u_long)so->so_pcb); + } printf("%-5.5s %6ld %6ld ", name, so->so_rcv.sb_cc, so->so_snd.sb_cc); if (nflag) { The second patch is for fstat. It causes socket pcb address to be displayed for tcp sockets, instead of tcpcb: Index: fstat.1 =================================================================== RCS file: /usr/FreeBSD-CVS/src/usr.bin/fstat/fstat.1,v retrieving revision 1.6 diff -u -r1.6 fstat.1 --- fstat.1 1998/01/25 16:38:42 1.6 +++ fstat.1 1999/02/08 12:12:57 @@ -183,7 +183,7 @@ is the socket type (stream, dgram, etc), and the third is the socket flags field (in hex). The remaining fields are protocol dependent. -For tcp, it is the address of the tcpcb, and for udp, the inpcb (socket pcb). +For tcp and udp, it is the address of the inpcb (socket pcb). For unix domain sockets, its the address of the socket pcb and the address of the connected pcb (if connected). Otherwise the protocol number and address of the socket itself are printed. Index: fstat.c =================================================================== RCS file: /usr/FreeBSD-CVS/src/usr.bin/fstat/fstat.c,v retrieving revision 1.16 diff -u -r1.16 fstat.c --- fstat.c 1998/07/06 21:01:16 1.16 +++ fstat.c 1999/02/08 12:37:33 @@ -663,9 +663,9 @@ /* * protocol specific formatting * - * Try to find interesting things to print. For tcp, the interesting - * thing is the address of the tcpcb, for udp and others, just the - * inpcb (socket pcb). For unix domain, its the address of the socket + * Try to find interesting things to print. + * For tcp, udp and others, it is just the address of the inpcb + * (socket pcb). For unix domain, it is the address of the socket * pcb and the address of the connected pcb (if connected). Otherwise * just print the protocol number and address of the socket itself. * The idea is not to duplicate netstat, but to make available enough @@ -674,20 +674,7 @@ switch(dom.dom_family) { case AF_INET: getinetproto(proto.pr_protocol); - if (proto.pr_protocol == IPPROTO_TCP ) { - if (so.so_pcb) { - if (kvm_read(kd, (u_long)so.so_pcb, - (char *)&inpcb, sizeof(struct inpcb)) - != sizeof(struct inpcb)) { - dprintf(stderr, - "can't read inpcb at %p\n", - (void *)so.so_pcb); - goto bad; - } - printf(" %x", (int)inpcb.inp_ppcb); - } - } - else if (so.so_pcb) + if (so.so_pcb) printf(" %x", (int)so.so_pcb); break; case AF_UNIX: >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199902081252.OAA88956>