BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / netstat / iso.c
index fffb2ae..2da77b2 100644 (file)
@@ -1,15 +1,46 @@
-/*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1989, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
  */
 
+#ifndef lint
+static char sccsid[] = "@(#)iso.c      5.6 (Berkeley) 4/27/91";
+#endif /* not lint */
+
 /*
  * $Header: iso.c,v 3.3 88/12/08 14:44:49 hagens Exp $
  * $Source: /usr/argo/src/ucb/netstat/RCS/iso.c,v $
  */
 /*******************************************************************************
 /*
  * $Header: iso.c,v 3.3 88/12/08 14:44:49 hagens Exp $
  * $Source: /usr/argo/src/ucb/netstat/RCS/iso.c,v $
  */
 /*******************************************************************************
-                         Copyright IBM Corporation 1987
+                 Copyright IBM Corporation 1987
 
                       All Rights Reserved
 
 
                       All Rights Reserved
 
@@ -32,9 +63,8 @@ SOFTWARE.
 *******************************************************************************/
 
 /*
 *******************************************************************************/
 
 /*
- *     ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
+ * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
  */
  */
-static char sccsid[] = "@(#)iso.c      5.1 (Berkeley) %G%";
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
@@ -56,10 +86,10 @@ static char sccsid[] = "@(#)iso.c   5.1 (Berkeley) %G%";
 #include <netiso/tp_param.h>
 #include <netiso/tp_states.h>
 #include <netiso/tp_astring.c>
 #include <netiso/tp_param.h>
 #include <netiso/tp_states.h>
 #include <netiso/tp_astring.c>
-#define KERNEL
 #include <netiso/tp_pcb.h>
 #include <netiso/tp_stat.h>
 #include <netiso/iso_pcb.h>
 #include <netiso/tp_pcb.h>
 #include <netiso/tp_stat.h>
 #include <netiso/iso_pcb.h>
+#include <netiso/cltp_var.h>
 #include <netiso/cons.h>
 #ifdef IncStat
 #undef IncStat
 #include <netiso/cons.h>
 #ifdef IncStat
 #undef IncStat
@@ -67,7 +97,6 @@ static char sccsid[] = "@(#)iso.c     5.1 (Berkeley) %G%";
 #include <netiso/cons_pcb.h>
 #include <netdb.h>
 
 #include <netiso/cons_pcb.h>
 #include <netdb.h>
 
-extern int kmem;
 
 /*
  *     Dump esis stats
 
 /*
  *     Dump esis stats
@@ -80,8 +109,7 @@ esis_stats(off, name)
 
        if (off == 0)
                return;
 
        if (off == 0)
                return;
-       klseek(kmem, off, 0);
-       read(kmem, (char *)&esis_stat, sizeof (struct esis_stat));
+       kvm_read(off, (char *)&esis_stat, sizeof (struct esis_stat));
        printf("%s:\n", name);
        printf("\t%d esh sent, %d esh received\n", esis_stat.es_eshsent,
                esis_stat.es_eshrcvd);
        printf("%s:\n", name);
        printf("\t%d esh sent, %d esh received\n", esis_stat.es_eshsent,
                esis_stat.es_eshrcvd);
@@ -109,8 +137,7 @@ clnp_stats(off, name)
 
        if (off == 0)
                return;
 
        if (off == 0)
                return;
-       klseek(kmem, off, 0);
-       read(kmem, (char *)&clnp_stat, sizeof (clnp_stat));
+       kvm_read(off, (char *)&clnp_stat, sizeof (clnp_stat));
 
        printf("%s:\n\t%d total packets sent\n", name, clnp_stat.cns_sent);
        printf("\t%d total fragments sent\n", clnp_stat.cns_fragments);
 
        printf("%s:\n\t%d total packets sent\n", name, clnp_stat.cns_sent);
        printf("\t%d total fragments sent\n", clnp_stat.cns_fragments);
@@ -133,6 +160,26 @@ clnp_stats(off, name)
        printf("\t%d clnp congestion experience bits received\n", 
                clnp_stat.cns_congest_rcvd);
 }
        printf("\t%d clnp congestion experience bits received\n", 
                clnp_stat.cns_congest_rcvd);
 }
+/*
+ * Dump CLTP statistics structure.
+ */
+cltp_stats(off, name)
+       off_t off;
+       char *name;
+{
+       struct cltpstat cltpstat;
+
+       if (off == 0)
+               return;
+       kvm_read(off, (char *)&cltpstat, sizeof (cltpstat));
+       printf("%s:\n\t%u incomplete header%s\n", name,
+               cltpstat.cltps_hdrops, plural(cltpstat.cltps_hdrops));
+       printf("\t%u bad data length field%s\n",
+               cltpstat.cltps_badlen, plural(cltpstat.cltps_badlen));
+       printf("\t%u bad checksum%s\n",
+               cltpstat.cltps_badsum, plural(cltpstat.cltps_badsum));
+}
+
 struct tp_pcb tpcb;
 struct isopcb isopcb;
 struct socket sockb;
 struct tp_pcb tpcb;
 struct isopcb isopcb;
 struct socket sockb;
