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.
This commit is contained in:
mux 2003-06-07 14:36:49 +00:00
parent d000b6db79
commit df4d18c70c

View File

@ -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);