Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin Display SOCK_SEQPACKET local sockets in sockstat and...
details: https://anonhg.NetBSD.org/src/rev/df2d61a7274b
branches: trunk
changeset: 765514:df2d61a7274b
user: manu <manu%NetBSD.org@localhost>
date: Sun May 29 04:45:08 2011 +0000
description:
Display SOCK_SEQPACKET local sockets in sockstat and netstat
diffstat:
usr.bin/netstat/unix.c | 98 +++++++++++++++++++++++---------------------
usr.bin/sockstat/sockstat.c | 5 +-
2 files changed, 54 insertions(+), 49 deletions(-)
diffs (160 lines):
diff -r 373c001bd626 -r df2d61a7274b usr.bin/netstat/unix.c
--- a/usr.bin/netstat/unix.c Sun May 29 03:34:33 2011 +0000
+++ b/usr.bin/netstat/unix.c Sun May 29 04:45:08 2011 +0000
@@ -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 (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 (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 ((pcblist = malloc(size)) == NULL)
- err(1, "malloc");
- memset(pcblist, 0, size);
+ if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib),
+ pcblist, &size, NULL, 0) == -1)
+ err(1, "sysctl (copy)");
- mib[6] = sizeof(*pcblist);
- mib[7] = size / sizeof(*pcblist);
+ for (i = 0; i < size / sizeof(*pcblist); i++) {
+ struct kinfo_pcb *ki = &pcblist[i];
+ struct sockaddr_un *sun;
+ int remote = 0;
- if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib), pcblist,
- &size, NULL, 0) == -1)
- err(1, "sysctl (copy)");
+ if (first) {
+ unixdomainprhdr();
+ first = 0;
+ }
- for (i = 0; i < size / sizeof(*pcblist); i++) {
- struct kinfo_pcb *ki = &pcblist[i];
- struct sockaddr_un *sun;
- int remote = 0;
+ sun = (struct sockaddr_un *)&ki->ki_dst;
+ if (sun->sun_path[0] != '\0') {
+ remote = 1;
+ } else {
+ sun = (struct sockaddr_un *)&ki->ki_src;
+ }
- if (first) {
- unixdomainprhdr();
- first = 0;
+ 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));
diff -r 373c001bd626 -r df2d61a7274b usr.bin/sockstat/sockstat.c
--- a/usr.bin/sockstat/sockstat.c Sun May 29 03:34:33 2011 +0000
+++ b/usr.bin/sockstat/sockstat.c Sun May 29 04:45:08 2011 +0000
@@ -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");
}
Home |
Main Index |
Thread Index |
Old Index