@@ -141,8 +188,7 @@ struct sockaddr_iso siso;
 char   data[128];
 } laddr, faddr;
 #define kget(o, p) \
 char   data[128];
 } laddr, faddr;
 #define kget(o, p) \
-       (klseek(kmem, (off_t)(o), 0), read(kmem, (char *)&p, sizeof (p)))
-extern int kmem;
+       (kvm_read((off_t)(o), (char *)&p, sizeof (p)))
 extern int Aflag;
 extern int aflag;
 extern int nflag;
 extern int Aflag;
 extern int aflag;
 extern int nflag;
@@ -161,6 +207,7 @@ iso_protopr(off, name)
 {
        struct isopcb cb;
        register struct isopcb *prev, *next;
 {
        struct isopcb cb;
        register struct isopcb *prev, *next;
+       int istp = (strcmp(name, "tp") == 0);
 
        if (off == 0) {
                printf("%s control block: symbol not in namelist\n", name);
 
        if (off == 0) {
                printf("%s control block: symbol not in namelist\n", name);
@@ -180,15 +227,17 @@ iso_protopr(off, name)
                        break;
                }
                kget(isopcb.isop_socket, sockb);
                        break;
                }
                kget(isopcb.isop_socket, sockb);
-               kget(sockb.so_tpcb, tpcb);
-               if (tpcb.tp_state == ST_ERROR)
-                       fprintf(stderr,"addr: 0x%x, prev 0x%x\n", next, prev);
-               if (!aflag &&
-                       tpcb.tp_state == TP_LISTENING ||
-                       tpcb.tp_state == TP_CLOSED ||
-                       tpcb.tp_state == TP_REFWAIT) {
-                       prev = next;
-                       continue;
+               if (istp) {
+                       kget(sockb.so_tpcb, tpcb);
+                       if (tpcb.tp_state == ST_ERROR)
+                               fprintf(stderr,"addr: 0x%x, prev 0x%x\n", next, prev);
+                       if (!aflag &&
+                               tpcb.tp_state == TP_LISTENING ||
+                               tpcb.tp_state == TP_CLOSED ||
+                               tpcb.tp_state == TP_REFWAIT) {
+                               prev = next;
+                               continue;
+                       }
                }
                if (first) {
                        printf("Active ISO net connections");
                }
                if (first) {
                        printf("Active ISO net connections");
@@ -205,25 +254,36 @@ iso_protopr(off, name)
                        first = 0;
                }
                if (Aflag)
                        first = 0;
                }
                if (Aflag)
-                               printf("%8x ", sockb.so_tpcb);
+                       printf("%8x ",
+                               (istp ? (off_t)sockb.so_tpcb : (off_t)next));
                printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
                        sockb.so_snd.sb_cc);
                printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
                        sockb.so_snd.sb_cc);
