summaryrefslogtreecommitdiffstats
path: root/usr.bin/sockstat
diff options
context:
space:
mode:
authormux <mux@FreeBSD.org>2003-06-07 14:36:49 +0000
committermux <mux@FreeBSD.org>2003-06-07 14:36:49 +0000
commitdf4d18c70c74ae792c0e50657c3a501026e37258 (patch)
tree376e8570e214164bff991d4aaa06cb90b74effcb /usr.bin/sockstat
parentd000b6db794ebebad8753aed4cf69cfecb55ad90 (diff)
downloadFreeBSD-src-df4d18c70c74ae792c0e50657c3a501026e37258.zip
FreeBSD-src-df4d18c70c74ae792c0e50657c3a501026e37258.tar.gz
Finish the implementation of the -p switch so that it
actually works. I have no idea why this wasn't finished and happened to try to use it.
Diffstat (limited to 'usr.bin/sockstat')
-rw-r--r--usr.bin/sockstat/sockstat.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c
index 1212be1..b68906e 100644
--- a/usr.bin/sockstat/sockstat.c
+++ b/usr.bin/sockstat/sockstat.c
@@ -456,6 +456,30 @@ getprocname(pid_t pid)
return (proc.ki_ocomm);
}
+static int
+check_ports(struct sock *s)
+{
+ int port;
+
+ if (ports == NULL)
+ return (1);
+ if ((s->family != AF_INET) && (s->family != AF_INET6))
+ return (1);
+ if (s->family == AF_INET)
+ port = ntohs(((struct sockaddr_in *)(&s->laddr))->sin_port);
+ else
+ port = ntohs(((struct sockaddr_in6 *)(&s->laddr))->sin6_port);
+ if (CHK_PORT(port))
+ return (1);
+ if (s->family == AF_INET)
+ port = ntohs(((struct sockaddr_in *)(&s->faddr))->sin_port);
+ else
+ port = ntohs(((struct sockaddr_in6 *)(&s->faddr))->sin6_port);
+ if (CHK_PORT(port))
+ return (1);
+ return (0);
+}
+
static void
display(void)
{
@@ -476,6 +500,8 @@ display(void)
break;
if (s == NULL)
continue;
+ if (!check_ports(s))
+ continue;
pos = 0;
if ((pwd = getpwuid(xf->xf_uid)) == NULL)
pos += xprintf("%lu", (u_long)xf->xf_uid);
OpenPOWER on IntegriCloud