Module Name: src Committed By: manu Date: Sun May 29 04:45:08 UTC 2011
Modified Files: src/usr.bin/netstat: unix.c src/usr.bin/sockstat: sockstat.c Log Message: Display SOCK_SEQPACKET local sockets in sockstat and netstat To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/usr.bin/netstat/unix.c cvs rdiff -u -r1.16 -r1.17 src/usr.bin/sockstat/sockstat.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/netstat/unix.c diff -u src/usr.bin/netstat/unix.c:1.32 src/usr.bin/netstat/unix.c:1.33 --- src/usr.bin/netstat/unix.c:1.32 Wed May 4 01:11:29 2011 +++ src/usr.bin/netstat/unix.c Sun May 29 04:45:08 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: unix.c,v 1.32 2011/05/04 01:11:29 dyoung Exp $ */ +/* $NetBSD: unix.c,v 1.33 2011/05/29 04:45:08 manu Exp $ */ /*- * Copyright (c) 1983, 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "from: @(#)unix.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: unix.c,v 1.32 2011/05/04 01:11:29 dyoung Exp $"); +__RCSID("$NetBSD: unix.c,v 1.33 2011/05/29 04:45:08 manu Exp $"); #endif #endif /* not lint */ @@ -152,66 +152,70 @@ struct kinfo_pcb *pcblist; int mib[8]; size_t namelen = 0, size = 0, i; - const char *mibname = "net.local.stream.pcblist"; + const char *mibnames[] = { + "net.local.stream.pcblist", + "net.local.dgram.pcblist", + "net.local.seqpacket.pcblist", + NULL, + }; + const char **mibname; static int first = 1; - int done = 0; - again: - memset(mib, 0, sizeof(mib)); + for (mibname = mibnames; *mibname; mibname++) { + memset(mib, 0, sizeof(mib)); - if (sysctlnametomib(mibname, mib, - &namelen) == -1) - err(1, "sysctlnametomib: %s", mibname); - - if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib), - NULL, &size, NULL, 0) == -1) - err(1, "sysctl (query)"); - - if ((pcblist = malloc(size)) == NULL) - err(1, "malloc"); - memset(pcblist, 0, size); - - mib[6] = sizeof(*pcblist); - mib[7] = size / sizeof(*pcblist); - - if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib), pcblist, - &size, NULL, 0) == -1) - err(1, "sysctl (copy)"); - - for (i = 0; i < size / sizeof(*pcblist); i++) { - struct kinfo_pcb *ki = &pcblist[i]; - struct sockaddr_un *sun; - int remote = 0; - - if (first) { - unixdomainprhdr(); - first = 0; + if (sysctlnametomib(*mibname, mib, + &namelen) == -1) + err(1, "sysctlnametomib: %s", *mibname); + + if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib), + NULL, &size, NULL, 0) == -1) + err(1, "sysctl (query)"); + + if ((pcblist = malloc(size)) == NULL) + err(1, "malloc"); + memset(pcblist, 0, size); + + mib[6] = sizeof(*pcblist); + mib[7] = size / sizeof(*pcblist); + + if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib), + pcblist, &size, NULL, 0) == -1) + err(1, "sysctl (copy)"); + + for (i = 0; i < size / sizeof(*pcblist); i++) { + struct kinfo_pcb *ki = &pcblist[i]; + struct sockaddr_un *sun; + int remote = 0; + + if (first) { + unixdomainprhdr(); + first = 0; + } + + sun = (struct sockaddr_un *)&ki->ki_dst; + if (sun->sun_path[0] != '\0') { + remote = 1; + } else { + sun = (struct sockaddr_un *)&ki->ki_src; + } + + unixdomainpr0(ki->ki_pcbaddr, ki->ki_type, + ki->ki_rcvq, ki->ki_sndq, + ki->ki_vnode, ki->ki_conn, + ki->ki_refs, ki->ki_nextref, + ki->ki_sockaddr, sun, remote); } - sun = (struct sockaddr_un *)&ki->ki_dst; - if (sun->sun_path[0] != '\0') { - remote = 1; - } else { - sun = (struct sockaddr_un *)&ki->ki_src; - } - - unixdomainpr0(ki->ki_pcbaddr, ki->ki_type, - ki->ki_rcvq, ki->ki_sndq, - ki->ki_vnode, ki->ki_conn, ki->ki_refs, - ki->ki_nextref, ki->ki_sockaddr, sun, remote); + free(pcblist); } - free(pcblist); - - if (!done && mibname) { - mibname = "net.local.dgram.pcblist"; - done = 1; - goto again; - } } else { - filebuf = (char *)kvm_getfiles(get_kvmd(), KERN_FILE, 0, &ns_nfiles); + filebuf = (char *)kvm_getfiles(get_kvmd(), KERN_FILE, + 0, &ns_nfiles); if (filebuf == 0) { - printf("file table read error: %s", kvm_geterr(get_kvmd())); + printf("file table read error: %s", + kvm_geterr(get_kvmd())); return; } file = (struct file *)(filebuf + sizeof(fp)); Index: src/usr.bin/sockstat/sockstat.c diff -u src/usr.bin/sockstat/sockstat.c:1.16 src/usr.bin/sockstat/sockstat.c:1.17 --- src/usr.bin/sockstat/sockstat.c:1.16 Fri Jan 28 18:52:49 2011 +++ src/usr.bin/sockstat/sockstat.c Sun May 29 04:45:08 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: sockstat.c,v 1.16 2011/01/28 18:52:49 pooka Exp $ */ +/* $NetBSD: sockstat.c,v 1.17 2011/05/29 04:45:08 manu Exp $ */ /* * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: sockstat.c,v 1.16 2011/01/28 18:52:49 pooka Exp $"); +__RCSID("$NetBSD: sockstat.c,v 1.17 2011/05/29 04:45:08 manu Exp $"); #endif #include <sys/types.h> @@ -210,6 +210,7 @@ if (pf_list & PF_LIST_LOCAL) { get_sockets("net.local.stream.pcblist"); + get_sockets("net.local.seqpacket.pcblist"); get_sockets("net.local.dgram.pcblist"); }