diff options
author | 2015-02-12 01:49:02 +0000 | |
---|---|---|
committer | 2015-02-12 01:49:02 +0000 | |
commit | 543e2d55756daece4cfce071d42245d5565a5694 (patch) | |
tree | 4eaf225ab1223f36e39c52c178bed563aa75d2ff /usr.bin/netstat/unix.c | |
parent | Put the dev+ino table for cpio hardlink matching behind #ifndef NOCPIO (diff) | |
download | wireguard-openbsd-543e2d55756daece4cfce071d42245d5565a5694.tar.xz wireguard-openbsd-543e2d55756daece4cfce071d42245d5565a5694.zip |
Switch the printing of open sockets from ugly KVM internals to use
kvm_getfiles. This allows to run netstat without any extra privileges
and removes another setgid program from base..
There is still kvm reader code in there which is used for debugging
purposes (crashdump). netstat should still behave mostly the same.
deraadt@ and sthen@ agree that it is time to get this puppy in.
Diffstat (limited to 'usr.bin/netstat/unix.c')
-rw-r--r-- | usr.bin/netstat/unix.c | 45 |
1 files changed, 12 insertions, 33 deletions
diff --git a/usr.bin/netstat/unix.c b/usr.bin/netstat/unix.c index 27ed2816812..fbf98ca2eaa 100644 --- a/usr.bin/netstat/unix.c +++ b/usr.bin/netstat/unix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: unix.c,v 1.25 2015/01/20 18:26:57 deraadt Exp $ */ +/* $OpenBSD: unix.c,v 1.26 2015/02/12 01:49:02 claudio Exp $ */ /* $NetBSD: unix.c,v 1.13 1995/10/03 21:42:48 thorpej Exp $ */ /*- @@ -53,40 +53,17 @@ #include <kvm.h> #include "netstat.h" -static void unixdomainpr(const struct kinfo_file *, u_long); - -void -unixpr(kvm_t *kvmd, u_long pcbaddr) -{ - struct kinfo_file *kf; - int i, fcnt; - - kf = kvm_getfiles(kvmd, KERN_FILE_BYFILE, 0, sizeof(*kf), &fcnt); - if (kf == NULL) { - printf("Out of memory (file table).\n"); - return; - } - for (i = 0; i < fcnt; i++) { - if (kf[i].f_count != 0 && kf[i].f_type == DTYPE_SOCKET && - kf[i].so_family == AF_LOCAL && (kf[i].so_pcb != 0 || - kf[i].unp_path[0] != '\0')) - unixdomainpr(&kf[i], pcbaddr); - } -} - static const char *socktype[] = { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" }; -static void -unixdomainpr(const struct kinfo_file *kf, u_long pcbaddr) +void +unixdomainpr(struct kinfo_file *kf) { static int first = 1; - if (Pflag) { - if (pcbaddr == kf->f_data) - socket_dump(pcbaddr); - return; - } + /* XXX should fix kinfo_file instead but not now */ + if (kf->so_pcb == -1) + kf->so_pcb = 0; if (first) { printf("Active UNIX domain sockets\n"); @@ -97,9 +74,8 @@ unixdomainpr(const struct kinfo_file *kf, u_long pcbaddr) first = 0; } -#define FAKE_PTR(p) (PLEN - ((p) ? 0 : 2)), p, ((p) ? "" : "x0") printf("%#*llx%s %-6.6s %6llu %6llu %#*llx%s %#*llx%s %#*llx%s %#*llx%s", - FAKE_PTR(kf->f_data), socktype[kf->so_type], + FAKE_PTR(kf->so_pcb), socktype[kf->so_type], kf->so_rcv_cc, kf->so_snd_cc, FAKE_PTR(kf->v_un), FAKE_PTR(kf->unp_conn), @@ -122,11 +98,14 @@ unpcb_dump(u_long off) return; kread(off, &unp, sizeof(unp)); + if (vflag) + socket_dump((u_long)unp.unp_socket); + #define p(fmt, v, sep) printf(#v " " fmt sep, unp.v); #define pll(fmt, v, sep) printf(#v " " fmt sep, (long long) unp.v); #define pull(fmt, v, sep) printf(#v " " fmt sep, (unsigned long long) unp.v); -#define pp(fmt, v, sep) printf(#v " " fmt sep, hideroot ? 0 : unp.v); - printf("unpcb %#lx\n ", hideroot ? 0 : off); +#define pp(fmt, v, sep) printf(#v " " fmt sep, unp.v); + printf("unpcb %#lx\n ", off); pp("%p", unp_socket, "\n "); pp("%p", unp_vnode, ", "); pull("%llu", unp_ino, "\n "); |