version 1.20, 2013/08/18 16:32:24 |
version 1.21, 2013/10/22 16:40:28 |
|
|
#include <sys/un.h> |
#include <sys/un.h> |
#include <sys/unpcb.h> |
#include <sys/unpcb.h> |
#define _KERNEL |
#define _KERNEL |
struct uio; |
|
struct proc; |
|
#include <sys/file.h> |
#include <sys/file.h> |
|
#undef _KERNEL |
|
|
#include <netinet/in.h> |
#include <netinet/in.h> |
|
|
|
|
#include <kvm.h> |
#include <kvm.h> |
#include "netstat.h" |
#include "netstat.h" |
|
|
static void unixdomainpr(struct socket *, caddr_t, u_long); |
static void unixdomainpr(const struct kinfo_file *, u_long); |
|
|
static struct file *file, *fileNFILE; |
|
static int fcnt; |
|
extern kvm_t *kvmd; |
|
|
|
void |
void |
unixpr(u_long off, u_long pcbaddr) |
unixpr(kvm_t *kvmd, u_long pcbaddr) |
{ |
{ |
struct file *fp; |
struct kinfo_file *kf; |
struct socket sock, *so = &sock; |
struct socket sock, *so = &sock; |
char *filebuf; |
int i, fcnt; |
struct protosw *unixsw = (struct protosw *)off; |
|
|
|
filebuf = kvm_getfiles(kvmd, KERN_FILE, 0, &fcnt); |
kf = kvm_getfiles(kvmd, KERN_FILE_BYFILE, 0, sizeof(*kf), &fcnt); |
if (filebuf == NULL) { |
if (kf == NULL) { |
printf("Out of memory (file table).\n"); |
printf("Out of memory (file table).\n"); |
return; |
return; |
} |
} |
file = (struct file *)(filebuf + sizeof(fp)); |
for (i = 0; i < fcnt; i++) { |
fileNFILE = file + fcnt; |
if (kf[i].f_count != 0 && kf[i].f_type == DTYPE_SOCKET && |
for (fp = file; fp < fileNFILE; fp++) { |
kf[i].so_family == AF_LOCAL && (kf[i].so_pcb != 0 || |
if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET) |
kf[i].unp_path[0] != '\0')) |
continue; |
unixdomainpr(&kf[i], pcbaddr); |
if (kread((u_long)fp->f_data, so, sizeof (*so))) |
|
continue; |
|
/* kludge */ |
|
if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2) |
|
if (so->so_pcb) |
|
unixdomainpr(so, fp->f_data, pcbaddr); |
|
} |
} |
} |
} |
|
|
static char *socktype[] = |
static const char *socktype[] = |
{ "#0", "stream", "dgram", "raw", "rdm", "seqpacket" }; |
{ "#0", "stream", "dgram", "raw", "rdm", "seqpacket" }; |
|
|
static void |
static void |
unixdomainpr(struct socket *so, caddr_t soaddr, u_long pcbaddr) |
unixdomainpr(const struct kinfo_file *kf, u_long pcbaddr) |
{ |
{ |
struct unpcb unpcb, *unp = &unpcb; |
|
struct mbuf mbuf, *m; |
|
struct sockaddr_un *sa = NULL; |
|
static int first = 1; |
static int first = 1; |
|
|
if (Pflag) { |
if (Pflag) { |
if (pcbaddr == (u_long)soaddr) |
if (pcbaddr == kf->f_data) |
socket_dump(pcbaddr); |
socket_dump(pcbaddr); |
return; |
return; |
} |
} |
|
|
if (kread((u_long)so->so_pcb, unp, sizeof (*unp))) |
|
return; |
|
if (unp->unp_addr) { |
|
m = &mbuf; |
|
if (kread((u_long)unp->unp_addr, m, sizeof (*m))) |
|
m = NULL; |
|
sa = (struct sockaddr_un *)(m->m_dat); |
|
} else |
|
m = NULL; |
|
if (first) { |
if (first) { |
printf("Active UNIX domain sockets\n"); |
printf("Active UNIX domain sockets\n"); |
printf("%-*.*s %-6.6s %-6.6s %-6.6s %*.*s %*.*s %*.*s %*.*s Addr\n", |
printf("%-*.*s %-6.6s %-6.6s %-6.6s %*.*s %*.*s %*.*s %*.*s Addr\n", |
|
|
PLEN, PLEN, "Refs", PLEN, PLEN, "Nextref"); |
PLEN, PLEN, "Refs", PLEN, PLEN, "Nextref"); |
first = 0; |
first = 0; |
} |
} |
printf("%*p %-6.6s %6ld %6ld %*p %*p %*p %*p", |
|
PLEN, hideroot ? 0 : soaddr, |
#define FAKE_PTR(p) (PLEN - ((p) ? 0 : 2)), p, ((p) ? "" : "x0") |
socktype[so->so_type], so->so_rcv.sb_cc, so->so_snd.sb_cc, |
printf("%#*llx%s %-6.6s %6ld %6ld %#*llx%s %#*llx%s %#*llx%s %#*llx%s", |
PLEN, hideroot ? 0 : unp->unp_vnode, |
FAKE_PTR(kf->f_data), socktype[kf->so_type], |
PLEN, hideroot ? 0 : unp->unp_conn, |
kf->so_rcv_cc, kf->so_snd_cc, |
PLEN, hideroot ? 0 : unp->unp_refs, |
FAKE_PTR(kf->v_un), |
PLEN, hideroot ? 0 : unp->unp_nextref); |
FAKE_PTR(kf->unp_conn), |
if (m) |
FAKE_PTR(kf->unp_refs), |
printf(" %.*s", |
FAKE_PTR(kf->unp_nextref)); |
(int)(m->m_len - (int)(sizeof(*sa) - sizeof(sa->sun_path))), |
if (kf->unp_path[0] != '\0') |
sa->sun_path); |
printf(" %.*s", KI_UNPPATHLEN, kf->unp_path); |
putchar('\n'); |
putchar('\n'); |
} |
} |
|
|