summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat/unix.c
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2010-10-30 23:06:05 +0000
committerbluhm <bluhm@openbsd.org>2010-10-30 23:06:05 +0000
commit74a63420517b276fb1b5bb4fd2aae28e24195eb9 (patch)
tree432f83038b9e9c15cbc938e0c594410b9d4b85f7 /usr.bin/netstat/unix.c
parentfor the user, create a matching group and put the user in there by default; ok halex guenther (diff)
downloadwireguard-openbsd-74a63420517b276fb1b5bb4fd2aae28e24195eb9.tar.xz
wireguard-openbsd-74a63420517b276fb1b5bb4fd2aae28e24195eb9.zip
Print socket structure internals when netstat -P pcbaddr is called
with -v. Also netstat -P supports more than TCP now. ok markus@ jmc@
Diffstat (limited to 'usr.bin/netstat/unix.c')
-rw-r--r--usr.bin/netstat/unix.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/usr.bin/netstat/unix.c b/usr.bin/netstat/unix.c
index 61575badda4..e80c917f0d4 100644
--- a/usr.bin/netstat/unix.c
+++ b/usr.bin/netstat/unix.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: unix.c,v 1.14 2010/04/28 18:22:11 jsg Exp $ */
+/* $OpenBSD: unix.c,v 1.15 2010/10/30 23:06:05 bluhm Exp $ */
/* $NetBSD: unix.c,v 1.13 1995/10/03 21:42:48 thorpej Exp $ */
/*-
@@ -54,14 +54,14 @@ struct proc;
#include <kvm.h>
#include "netstat.h"
-static void unixdomainpr(struct socket *, caddr_t);
+static void unixdomainpr(struct socket *, caddr_t, u_long);
static struct file *file, *fileNFILE;
static int fcnt;
extern kvm_t *kvmd;
void
-unixpr(u_long off)
+unixpr(u_long off, u_long pcbaddr)
{
struct file *fp;
struct socket sock, *so = &sock;
@@ -83,7 +83,7 @@ unixpr(u_long off)
/* kludge */
if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
if (so->so_pcb)
- unixdomainpr(so, fp->f_data);
+ unixdomainpr(so, fp->f_data, pcbaddr);
}
}
@@ -91,13 +91,19 @@ static char *socktype[] =
{ "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
static void
-unixdomainpr(struct socket *so, caddr_t soaddr)
+unixdomainpr(struct socket *so, caddr_t soaddr, u_long pcbaddr)
{
struct unpcb unpcb, *unp = &unpcb;
struct mbuf mbuf, *m;
struct sockaddr_un *sa = NULL;
static int first = 1;
+ if (Pflag) {
+ if (pcbaddr == (u_long)soaddr)
+ socket_dump(pcbaddr);
+ return;
+ }
+
if (kread((u_long)so->so_pcb, unp, sizeof (*unp)))
return;
if (unp->unp_addr) {
@@ -125,3 +131,35 @@ unixdomainpr(struct socket *so, caddr_t soaddr)
sa->sun_path);
putchar('\n');
}
+
+/*
+ * Dump the contents of a UNIX PCB
+ */
+void
+unpcb_dump(u_long off)
+{
+ struct unpcb unp;
+
+ if (off == 0)
+ return;
+ kread(off, &unp, sizeof(unp));
+
+#define p(fmt, v, sep) printf(#v " " fmt sep, unp.v);
+ printf("unpcb %#lx\n ", off);
+ p("%p", unp_socket, "\n ");
+ p("%p", unp_vnode, ", ");
+ p("%u", unp_ino, "\n ");
+ p("%p", unp_conn, ", ");
+ p("%p", unp_refs, ", ");
+ p("%p", unp_nextref, "\n ");
+ p("%p", unp_addr, "\n ");
+ p("%#0.8x", unp_flags, "\n ");
+ p("%u", unp_connid.uid, ", ");
+ p("%u", unp_connid.gid, ", ");
+ p("%d", unp_connid.pid, "\n ");
+ p("%d", unp_cc, ", ");
+ p("%d", unp_mbcnt, "\n ");
+ p("%d", unp_ctime.tv_sec, ", ");
+ p("%ld", unp_ctime.tv_nsec, "\n");
+#undef p
+}