diff options
-rw-r--r-- | usr.bin/netstat/inet.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index 3046796..abcfa6d 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -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 : "*"); |