From df4d18c70c74ae792c0e50657c3a501026e37258 Mon Sep 17 00:00:00 2001 From: mux Date: Sat, 7 Jun 2003 14:36:49 +0000 Subject: [PATCH] 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. --- usr.bin/sockstat/sockstat.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c index 1212be10fa7a..b68906e5172a 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);