From ae94c42781bbb64137bac1b02ba3dff0889ed2e1 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 24 Dec 2004 02:23:50 +0000 Subject: [PATCH] Add the -P flag which displays more PCB information (in particular, TCP). In particular, information related to the TCP window parameters, unacked data, and connection RTT. --- usr.bin/netstat/inet.c | 29 ++++++++++++++++++++++++++++- usr.bin/netstat/main.c | 8 ++++++-- usr.bin/netstat/netstat.1 | 7 +++++-- usr.bin/netstat/netstat.h | 3 ++- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index 2a532b9e07..6b103a738a 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -32,7 +32,7 @@ * * @(#)inet.c 8.5 (Berkeley) 5/24/95 * $FreeBSD: src/usr.bin/netstat/inet.c,v 1.37.2.11 2003/11/27 14:46:49 ru Exp $ - * $DragonFly: src/usr.bin/netstat/inet.c,v 1.16 2004/12/20 11:03:16 joerg Exp $ + * $DragonFly: src/usr.bin/netstat/inet.c,v 1.17 2004/12/24 02:23:50 dillon Exp $ */ #include @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -175,6 +176,14 @@ static void outputpcb(int proto, const char *name, struct inpcb *inp, struct xsocket *so, struct tcpcb *tp) { const char *vchar; + static struct clockinfo clockinfo; + + if (clockinfo.hz == 0) { + int size = sizeof(clockinfo); + sysctlbyname("kern.clockrate", &clockinfo, &size, NULL, 0); + if (clockinfo.hz == 0) + clockinfo.hz = 100; + } /* Ignore sockets for protocols other than the desired one. */ if (so->xso_protocol != (int)proto) @@ -220,6 +229,8 @@ outputpcb(int proto, const char *name, struct inpcb *inp, struct xsocket *so, st putchar('\n'); if (Aflag) printf("%-8.8s ", "Socket"); + if (Pflag) + printf("%8.8s %8.8s %8.8s ", "TxWin", "Unacked", "RTT/ms"); if (Lflag) { printf("%-5.5s %-14.14s %-22.22s\n", "Proto", "Listen", "Local Address"); @@ -241,6 +252,22 @@ outputpcb(int proto, const char *name, struct inpcb *inp, struct xsocket *so, st else printf("%8lx ", (u_long)so->so_pcb); } + if (Pflag) { + if (tp) { + int window = MIN(tp->snd_cwnd, tp->snd_bwnd); + if (window == 1073725440) + printf("%8s ", "max"); + else + printf("%8d ", (int)MIN(tp->snd_cwnd, tp->snd_bwnd)); + printf("%8d ", (int)(tp->snd_max - tp->snd_una)); + if (tp->t_srtt == 0) + printf("%8s ", "-"); + else + printf("%8.3f ", (double)tp->t_srtt * 1000.0 / TCP_RTT_SCALE / clockinfo.hz); + } else { + printf("%8s %8s %8s ", "-", "-", "-"); + } + } #ifdef INET6 if ((inp->inp_vflag & INP_IPV6) != 0) vchar = ((inp->inp_vflag & INP_IPV4) != 0) ? "46" : "6 "; diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index f1ba48d847..ca831d2220 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1983, 1988, 1993 Regents of the University of California. All rights reserved. * @(#)main.c 8.4 (Berkeley) 3/1/94 * $FreeBSD: src/usr.bin/netstat/main.c,v 1.34.2.12 2001/09/17 15:17:46 ru Exp $ - * $DragonFly: src/usr.bin/netstat/main.c,v 1.6 2004/03/08 22:41:05 dillon Exp $ + * $DragonFly: src/usr.bin/netstat/main.c,v 1.7 2004/12/24 02:23:50 dillon Exp $ */ #include @@ -307,6 +307,7 @@ int gflag; /* show group (multicast) routing or stats */ int iflag; /* show interfaces */ int Lflag; /* show size of listen queues */ int mflag; /* show memory stats */ +int Pflag; /* show more protocol info (go past 80 columns) */ int numeric_addr; /* show addresses numerically */ int numeric_port; /* show ports numerically */ static int pflag; /* show given protocol */ @@ -332,7 +333,7 @@ main(int argc, char **argv) af = AF_UNSPEC; - while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rSsBtuWw:z")) != -1) + while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:nPp:rSsBtuWw:z")) != -1) switch(ch) { case 'A': Aflag = 1; @@ -411,6 +412,9 @@ main(int argc, char **argv) case 'n': numeric_addr = numeric_port = 1; break; + case 'P': + Pflag = 1; + break; case 'p': if ((tp = name2protox(optarg)) == NULL) { errx(1, diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index d8346bd2ac..0fc7172596 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -31,7 +31,7 @@ .\" .\" @(#)netstat.1 8.8 (Berkeley) 4/18/94 .\" $FreeBSD: src/usr.bin/netstat/netstat.1,v 1.22.2.13 2003/05/03 22:10:02 keramida Exp $ -.\" $DragonFly: src/usr.bin/netstat/netstat.1,v 1.4 2004/03/08 22:41:05 dillon Exp $ +.\" $DragonFly: src/usr.bin/netstat/netstat.1,v 1.5 2004/12/24 02:23:50 dillon Exp $ .\" .Dd September 7, 2001 .Dt NETSTAT 1 @@ -50,7 +50,7 @@ depending on the options for the information presented. .It Xo .Bk -words .Nm -.Op Fl AaLlnSW +.Op Fl AaLlnPSW .Op Fl f Ar protocol_family | Fl p Ar protocol .Op Fl M Ar core .Op Fl N Ar system @@ -318,6 +318,9 @@ Normally .Nm attempts to resolve addresses and ports, and display them symbolically. +.It Fl P +Display additional protocol-specific information. For TCP the current +transmit window, unacked sequence space, and RTT is displayed. .It Fl W In certain displays, avoid truncating addresses even if this causes some fields to overflow. diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index 01f98b89c2..7c905071f6 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -32,7 +32,7 @@ * * @(#)netstat.h 8.2 (Berkeley) 1/4/94 * $FreeBSD: src/usr.bin/netstat/netstat.h,v 1.16.2.7 2001/09/17 15:17:46 ru Exp $ - * $DragonFly: src/usr.bin/netstat/netstat.h,v 1.4 2004/03/08 22:41:05 dillon Exp $ + * $DragonFly: src/usr.bin/netstat/netstat.h,v 1.5 2004/12/24 02:23:50 dillon Exp $ */ #include @@ -45,6 +45,7 @@ extern int gflag; /* show group (multicast) routing or stats */ extern int iflag; /* show interfaces */ extern int Lflag; /* show size of listen queues */ extern int mflag; /* show memory stats */ +extern int Pflag; /* show more protocol info */ extern int numeric_addr; /* show addresses numerically */ extern int numeric_port; /* show ports numerically */ extern int rflag; /* show routing tables (or routing stats) */ -- 2.41.0