version 1.25, 2015/01/20 18:26:57 |
version 1.26, 2015/02/12 01:49:02 |
|
|
#include <kvm.h> |
#include <kvm.h> |
#include "netstat.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[] = |
static const char *socktype[] = |
{ "#0", "stream", "dgram", "raw", "rdm", "seqpacket" }; |
{ "#0", "stream", "dgram", "raw", "rdm", "seqpacket" }; |
|
|
static void |
void |
unixdomainpr(const struct kinfo_file *kf, u_long pcbaddr) |
unixdomainpr(struct kinfo_file *kf) |
{ |
{ |
static int first = 1; |
static int first = 1; |
|
|
if (Pflag) { |
/* XXX should fix kinfo_file instead but not now */ |
if (pcbaddr == kf->f_data) |
if (kf->so_pcb == -1) |
socket_dump(pcbaddr); |
kf->so_pcb = 0; |
return; |
|
} |
|
|
|
if (first) { |
if (first) { |
printf("Active UNIX domain sockets\n"); |
printf("Active UNIX domain sockets\n"); |
|
|
first = 0; |
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", |
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, |
kf->so_rcv_cc, kf->so_snd_cc, |
FAKE_PTR(kf->v_un), |
FAKE_PTR(kf->v_un), |
FAKE_PTR(kf->unp_conn), |
FAKE_PTR(kf->unp_conn), |
|
|
return; |
return; |
kread(off, &unp, sizeof(unp)); |
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 p(fmt, v, sep) printf(#v " " fmt sep, unp.v); |
#define pll(fmt, v, sep) printf(#v " " fmt sep, (long long) 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 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); |
#define pp(fmt, v, sep) printf(#v " " fmt sep, unp.v); |
printf("unpcb %#lx\n ", hideroot ? 0 : off); |
printf("unpcb %#lx\n ", off); |
pp("%p", unp_socket, "\n "); |
pp("%p", unp_socket, "\n "); |
pp("%p", unp_vnode, ", "); |
pp("%p", unp_vnode, ", "); |
pull("%llu", unp_ino, "\n "); |
pull("%llu", unp_ino, "\n "); |