version 1.73, 2012/11/30 14:40:03 |
version 1.74, 2013/03/24 15:09:13 |
|
|
void vtrans(struct kinfo_file2 *); |
void vtrans(struct kinfo_file2 *); |
const char *inet6_addrstr(struct in6_addr *); |
const char *inet6_addrstr(struct in6_addr *); |
int signame_to_signum(char *); |
int signame_to_signum(char *); |
|
void hide(void *p); |
|
|
|
int hideroot; |
|
|
|
void |
|
hide(void *p) |
|
{ |
|
printf("%p", hideroot ? NULL : p); |
|
} |
|
|
int |
int |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
{ |
{ |
|
|
const char *errstr; |
const char *errstr; |
int cnt, flags; |
int cnt, flags; |
|
|
|
hideroot = getuid(); |
|
|
arg = -1; |
arg = -1; |
what = KERN_FILE_BYPID; |
what = KERN_FILE_BYPID; |
nlistf = memf = NULL; |
nlistf = memf = NULL; |
|
|
usage(); |
usage(); |
arg = strtonum(optarg, 0, INT_MAX, &errstr); |
arg = strtonum(optarg, 0, INT_MAX, &errstr); |
if (errstr != NULL) { |
if (errstr != NULL) { |
warnx("-p requires a process id, %s: %s", |
warnx("-p requires a process id, %s: %s", |
errstr, optarg); |
errstr, optarg); |
usage(); |
usage(); |
} |
} |
|
|
usage(); |
usage(); |
if (!fuser) { |
if (!fuser) { |
if (!(passwd = getpwnam(optarg))) { |
if (!(passwd = getpwnam(optarg))) { |
arg = strtonum(optarg, 0, UID_MAX, |
arg = strtonum(optarg, 0, UID_MAX, |
&errstr); |
&errstr); |
if (errstr != NULL) { |
if (errstr != NULL) { |
errx(1, "%s: unknown uid", |
errx(1, "%s: unknown uid", |
|
|
if (oflg) { |
if (oflg) { |
if (uid == 0 || uid == *procuid) |
if (uid == 0 || uid == *procuid) |
printf(":%-8llu", kf->f_offset); |
printf(":%-8llu", kf->f_offset); |
else |
else |
printf(":%-8s", "*"); |
printf(":%-8s", "*"); |
} |
} |
} |
} |
if (sflg) { |
if (sflg) { |
if (uid == 0 || uid == *procuid) { |
if (uid == 0 || uid == *procuid) { |
printf(" %8llu %8llu", |
printf(" %8llu %8llu", |
(kf->f_rxfer + kf->f_rwfer), |
(kf->f_rxfer + kf->f_rwfer), |
(kf->f_rbytes + kf->f_wbytes) / 1024); |
(kf->f_rbytes + kf->f_wbytes) / 1024); |
} else { |
} else { |
printf(" %8s %8s", "*", "*"); |
printf(" %8s %8s", "*", "*"); |
} |
} |
|
|
*/ |
*/ |
maxaddr = (void *)(uintptr_t)MAX(kf->f_data, kf->pipe_peer); |
maxaddr = (void *)(uintptr_t)MAX(kf->f_data, kf->pipe_peer); |
|
|
printf("pipe %p state: %s%s%s", maxaddr, |
printf("pipe "); |
|
hide(maxaddr); |
|
printf("state: %s%s%s", |
(kf->pipe_state & PIPE_WANTR) ? "R" : "", |
(kf->pipe_state & PIPE_WANTR) ? "R" : "", |
(kf->pipe_state & PIPE_WANTW) ? "W" : "", |
(kf->pipe_state & PIPE_WANTW) ? "W" : "", |
(kf->pipe_state & PIPE_EOF) ? "E" : ""); |
(kf->pipe_state & PIPE_EOF) ? "E" : ""); |
|
|
|
|
printf(" "); |
printf(" "); |
|
|
printf("kqueue %p %d state: %s%s\n", (void *)(uintptr_t)kf->f_data, |
printf("kqueue "); |
|
hide((void *)(uintptr_t)kf->f_data); |
|
printf(" %d state: %s%s\n", |
kf->kq_count, |
kf->kq_count, |
(kf->kq_state & KQ_SEL) ? "S" : "", |
(kf->kq_state & KQ_SEL) ? "S" : "", |
(kf->kq_state & KQ_SLEEP) ? "W" : ""); |
(kf->kq_state & KQ_SLEEP) ? "W" : ""); |
|
|
|
|
printf(" "); |
printf(" "); |
|
|
printf("crypto %p\n", (void *)(uintptr_t)kf->f_data); |
printf("crypto "); |
|
hide((void *)(uintptr_t)kf->f_data); |
|
printf("\n"); |
} |
} |
|
|
void |
void |
|
|
|
|
printf(" "); |
printf(" "); |
|
|
printf("systrace %p npol %d\n", (void *)(uintptr_t)kf->f_data, |
printf("systrace "); |
kf->str_npolicies); |
hide((void *)(uintptr_t)kf->f_data); |
|
printf(" npol %d\n", kf->str_npolicies); |
return; |
return; |
} |
} |
|
|
|
|
{ |
{ |
ENTRY entry, *found; |
ENTRY entry, *found; |
|
|
if (asprintf(&entry.key, "%c%llx", type, ptr) == -1) |
if (asprintf(&entry.key, "%c%llx", type, hideroot ? 0 : ptr) == -1) |
err(1, NULL); |
err(1, NULL); |
entry.data = data; |
entry.data = data; |
if ((found = hsearch(entry, ENTER)) == NULL) |
if ((found = hsearch(entry, ENTER)) == NULL) |
|
|
ENTRY entry, *found; |
ENTRY entry, *found; |
char buf[20]; |
char buf[20]; |
|
|
snprintf(buf, sizeof(buf), "%c%llx", type, ptr); |
snprintf(buf, sizeof(buf), "%c%llx", type, hideroot ? 0 : ptr); |
entry.key = buf; |
entry.key = buf; |
found = hsearch(entry, FIND); |
found = hsearch(entry, FIND); |
return (found != NULL ? found->data : NULL); |
return (found != NULL ? found->data : NULL); |
|
|
memcpy(&laddr, kf->inp_laddru, sizeof(laddr)); |
memcpy(&laddr, kf->inp_laddru, sizeof(laddr)); |
memcpy(&faddr, kf->inp_faddru, sizeof(faddr)); |
memcpy(&faddr, kf->inp_faddru, sizeof(faddr)); |
if (kf->so_protocol == IPPROTO_TCP) { |
if (kf->so_protocol == IPPROTO_TCP) { |
printf(" %p", (void *)(uintptr_t)kf->inp_ppcb); |
printf(" "); |
|
hide((void *)(uintptr_t)kf->inp_ppcb); |
printf(" %s:%d", laddr.s_addr == INADDR_ANY ? "*" : |
printf(" %s:%d", laddr.s_addr == INADDR_ANY ? "*" : |
inet_ntoa(laddr), ntohs(kf->inp_lport)); |
inet_ntoa(laddr), ntohs(kf->inp_lport)); |
if (kf->inp_fport) { |
if (kf->inp_fport) { |
|
|
faddr.s_addr == INADDR_ANY ? "*" : |
faddr.s_addr == INADDR_ANY ? "*" : |
inet_ntoa(faddr), ntohs(kf->inp_fport)); |
inet_ntoa(faddr), ntohs(kf->inp_fport)); |
} |
} |
} else if (kf->so_pcb) |
} else if (kf->so_pcb) { |
printf(" %p", (void *)(uintptr_t)kf->so_pcb); |
printf(" "); |
|
hide((void *)(uintptr_t)kf->so_pcb); |
|
} |
} |
} |
|
|
#ifdef INET6 |
#ifdef INET6 |
|
|
memcpy(&laddr6, kf->inp_laddru, sizeof(laddr6)); |
memcpy(&laddr6, kf->inp_laddru, sizeof(laddr6)); |
memcpy(&faddr6, kf->inp_faddru, sizeof(faddr6)); |
memcpy(&faddr6, kf->inp_faddru, sizeof(faddr6)); |
if (kf->so_protocol == IPPROTO_TCP) { |
if (kf->so_protocol == IPPROTO_TCP) { |
printf(" %p", (void *)(uintptr_t)kf->inp_ppcb); |
printf(" "); |
|
hide((void *)(uintptr_t)kf->inp_ppcb); |
snprintf(xaddrbuf, sizeof(xaddrbuf), "[%s]", |
snprintf(xaddrbuf, sizeof(xaddrbuf), "[%s]", |
inet6_addrstr(&laddr6)); |
inet6_addrstr(&laddr6)); |
printf(" %s:%d", |
printf(" %s:%d", |
|
|
IN6_IS_ADDR_UNSPECIFIED(&faddr6) ? "*" : |
IN6_IS_ADDR_UNSPECIFIED(&faddr6) ? "*" : |
xaddrbuf, ntohs(kf->inp_fport)); |
xaddrbuf, ntohs(kf->inp_fport)); |
} |
} |
} else if (kf->so_pcb) |
} else if (kf->so_pcb) { |
printf(" %p", (void *)(uintptr_t)kf->so_pcb); |
printf(" "); |
|
hide((void *)(uintptr_t)kf->so_pcb); |
|
} |
} |
} |
#endif |
#endif |
|
|
|
|
/* print address of pcb and connected pcb */ |
/* print address of pcb and connected pcb */ |
printf("* unix %s", stype); |
printf("* unix %s", stype); |
if (kf->so_pcb) { |
if (kf->so_pcb) { |
printf(" %p", (void *)(uintptr_t)kf->so_pcb); |
printf(" "); |
|
hide((void *)(uintptr_t)kf->so_pcb); |
if (kf->unp_conn) { |
if (kf->unp_conn) { |
char shoconn[4], *cp; |
char shoconn[4], *cp; |
|
|
|
|
if (!(kf->so_state & SS_CANTSENDMORE)) |
if (!(kf->so_state & SS_CANTSENDMORE)) |
*cp++ = '>'; |
*cp++ = '>'; |
*cp = '\0'; |
*cp = '\0'; |
printf(" %s %p", shoconn, |
printf(" %s ", shoconn); |
(void *)(uintptr_t)kf->unp_conn); |
hide((void *)(uintptr_t)kf->unp_conn); |
} |
} |
} |
} |
break; |
break; |
case AF_MPLS: |
case AF_MPLS: |
/* print protocol number and socket address */ |
/* print protocol number and socket address */ |
printf("* mpls %s", stype); |
printf("* mpls %s", stype); |
printf(" %d %p", kf->so_protocol, |
printf(" %d ", kf->so_protocol); |
(void *)(uintptr_t)kf->f_data); |
hide((void *)(uintptr_t)kf->f_data); |
break; |
break; |
case AF_ROUTE: |
case AF_ROUTE: |
/* print protocol number and socket address */ |
/* print protocol number and socket address */ |
printf("* route %s", stype); |
printf("* route %s", stype); |
printf(" %d %p", kf->so_protocol, |
printf(" %d ", kf->so_protocol); |
(void *)(uintptr_t)kf->f_data); |
hide((void *)(uintptr_t)kf->f_data); |
break; |
break; |
case AF_BLUETOOTH: |
case AF_BLUETOOTH: |
/* print protocol number and socket address */ |
/* print protocol number and socket address */ |
printf("* bluetooth %s", stype); |
printf("* bluetooth %s", stype); |
printf(" %d %p", kf->so_protocol, |
printf(" %d ", kf->so_protocol); |
(void *)(uintptr_t)kf->f_data); |
hide((void *)(uintptr_t)kf->f_data); |
break; |
break; |
case AF_NATM: |
case AF_NATM: |
/* print protocol number and socket address */ |
/* print protocol number and socket address */ |
printf("* natm %s", stype); |
printf("* natm %s", stype); |
printf(" %d %p", kf->so_protocol, |
printf(" %d ", kf->so_protocol); |
(void *)(uintptr_t)kf->f_data); |
hide((void *)(uintptr_t)kf->f_data); |
break; |
break; |
default: |
default: |
/* print protocol number and socket address */ |
/* print protocol number and socket address */ |
printf("* %d %s", kf->so_family, stype); |
printf("* %d %s", kf->so_family, stype); |
printf(" %d %p", kf->so_protocol, |
printf(" %d ", kf->so_protocol); |
(void *)(uintptr_t)kf->f_data); |
hide((void *)(uintptr_t)kf->f_data); |
} |
} |
if (kf->so_splice != 0 || kf->so_splicelen == -1) { |
if (kf->so_splice != 0 || kf->so_splicelen == -1) { |
struct kinfo_file2 *from, *to; |
struct kinfo_file2 *from, *to; |