From 6df0a9277be244329d606ac81bcbd8b6284d8dde Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Mon, 6 Dec 1982 07:51:28 -0800 Subject: [PATCH] put back -s option SCCS-vsn: usr.bin/netstat/inet.c 4.6 SCCS-vsn: usr.bin/netstat/main.c 4.3 --- usr/src/usr.bin/netstat/inet.c | 65 +++++++++++++++++++++++++++++++++- usr/src/usr.bin/netstat/main.c | 36 +++++++++++++------ 2 files changed, 90 insertions(+), 11 deletions(-) diff --git a/usr/src/usr.bin/netstat/inet.c b/usr/src/usr.bin/netstat/inet.c index e3ec4ea95f..ec59f6eec2 100644 --- a/usr/src/usr.bin/netstat/inet.c +++ b/usr/src/usr.bin/netstat/inet.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)inet.c 4.5 82/11/14"; +static char sccsid[] = "@(#)inet.c 4.6 82/12/05"; #endif #include @@ -113,6 +113,69 @@ protopr(off, name) } } +/* + * Dump TCP statistics structure. + */ +tcp_stats(off, name) + off_t off; + char *name; +{ + struct tcpstat tcpstat; + + if (off == 0) { + printf("%sstat: symbol not in namelist\n", name); + return; + } + klseek(kmem, off, 0); + read(kmem, (char *)&tcpstat, sizeof (tcpstat)); + printf("%s:\n\t%d bad header checksums\n", name, tcpstat.tcps_badsum); + printf("\t%d bad header offset fields\n", tcpstat.tcps_badoff); + printf("\t%d incomplete headers\n", tcpstat.tcps_hdrops); +#ifdef notdef + printf("\t%d bad segments\n", tcpstat.tcps_badsegs); + printf("\t%d unacknowledged packets\n", tcpstat.tcps_unack); +#endif +} + +/* + * Dump UDP statistics structure. + */ +udp_stats(off, name) + off_t off; + char *name; +{ + struct udpstat udpstat; + + if (off == 0) { + printf("%sstat: symbol not in namelist\n", name); + return; + } + klseek(kmem, off, 0); + read(kmem, (char *)&udpstat, sizeof (udpstat)); + printf("%s:\n\t%d bad header checksums\n", name, udpstat.udps_badsum); + printf("\t%d incomplete headers\n", udpstat.udps_hdrops); + printf("\t%d bad data length fields\n", udpstat.udps_badlen); +} + +/* + * Dump IP statistics structure. + */ +ip_stats(off, name) + off_t off; + char *name; +{ + struct ipstat ipstat; + + if (off == 0) { + printf("%sstat: symbol not in namelist\n", name); + return; + } + klseek(kmem, off, 0); + read(kmem, (char *)&ipstat, sizeof (ipstat)); + printf("%s:\n\t%d bad header checksums\n", name, ipstat.ips_badsum); + printf("\t%d incomplete packets\n", ipstat.ips_tooshort); +} + /* * Pretty print an Internet address (net address + port). * If the nflag was specified, use numbers instead of names. diff --git a/usr/src/usr.bin/netstat/main.c b/usr/src/usr.bin/netstat/main.c index fa34ba7bf2..765b9e2d3a 100644 --- a/usr/src/usr.bin/netstat/main.c +++ b/usr/src/usr.bin/netstat/main.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)main.c 4.2 82/10/06"; +static char sccsid[] = "@(#)main.c 4.3 82/12/05"; #endif #include @@ -40,14 +40,25 @@ struct nlist nl[] = { 0, }; +extern int protopr(); +extern int tcp_stats(), udp_stats(), ip_stats(); + struct protox { - short pr_index; /* index into nlist of cb head */ - short pr_wanted; /* 1 if wanted, 0 otherwise */ - char *pr_name; /* well-known name */ + u_char pr_index; /* index into nlist of cb head */ + u_char pr_sindex; /* index into nlist of stat block */ + u_char pr_wanted; /* 1 if wanted, 0 otherwise */ + int (*pr_cblocks)(); /* control blocks printing routine */ + int (*pr_stats)(); /* statistics printing routine */ + char *pr_name; /* well-known name */ } protox[] = { - { N_TCB, 1, "tcp" }, - { N_UDB, 1, "udp" }, - { -1, 0, 0 } + { N_TCB, N_TCPSTAT, 1, protopr, + tcp_stats, "tcp" }, + { N_UDB, N_UDPSTAT, 1, protopr, + udp_stats, "udp" }, + { -1, N_IPSTAT, 1, 0, + ip_stats, "ip" }, + { -1, -1, 0, 0, + 0, 0 } }; struct pte *Sysmap; @@ -191,12 +202,17 @@ use: while (p = getprotoent()) { register struct protox *tp; - for (tp = protox; tp->pr_index >= 0; tp++) + for (tp = protox; tp->pr_name; tp++) if (strcmp(tp->pr_name, p->p_name) == 0) break; - if (tp->pr_index < 0 || tp->pr_wanted == 0) + if (tp->pr_name == 0 || tp->pr_wanted == 0) + continue; + if (sflag && tp->pr_stats) { + (*tp->pr_stats)(nl[tp->pr_sindex].n_value, p->p_name); continue; - protopr(nl[tp->pr_index].n_value, p->p_name); + } + if (tp->pr_cblocks) + (*tp->pr_cblocks)(nl[tp->pr_index].n_value, p->p_name); } endprotoent(); } -- 2.20.1