mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-20 15:26:43 +01:00
Try to make netstat more smart about port numbers.
Feedback most welcome.
This commit is contained in:
parent
321a284625
commit
8d612dd2fc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=17796
@ -74,7 +74,7 @@ struct tcpcb tcpcb;
|
||||
struct socket sockb;
|
||||
|
||||
char *inetname __P((struct in_addr *));
|
||||
void inetprint __P((struct in_addr *, int, char *));
|
||||
void inetprint __P((struct in_addr *, int, char *, int));
|
||||
|
||||
/*
|
||||
* Print a summary of connections related to an Internet
|
||||
@ -141,8 +141,22 @@ protopr(off, name)
|
||||
printf("%8x ", (int)next);
|
||||
printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc,
|
||||
sockb.so_snd.sb_cc);
|
||||
inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport, name);
|
||||
inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport, name);
|
||||
if (nflag) {
|
||||
inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport,
|
||||
name, 1);
|
||||
inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport,
|
||||
name, 1);
|
||||
} else if (inpcb.inp_flags & INP_ANONPORT) {
|
||||
inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport,
|
||||
name, 1);
|
||||
inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport,
|
||||
name, 0);
|
||||
} else {
|
||||
inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport,
|
||||
name, 0);
|
||||
inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport,
|
||||
name, inpcb.inp_lport != inpcb.inp_fport);
|
||||
}
|
||||
if (istcp) {
|
||||
if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
|
||||
printf(" %d", tcpcb.t_state);
|
||||
@ -431,21 +445,21 @@ igmp_stats(off, name)
|
||||
|
||||
/*
|
||||
* Pretty print an Internet address (net address + port).
|
||||
* If the nflag was specified, use numbers instead of names.
|
||||
*/
|
||||
void
|
||||
inetprint(in, port, proto)
|
||||
inetprint(in, port, proto,numeric)
|
||||
register struct in_addr *in;
|
||||
int port;
|
||||
char *proto;
|
||||
int numeric;
|
||||
{
|
||||
struct servent *sp = 0;
|
||||
char line[80], *cp;
|
||||
int width;
|
||||
|
||||
sprintf(line, "%.*s.", (Aflag && !nflag) ? 12 : 16, inetname(in));
|
||||
sprintf(line, "%.*s.", (Aflag && !numeric) ? 12 : 16, inetname(in));
|
||||
cp = index(line, '\0');
|
||||
if (!nflag && port)
|
||||
if (!numeric && port)
|
||||
sp = getservbyport((int)port, proto);
|
||||
if (sp || port == 0)
|
||||
sprintf(cp, "%.15s", sp ? sp->s_name : "*");
|
||||
|
Loading…
Reference in New Issue
Block a user