summaryrefslogtreecommitdiff
path: root/usr.bin/fstat
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-08-12 19:45:48 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-08-12 19:45:48 +0000
commit10ee12e5aba134f3475c901826660a4f84f3a669 (patch)
tree7299c7d2f9655cee26b738ff5d07b9c303f93c81 /usr.bin/fstat
parent804d9d35f3f60d5823371f6974f769b659406a17 (diff)
lsof-like support for fstat, whee
Diffstat (limited to 'usr.bin/fstat')
-rw-r--r--usr.bin/fstat/fstat.c56
1 files changed, 41 insertions, 15 deletions
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
index d11d3ded69d..79d47eef412 100644
--- a/usr.bin/fstat/fstat.c
+++ b/usr.bin/fstat/fstat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fstat.c,v 1.4 1996/08/06 18:05:51 deraadt Exp $ */
+/* $OpenBSD: fstat.c,v 1.5 1996/08/12 19:45:47 deraadt Exp $ */
/*-
* Copyright (c) 1988, 1993
@@ -41,7 +41,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)fstat.c 8.1 (Berkeley) 6/6/93";*/
-static char *rcsid = "$OpenBSD: fstat.c,v 1.4 1996/08/06 18:05:51 deraadt Exp $";
+static char *rcsid = "$OpenBSD: fstat.c,v 1.5 1996/08/12 19:45:47 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -76,6 +76,8 @@ static char *rcsid = "$OpenBSD: fstat.c,v 1.4 1996/08/06 18:05:51 deraadt Exp $"
#include <netinet/ip.h>
#include <netinet/in_pcb.h>
+#include <arpa/inet.h>
+
#include <ctype.h>
#include <errno.h>
#include <kvm.h>
@@ -638,20 +640,44 @@ socktrans(sock, i)
switch(dom.dom_family) {
case AF_INET:
getinetproto(proto.pr_protocol);
- if (proto.pr_protocol == IPPROTO_TCP ) {
- if (so.so_pcb) {
- if (kvm_read(kd, (u_long)so.so_pcb,
- (char *)&inpcb, sizeof(struct inpcb))
- != sizeof(struct inpcb)) {
- dprintf(stderr,
- "can't read inpcb at %x\n",
- so.so_pcb);
- goto bad;
- }
- printf(" %lx", (long)inpcb.inp_ppcb);
+ if (proto.pr_protocol == IPPROTO_TCP) {
+ if (so.so_pcb == NULL)
+ break;
+ if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb,
+ sizeof(struct inpcb)) != sizeof(struct inpcb)) {
+ dprintf(stderr, "can't read inpcb at %x\n",
+ so.so_pcb);
+ goto bad;
}
- }
- else if (so.so_pcb)
+ printf(" %lx", (long)inpcb.inp_ppcb);
+ printf(" %s:%d",
+ inpcb.inp_laddr.s_addr == INADDR_ANY ? "*" :
+ inet_ntoa(inpcb.inp_laddr),
+ ntohs(inpcb.inp_lport));
+ if (inpcb.inp_fport)
+ printf(" -> %s:%d",
+ inpcb.inp_faddr.s_addr == INADDR_ANY ? "*" :
+ inet_ntoa(inpcb.inp_faddr),
+ ntohs(inpcb.inp_fport));
+ } else if (proto.pr_protocol == IPPROTO_UDP) {
+ if (so.so_pcb == NULL)
+ break;
+ if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb,
+ sizeof(struct inpcb)) != sizeof(struct inpcb)) {
+ dprintf(stderr, "can't read inpcb at %x\n",
+ so.so_pcb);
+ goto bad;
+ }
+ printf(" %s:%d",
+ inpcb.inp_laddr.s_addr == INADDR_ANY ? "*" :
+ inet_ntoa(inpcb.inp_laddr),
+ ntohs(inpcb.inp_lport));
+ if (inpcb.inp_fport)
+ printf(" -> %s:%d",
+ inpcb.inp_faddr.s_addr == INADDR_ANY ? "*" :
+ inet_ntoa(inpcb.inp_faddr),
+ ntohs(inpcb.inp_fport));
+ } else if (so.so_pcb)
printf(" %lx", (long)so.so_pcb);
break;
case AF_UNIX: