put back -s option
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Mon, 6 Dec 1982 15:51:28 +0000 (07:51 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Mon, 6 Dec 1982 15:51:28 +0000 (07:51 -0800)
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
usr/src/usr.bin/netstat/main.c

index e3ec4ea..ec59f6e 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)inet.c     4.5 82/11/14";
+static char sccsid[] = "@(#)inet.c     4.6 82/12/05";
 #endif
 
 #include <sys/types.h>
 #endif
 
 #include <sys/types.h>
@@ -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.
 /*
  * Pretty print an Internet address (net address + port).
  * If the nflag was specified, use numbers instead of names.
index fa34ba7..765b9e2 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)main.c     4.2 82/10/06";
+static char sccsid[] = "@(#)main.c     4.3 82/12/05";
 #endif
 
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
@@ -40,14 +40,25 @@ struct nlist nl[] = {
        0,
 };
 
        0,
 };
 
+extern int protopr();
+extern int tcp_stats(), udp_stats(), ip_stats();
+
 struct protox {
 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[] = {
 } 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;
 };
 
 struct pte *Sysmap;
@@ -191,12 +202,17 @@ use:
        while (p = getprotoent()) {
                register struct protox *tp;
 
        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 (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;
                        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();
 }
        }
        endprotoent();
 }