-               if ((char *)isopcb.isop_laddr == ((char *)next) +
-                       _offsetof(struct isopcb, isop_sladdr))
-                       laddr.siso = isopcb.isop_sladdr;
-               else
-                       kget(isopcb.isop_laddr, laddr);
-               if ((char *)isopcb.isop_faddr == ((char *)next) +
-                       _offsetof(struct isopcb, isop_sfaddr))
-                       faddr.siso = isopcb.isop_sfaddr;
-               else
-                       kget(isopcb.isop_laddr, faddr);
-               isonetprint(&laddr, 1);
-               isonetprint(&faddr, 0);
-               if (tpcb.tp_state >= tp_NSTATES)
-                       printf(" %d", tpcb.tp_state);
-               else
-                       printf(" %-12.12s", tp_sstring[tpcb.tp_state]);
+               if (isopcb.isop_laddr == 0)
+                       printf("*.*\t");
+               else {
+                       if ((char *)isopcb.isop_laddr == ((char *)next) +
+                               _offsetof(struct isopcb, isop_sladdr))
+                               laddr.siso = isopcb.isop_sladdr;
+                       else
+                               kget(isopcb.isop_laddr, laddr);
+                       isonetprint(&laddr, 1);
+               }
+               if (isopcb.isop_faddr == 0)
+                       printf("*.*\t");
+               else {
+                       if ((char *)isopcb.isop_faddr == ((char *)next) +
+                               _offsetof(struct isopcb, isop_sfaddr))
+                               faddr.siso = isopcb.isop_sfaddr;
+                       else
+                               kget(isopcb.isop_faddr, faddr);
+                       isonetprint(&faddr, 0);
+               }
+               if (istp) {
+                       if (tpcb.tp_state >= tp_NSTATES)
+                               printf(" %d", tpcb.tp_state);
+                       else
+                               printf(" %-12.12s", tp_sstring[tpcb.tp_state]);
+               }
                putchar('\n');
                prev = next;
        }
                putchar('\n');
                prev = next;
        }
@@ -344,21 +404,18 @@ x25_protopr(off, name)
                printf("%s control block: symbol not in namelist\n", name);
                return;
        }
                printf("%s control block: symbol not in namelist\n", name);
                return;
        }
-       klseek(kmem, off, 0);
-       read(kmem, &xpcb, sizeof (struct x25_pcb));
+       kvm_read(off, &xpcb, sizeof (struct x25_pcb));
        prev = (struct isopcb *)off;
        if (xpcb.x_next == (struct isopcb *)off)
                return;
        while (xpcb.x_next != (struct isopcb *)off) {
                next = isopcb.isop_next;
        prev = (struct isopcb *)off;
        if (xpcb.x_next == (struct isopcb *)off)
                return;
        while (xpcb.x_next != (struct isopcb *)off) {
                next = isopcb.isop_next;
-               klseek(kmem, (off_t)next, 0);
-               read(kmem, &xpcb, sizeof (struct x25_pcb));
+               kvm_read((off_t)next, &xpcb, sizeof (struct x25_pcb));
                if (xpcb.x_prev != prev) {
                        printf("???\n");
                        break;
                }
                if (xpcb.x_prev != prev) {
                        printf("???\n");
                        break;
                }
-               klseek(kmem, (off_t)xpcb.x_socket, 0);
-               read(kmem, &sockb, sizeof (sockb));
+               kvm_read((off_t)xpcb.x_socket, &sockb, sizeof (sockb));
 
                if (!aflag &&
                        xpcb.x_state == LISTENING ||
 
                if (!aflag &&
                        xpcb.x_state == LISTENING ||
@@ -405,6 +462,7 @@ caddr_t off, name;
                printf("TP not configured\n\n");
                return;
        }
                printf("TP not configured\n\n");
                return;
        }
+       printf("%s:\n", name);
        kget(off, tp_stat);
        tprintstat(&tp_stat, 8);
 }
        kget(off, tp_stat);
        tprintstat(&tp_stat, 8);
 }
@@ -689,7 +747,7 @@ int islocal;
        putchar(' ');
 }
 static char hexlist[] = "0123456789abcdef", obuf[128];
        putchar(' ');
 }
 static char hexlist[] = "0123456789abcdef", obuf[128];
-static
+
 hexprint(n, buf, delim)
 char *buf, *delim;
 {
 hexprint(n, buf, delim)
 char *buf, *delim;
 {
@@ -697,6 +755,8 @@ char *buf, *delim;
        register char *out = obuf;
        register int i;
 
        register char *out = obuf;
        register int i;
 
+       if (n == 0)
+               return;
        while (in < top) {
                i = *in++;
                *out++ = '.';
        while (in < top) {
                i = *in++;
                *out++ = '.';