BSD 4_4 release
[unix-history] / usr / src / usr.bin / netstat / iso.c
index cf6c6c1..1eecf15 100644 (file)
@@ -1,25 +1,56 @@
 /*
 /*
- * 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) 1983, 1988, 1993
+ *     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      8.1 (Berkeley) 6/6/93";
+#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 1.5 92/06/04 00:36:32 leres Exp $
+ * $Source: /usr/src/usr.bin/netstat/RCS/iso.c,v $
  */
 /*******************************************************************************
  */
 /*******************************************************************************
-                         Copyright IBM Corporation 1987
+                 Copyright IBM Corporation 1987
 
                       All Rights Reserved
 
 
                       All Rights Reserved
 
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
 provided that the above copyright notice appear in all copies and that
 provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
+both that copyright notice and this permission notice appear in
 supporting documentation, and that the name of IBM not be
 used in advertising or publicity pertaining to distribution of the
 supporting documentation, and that the name of IBM not be
 used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
+software without specific, written prior permission.
 
 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 
 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
@@ -32,13 +63,11 @@ 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.4 (Berkeley) 6/18/90";
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
-#define KERNEL
 #include <sys/time.h>
 #include <sys/domain.h>
 #include <sys/protosw.h>
 #include <sys/time.h>
 #include <sys/domain.h>
 #include <sys/protosw.h>
@@ -47,6 +76,11 @@ static char sccsid[] = "@(#)iso.c    5.4 (Berkeley) 6/18/90";
 #include <errno.h>
 #include <net/if.h>
 #include <net/route.h>
 #include <errno.h>
 #include <net/if.h>
 #include <net/route.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/in_pcb.h>
+#include <netinet/ip_var.h>
 #include <netiso/iso.h>
 #include <netiso/iso_errno.h>
 #include <netiso/clnp.h>
 #include <netiso/iso.h>
 #include <netiso/iso_errno.h>
 #include <netiso/clnp.h>
@@ -56,7 +90,6 @@ static char sccsid[] = "@(#)iso.c     5.4 (Berkeley) 6/18/90";
 #undef satosiso
 #include <netiso/tp_param.h>
 #include <netiso/tp_states.h>
 #undef satosiso
 #include <netiso/tp_param.h>
 #include <netiso/tp_states.h>
-#include <netiso/tp_astring.c>
 #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>
@@ -66,21 +99,31 @@ static char sccsid[] = "@(#)iso.c   5.4 (Berkeley) 6/18/90";
 #undef IncStat
 #endif
 #include <netiso/cons_pcb.h>
 #undef IncStat
 #endif
 #include <netiso/cons_pcb.h>
+#include <arpa/inet.h>
 #include <netdb.h>
 #include <netdb.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "netstat.h"
 
 
+static void tprintstat __P((struct tp_stat *, int));
+static void isonetprint __P((struct sockaddr_iso *, int));
+static void hexprint __P((int, char *, char *));
+extern void inetprint __P((struct in_addr *, int, char *));
 
 /*
  *     Dump esis stats
  */
 
 /*
  *     Dump esis stats
  */
+void
 esis_stats(off, name)
 esis_stats(off, name)
-       off_t   off;
+       u_long  off;
        char    *name;
 {
        struct esis_stat esis_stat;
 
        char    *name;
 {
        struct esis_stat esis_stat;
 
-       if (off == 0)
+       if (off == 0 ||
+           kread(off, (char *)&esis_stat, sizeof (struct esis_stat)))
                return;
                return;
-       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);
@@ -88,10 +131,10 @@ esis_stats(off, name)
                esis_stat.es_ishrcvd);
        printf("\t%d rd sent, %d rd received\n", esis_stat.es_rdsent,
                esis_stat.es_rdrcvd);
                esis_stat.es_ishrcvd);
        printf("\t%d rd sent, %d rd received\n", esis_stat.es_rdsent,
                esis_stat.es_rdrcvd);
-       printf("\t%d pdus not sent due to insufficient memory\n", 
+       printf("\t%d pdus not sent due to insufficient memory\n",
                esis_stat.es_nomem);
        printf("\t%d pdus received with bad checksum\n", esis_stat.es_badcsum);
                esis_stat.es_nomem);
        printf("\t%d pdus received with bad checksum\n", esis_stat.es_badcsum);
-       printf("\t%d pdus received with bad version number\n", 
+       printf("\t%d pdus received with bad version number\n",
                esis_stat.es_badvers);
        printf("\t%d pdus received with bad type field\n", esis_stat.es_badtype);
        printf("\t%d short pdus received\n", esis_stat.es_toosmall);
                esis_stat.es_badvers);
        printf("\t%d pdus received with bad type field\n", esis_stat.es_badtype);
        printf("\t%d short pdus received\n", esis_stat.es_toosmall);
@@ -100,49 +143,51 @@ esis_stats(off, name)
 /*
  * Dump clnp statistics structure.
  */
 /*
  * Dump clnp statistics structure.
  */
+void
 clnp_stats(off, name)
 clnp_stats(off, name)
-       off_t off;
+       u_long off;
        char *name;
 {
        struct clnp_stat clnp_stat;
 
        char *name;
 {
        struct clnp_stat clnp_stat;
 
-       if (off == 0)
+       if (off == 0 ||
+           kread(off, (char *)&clnp_stat, sizeof (clnp_stat)))
                return;
                return;
-       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("\t%d total packets received\n", clnp_stat.cns_total);
 
        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("\t%d total packets received\n", clnp_stat.cns_total);
-       printf("\t%d with fixed part of header too small\n", 
+       printf("\t%d with fixed part of header too small\n",
                clnp_stat.cns_toosmall);
        printf("\t%d with header length not reasonable\n", clnp_stat.cns_badhlen);
                clnp_stat.cns_toosmall);
        printf("\t%d with header length not reasonable\n", clnp_stat.cns_badhlen);
-       printf("\t%d incorrect checksum%s\n", 
+       printf("\t%d incorrect checksum%s\n",
                clnp_stat.cns_badcsum, plural(clnp_stat.cns_badcsum));
        printf("\t%d with unreasonable address lengths\n", clnp_stat.cns_badaddr);
                clnp_stat.cns_badcsum, plural(clnp_stat.cns_badcsum));
        printf("\t%d with unreasonable address lengths\n", clnp_stat.cns_badaddr);
-       printf("\t%d with forgotten segmentation information\n", 
+       printf("\t%d with forgotten segmentation information\n",
                clnp_stat.cns_noseg);
        printf("\t%d with an incorrect protocol identifier\n", clnp_stat.cns_noproto);
        printf("\t%d with an incorrect version\n", clnp_stat.cns_badvers);
                clnp_stat.cns_noseg);
        printf("\t%d with an incorrect protocol identifier\n", clnp_stat.cns_noproto);
        printf("\t%d with an incorrect version\n", clnp_stat.cns_badvers);
-       printf("\t%d dropped because the ttl has expired\n", 
+       printf("\t%d dropped because the ttl has expired\n",
                clnp_stat.cns_ttlexpired);
        printf("\t%d clnp cache misses\n", clnp_stat.cns_cachemiss);
                clnp_stat.cns_ttlexpired);
        printf("\t%d clnp cache misses\n", clnp_stat.cns_cachemiss);
-       printf("\t%d clnp congestion experience bits set\n", 
+       printf("\t%d clnp congestion experience bits set\n",
                clnp_stat.cns_congest_set);
                clnp_stat.cns_congest_set);
-       printf("\t%d clnp congestion experience bits received\n", 
+       printf("\t%d clnp congestion experience bits received\n",
                clnp_stat.cns_congest_rcvd);
 }
 /*
  * Dump CLTP statistics structure.
  */
                clnp_stat.cns_congest_rcvd);
 }
 /*
  * Dump CLTP statistics structure.
  */
+void
 cltp_stats(off, name)
 cltp_stats(off, name)
-       off_t off;
+       u_long off;
        char *name;
 {
        struct cltpstat cltpstat;
 
        char *name;
 {
        struct cltpstat cltpstat;
 
-       if (off == 0)
+       if (off == 0 ||
+           kread(off, (char *)&cltpstat, sizeof (cltpstat)))
                return;
                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",
        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",
@@ -155,14 +200,11 @@ struct    tp_pcb tpcb;
 struct isopcb isopcb;
 struct socket sockb;
 union  {
 struct isopcb isopcb;
 struct socket sockb;
 union  {
-struct sockaddr_iso    siso;
-char   data[128];
+       struct sockaddr_iso     siso;
+       char    data[128];
 } laddr, faddr;
 #define kget(o, p) \
 } laddr, faddr;
 #define kget(o, p) \
-       (kvm_read((off_t)(o), (char *)&p, sizeof (p)))
-extern int Aflag;
-extern int aflag;
-extern int nflag;
+       (kread((u_long)(o), (char *)&p, sizeof (p)))
 
 static int first = 1;
 
 
 static int first = 1;
 
@@ -172,19 +214,24 @@ static    int first = 1;
  * Listening processes (aflag) are suppressed unless the
  * -a (all) flag is specified.
  */
  * Listening processes (aflag) are suppressed unless the
  * -a (all) flag is specified.
  */
+void
 iso_protopr(off, name)
 iso_protopr(off, name)
-       off_t off;
+       u_long off;
        char *name;
 {
        struct isopcb cb;
        register struct isopcb *prev, *next;
        char *name;
 {
        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);
                return;
        }
 
        if (off == 0) {
                printf("%s control block: symbol not in namelist\n", name);
                return;
        }
-       kget(off, cb);
+       if (strcmp(name, "tp") == 0) {
+               tp_protopr(off, name);
+               return;
+       }
+       if (kread(off, (char *)&cb, sizeof(cb)))
+               return;
        isopcb = cb;
        prev = (struct isopcb *)off;
        if (isopcb.isop_next == (struct isopcb *)off)
        isopcb = cb;
        prev = (struct isopcb *)off;
        if (isopcb.isop_next == (struct isopcb *)off)
@@ -198,68 +245,125 @@ iso_protopr(off, name)
                        break;
                }
                kget(isopcb.isop_socket, sockb);
                        break;
                }
                kget(isopcb.isop_socket, sockb);
-               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 (aflag)
-                               printf(" (including servers)");
-                       putchar('\n');
-                       if (Aflag)
-                               printf("%-8.8s ", "PCB");
-                       printf(Aflag ?
-                               "%-5.5s %-6.6s %-6.6s  %-18.18s %-18.18s %s\n" :
-                               "%-5.5s %-6.6s %-6.6s  %-22.22s %-22.22s %s\n",
-                               "Proto", "Recv-Q", "Send-Q",
-                               "Local Address", "Foreign Address", "(state)");
-                       first = 0;
-               }
+               iso_protopr1((u_long)next, 0);
+               putchar('\n');
+               prev = next;
+       }
+}
+
+void
+iso_protopr1(kern_addr, istp)
+       u_long kern_addr;
+       int istp;
+{
+       if (first) {
+               printf("Active ISO net connections");
+               if (aflag)
+                       printf(" (including servers)");
+               putchar('\n');
                if (Aflag)
                if (Aflag)
+                       printf("%-8.8s ", "PCB");
+               printf(Aflag ?
+                       "%-5.5s %-6.6s %-6.6s  %-18.18s %-18.18s %s\n" :
+                       "%-5.5s %-6.6s %-6.6s  %-22.22s %-22.22s %s\n",
+                       "Proto", "Recv-Q", "Send-Q",
+                       "Local Address", "Foreign Address", "(state)");
+               first = 0;
+       }
+       if (Aflag)
                        printf("%8x ",
                        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);
-               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)
+                                       (sockb.so_pcb ? (void *)sockb.so_pcb : (void *)kern_addr));
+       printf("%-5.5s %6d %6d ", "tp", sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc);
+       if (istp && tpcb.tp_lsuffixlen) {
+                       hexprint(tpcb.tp_lsuffixlen, tpcb.tp_lsuffix, "()");
+                       printf("\t");
+       } else if (isopcb.isop_laddr == 0)
                        printf("*.*\t");
                        printf("*.*\t");
-               else {
-                       if ((char *)isopcb.isop_faddr == ((char *)next) +
-                               _offsetof(struct isopcb, isop_sfaddr))
-                               faddr.siso = isopcb.isop_sfaddr;
+       else {
+                       if ((char *)isopcb.isop_laddr == ((char *)kern_addr) +
+                                       _offsetof(struct isopcb, isop_sladdr))
+                                       laddr.siso = isopcb.isop_sladdr;
                        else
                        else
-                               kget(isopcb.isop_faddr, faddr);
-                       isonetprint(&faddr, 0);
+                                       kget(isopcb.isop_laddr, laddr);
+                       isonetprint((struct sockaddr_iso *)&laddr, 1);
+       }
+       if (istp && tpcb.tp_fsuffixlen) {
+                       hexprint(tpcb.tp_fsuffixlen, tpcb.tp_fsuffix, "()");
+                       printf("\t");
+       } else if (isopcb.isop_faddr == 0)
+               printf("*.*\t");
+       else {
+               if ((char *)isopcb.isop_faddr == ((char *)kern_addr) +
+                       _offsetof(struct isopcb, isop_sfaddr))
+                       faddr.siso = isopcb.isop_sfaddr;
+               else
+                       kget(isopcb.isop_faddr, faddr);
+               isonetprint((struct sockaddr_iso *)&faddr, 0);
+       }
+}
+
+void
+tp_protopr(off, name)
+       u_long off;
+       char *name;
+{
+       extern char *tp_sstring[];
+       struct tp_ref *tpr, *tpr_base;
+       struct tp_refinfo tpkerninfo;
+       int size;
+
+       kget(off, tpkerninfo);
+       size = tpkerninfo.tpr_size * sizeof (*tpr);
+       tpr_base = (struct tp_ref *)malloc(size);
+       if (tpr_base == 0)
+               return;
+       kread((u_long)(tpkerninfo.tpr_base), (char *)tpr_base, size);
+       for (tpr = tpr_base; tpr < tpr_base + tpkerninfo.tpr_size; tpr++) {
+               if (tpr->tpr_pcb == 0)
+                       continue;
+               kget(tpr->tpr_pcb, tpcb);
+               if (tpcb.tp_state == ST_ERROR)
+                       printf("undefined tpcb state: 0x%x\n", tpr->tpr_pcb);
+               if (!aflag &&
+                       (tpcb.tp_state == TP_LISTENING ||
+                        tpcb.tp_state == TP_CLOSED ||
+                        tpcb.tp_state == TP_REFWAIT)) {
+                       continue;
                }
                }
-               if (istp) {
-                       if (tpcb.tp_state >= tp_NSTATES)
-                               printf(" %d", tpcb.tp_state);
-                       else
-                               printf(" %-12.12s", tp_sstring[tpcb.tp_state]);
+               kget(tpcb.tp_sock, sockb);
+               if (tpcb.tp_npcb) switch(tpcb.tp_netservice) {
+                       case IN_CLNS:
+                               tp_inproto((u_long)tpkerninfo.tpr_base);
+                               break;
+                       default:
+                               kget(tpcb.tp_npcb, isopcb);
+                               iso_protopr1((u_long)tpcb.tp_npcb, 1);
+                               break;
                }
                }
+               if (tpcb.tp_state >= tp_NSTATES)
+                       printf(" %d", tpcb.tp_state);
+               else
+                       printf(" %-12.12s", tp_sstring[tpcb.tp_state]);
                putchar('\n');
                putchar('\n');
-               prev = next;
        }
 }
 
        }
 }
 
+void
+tp_inproto(pcb)
+       u_long pcb;
+{
+       struct inpcb inpcb;
+       kget(tpcb.tp_npcb, inpcb);
+       if (!aflag && inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)
+               return;
+       if (Aflag)
+               printf("%8x ", pcb);
+       printf("%-5.5s %6d %6d ", "tpip",
+           sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc);
+       inetprint(&inpcb.inp_laddr, inpcb.inp_lport, "tp");
+       inetprint(&inpcb.inp_faddr, inpcb.inp_fport, "tp");
+}
+
 /*
  * Pretty print an iso address (net address + port).
  * If the nflag was specified, use numbers instead of names.
 /*
  * Pretty print an iso address (net address + port).
  * If the nflag was specified, use numbers instead of names.
@@ -276,7 +380,6 @@ isonetname(iso)
        struct iso_hostent *iso_getserventrybytsel();
        struct iso_hostent Ihe;
        static char line[80];
        struct iso_hostent *iso_getserventrybytsel();
        struct iso_hostent Ihe;
        static char line[80];
-       char *index();
 
        bzero(line, sizeof(line));
        if( iso->isoa_afi ) {
 
        bzero(line, sizeof(line));
        if( iso->isoa_afi ) {
@@ -299,6 +402,7 @@ isonetname(iso)
        return line;
 }
 
        return line;
 }
 
+static void
 isonetprint(iso, sufx, sufxlen, islocal)
        register struct iso_addr *iso;
        char *sufx;
 isonetprint(iso, sufx, sufxlen, islocal)
        register struct iso_addr *iso;
        char *sufx;
@@ -307,7 +411,7 @@ isonetprint(iso, sufx, sufxlen, islocal)
 {
        struct iso_hostent *iso_getserventrybytsel(), *ihe;
        struct iso_hostent Ihe;
 {
        struct iso_hostent *iso_getserventrybytsel(), *ihe;
        struct iso_hostent Ihe;
-       char *line, *cp, *index();
+       char *line, *cp;
        int Alen = Aflag?18:22;
 
        line =  isonetname(iso);
        int Alen = Aflag?18:22;
 
        line =  isonetname(iso);
@@ -316,7 +420,7 @@ isonetprint(iso, sufx, sufxlen, islocal)
 
        if( islocal )
                islocal = 20;
 
        if( islocal )
                islocal = 20;
-       else 
+       else
                islocal = 22 + Alen;
 
        if(Aflag)
                islocal = 22 + Alen;
 
        if(Aflag)
@@ -356,8 +460,9 @@ isonetprint(iso, sufx, sufxlen, islocal)
 #endif
 
 #ifdef notdef
 #endif
 
 #ifdef notdef
+static void
 x25_protopr(off, name)
 x25_protopr(off, name)
-       off_t off;
+       u_long off;
        char *name;
 {
        static char *xpcb_states[] = {
        char *name;
 {
        static char *xpcb_states[] = {
@@ -375,18 +480,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;
        }
-       kvm_read(off, &xpcb, sizeof (struct x25_pcb));
+       kread(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;
-               kvm_read((off_t)next, &xpcb, sizeof (struct x25_pcb));
+               kread((u_long)next, &xpcb, sizeof (struct x25_pcb));
                if (xpcb.x_prev != prev) {
                        printf("???\n");
                        break;
                }
                if (xpcb.x_prev != prev) {
                        printf("???\n");
                        break;
                }
-               kvm_read((off_t)xpcb.x_socket, &sockb, sizeof (sockb));
+               kread((u_long)xpcb.x_socket, &sockb, sizeof (sockb));
 
                if (!aflag &&
                        xpcb.x_state == LISTENING ||
 
                if (!aflag &&
                        xpcb.x_state == LISTENING ||
@@ -410,9 +515,9 @@ x25_protopr(off, name)
                }
                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);
-               isonetprint(&xpcb.x_laddr.siso_addr, &xpcb.x_lport, 
+               isonetprint(&xpcb.x_laddr.siso_addr, &xpcb.x_lport,
                        sizeof(xpcb.x_lport), 1);
                        sizeof(xpcb.x_lport), 1);
-               isonetprint(&xpcb.x_faddr.siso_addr, &xpcb.x_fport, 
+               isonetprint(&xpcb.x_faddr.siso_addr, &xpcb.x_fport,
                        sizeof(xpcb.x_lport), 0);
                if (xpcb.x_state < 0 || xpcb.x_state >= x25_NSTATES)
                        printf(" 0x0x0x0x0x0x0x0x0x%x", xpcb.x_state);
                        sizeof(xpcb.x_lport), 0);
                if (xpcb.x_state < 0 || xpcb.x_state >= x25_NSTATES)
                        printf(" 0x0x0x0x0x0x0x0x0x%x", xpcb.x_state);
@@ -426,8 +531,9 @@ x25_protopr(off, name)
 
 struct tp_stat tp_stat;
 
 
 struct tp_stat tp_stat;
 
+void
 tp_stats(off, name)
 tp_stats(off, name)
-caddr_t off, name;
+       caddr_t off, name;
 {
        if (off == 0) {
                printf("TP not configured\n\n");
 {
        if (off == 0) {
                printf("TP not configured\n\n");
@@ -440,11 +546,10 @@ caddr_t off, name;
 
 #define OUT stdout
 
 
 #define OUT stdout
 
-#define plural(x) (x>1?"s":"")
-
+static void
 tprintstat(s, indent)
 tprintstat(s, indent)
-register struct tp_stat *s;
-int indent;
+       register struct tp_stat *s;
+       int indent;
 {
        fprintf(OUT,
                "%*sReceiving:\n",indent," ");
 {
        fprintf(OUT,
                "%*sReceiving:\n",indent," ");
@@ -515,7 +620,7 @@ int indent;
                "\t%*s%d cluster%s\n", indent, " ",
                s->ts_mb_cluster, plural(s->ts_mb_cluster));
        fprintf(OUT,
                "\t%*s%d cluster%s\n", indent, " ",
                s->ts_mb_cluster, plural(s->ts_mb_cluster));
        fprintf(OUT,
-               "\t%*s%d source quench \n",indent, " ", 
+               "\t%*s%d source quench \n",indent, " ",
                s->ts_quench);
        fprintf(OUT,
                "\t%*s%d dec bit%s\n", indent, " ",
                s->ts_quench);
        fprintf(OUT,
                "\t%*s%d dec bit%s\n", indent, " ",
@@ -563,46 +668,35 @@ int indent;
        fprintf(OUT,
                "\t%*s%d tp 0 connection%s\n",  indent, " ",
                s->ts_tp0_conn ,plural(s->ts_tp0_conn));
        fprintf(OUT,
                "\t%*s%d tp 0 connection%s\n",  indent, " ",
                s->ts_tp0_conn ,plural(s->ts_tp0_conn));
-       {
-               register int j, div;
-               register float f;
+    {
+               register int j;
                static char *name[]= {
                static char *name[]= {
-                       "~LOCAL, PDN", 
+                       "~LOCAL, PDN",
                        "~LOCAL,~PDN",
                        " LOCAL,~PDN",
                        " LOCAL, PDN"
                };
                        "~LOCAL,~PDN",
                        " LOCAL,~PDN",
                        " LOCAL, PDN"
                };
-#define factor(i) \
-       div = (s->ts_rtt[(i)].tv_sec * 1000000) + \
-               s->ts_rtt[(i)].tv_usec ;\
-       if(div) {\
-               f = ((s->ts_rtv[(i)].tv_sec * 1000000) + \
-                               s->ts_rtv[(i)].tv_usec)/div;  \
-               div = (int) (f + 0.5);\
-       }
 
 
-               fprintf(OUT, 
-                       "\n%*sRound trip times, listed in (sec: usec):\n", indent, " ");
-               fprintf(OUT, 
+               fprintf(OUT,
+                       "\n%*sRound trip times, listed in ticks:\n", indent, " ");
+               fprintf(OUT,
                        "\t%*s%11.11s  %12.12s | %12.12s | %s\n", indent, " ",
                                "Category",
                                "Smoothed avg", "Deviation", "Deviation/Avg");
                        "\t%*s%11.11s  %12.12s | %12.12s | %s\n", indent, " ",
                                "Category",
                                "Smoothed avg", "Deviation", "Deviation/Avg");
-               for( j=0; j<=3; j++) {
-                       factor(j);
+               for (j = 0; j <= 3; j++) {
                        fprintf(OUT,
                        fprintf(OUT,
-                               "\t%*s%11.11s: %5d:%-6d | %5d:%-6d | %-6d\n", indent, " ",
+                               "\t%*s%11.11s: %-11d | %-11d | %-11d | %-11d\n", indent, " ",
                                name[j],
                                name[j],
-                               s->ts_rtt[j].tv_sec,
-                               s->ts_rtt[j].tv_usec,
-                               s->ts_rtv[j].tv_sec,
-                               s->ts_rtv[j].tv_usec,
-                               div);
+                               s->ts_rtt[j],
+                               s->ts_rtt[j],
+                               s->ts_rtv[j],
+                               s->ts_rtv[j]);
                }
        }
        fprintf(OUT,
 "\n%*sTpdus RECVD [%d valid, %3.6f %% of total (%d); %d dropped]\n",indent," ",
                s->ts_tpdu_rcvd ,
                }
        }
        fprintf(OUT,
 "\n%*sTpdus RECVD [%d valid, %3.6f %% of total (%d); %d dropped]\n",indent," ",
                s->ts_tpdu_rcvd ,
-               ((s->ts_pkt_rcvd > 0) ? 
+               ((s->ts_pkt_rcvd > 0) ?
                        ((100 * (float)s->ts_tpdu_rcvd)/(float)s->ts_pkt_rcvd)
                        : 0),
                s->ts_pkt_rcvd,
                        ((100 * (float)s->ts_tpdu_rcvd)/(float)s->ts_pkt_rcvd)
                        : 0),
                s->ts_pkt_rcvd,
@@ -642,7 +736,7 @@ int indent;
        "\t%*sXPD %6d (%5.2f%%)\n",  indent, " ",
                s->ts_retrans_xpd,
                PERCENT(s->ts_retrans_xpd, s->ts_XPD_sent));
        "\t%*sXPD %6d (%5.2f%%)\n",  indent, " ",
                s->ts_retrans_xpd,
                PERCENT(s->ts_retrans_xpd, s->ts_XPD_sent));
-       
+
 
        fprintf(OUT,
                "\n%*sE Timers: [%6d ticks]\n", indent, " ", s->ts_Eticks);
 
        fprintf(OUT,
                "\n%*sE Timers: [%6d ticks]\n", indent, " ", s->ts_Eticks);
@@ -683,30 +777,31 @@ int indent;
        fprintf(OUT,
                "\n%*sACK reasons:\n", indent, " ");
        fprintf(OUT, "\t%*s%6d not acked immediately\n", indent, " ",
        fprintf(OUT,
                "\n%*sACK reasons:\n", indent, " ");
        fprintf(OUT, "\t%*s%6d not acked immediately\n", indent, " ",
-                                                                               s->ts_ackreason[_ACK_DONT_] );
+               s->ts_ackreason[_ACK_DONT_] );
        fprintf(OUT, "\t%*s%6d strategy==each\n", indent, " ",
        fprintf(OUT, "\t%*s%6d strategy==each\n", indent, " ",
-                                                                               s->ts_ackreason[_ACK_STRAT_EACH_] );
+               s->ts_ackreason[_ACK_STRAT_EACH_] );
        fprintf(OUT, "\t%*s%6d strategy==fullwindow\n", indent, " ",
        fprintf(OUT, "\t%*s%6d strategy==fullwindow\n", indent, " ",
-                                                                               s->ts_ackreason[_ACK_STRAT_FULLWIN_] );
+               s->ts_ackreason[_ACK_STRAT_FULLWIN_] );
        fprintf(OUT, "\t%*s%6d duplicate DT\n", indent, " ",
        fprintf(OUT, "\t%*s%6d duplicate DT\n", indent, " ",
-                                                                               s->ts_ackreason[_ACK_DUP_] );
+               s->ts_ackreason[_ACK_DUP_] );
        fprintf(OUT, "\t%*s%6d EOTSDU\n", indent, " ",
        fprintf(OUT, "\t%*s%6d EOTSDU\n", indent, " ",
-                                                                               s->ts_ackreason[_ACK_EOT_] );
+               s->ts_ackreason[_ACK_EOT_] );
        fprintf(OUT, "\t%*s%6d reordered DT\n", indent, " ",
        fprintf(OUT, "\t%*s%6d reordered DT\n", indent, " ",
-                                                                               s->ts_ackreason[_ACK_REORDER_] );
+               s->ts_ackreason[_ACK_REORDER_] );
        fprintf(OUT, "\t%*s%6d user rcvd\n", indent, " ",
        fprintf(OUT, "\t%*s%6d user rcvd\n", indent, " ",
-                                                                               s->ts_ackreason[_ACK_USRRCV_] );
-       fprintf(OUT, "\t%*s%6d fcc reqd\n",     indent, " ",
-                                                                               s->ts_ackreason[_ACK_FCC_] );
+               s->ts_ackreason[_ACK_USRRCV_] );
+       fprintf(OUT, "\t%*s%6d fcc reqd\n", indent, " ",
+               s->ts_ackreason[_ACK_FCC_] );
 }
 #ifndef SSEL
 #define SSEL(s) ((s)->siso_tlen + TSEL(s))
 #define PSEL(s) ((s)->siso_slen + SSEL(s))
 #endif
 
 }
 #ifndef SSEL
 #define SSEL(s) ((s)->siso_tlen + TSEL(s))
 #define PSEL(s) ((s)->siso_slen + SSEL(s))
 #endif
 
+static void
 isonetprint(siso, islocal)
 isonetprint(siso, islocal)
-register struct sockaddr_iso *siso;
-int islocal;
+       register struct sockaddr_iso *siso;
+       int islocal;
 {
        hexprint(siso->siso_nlen, siso->siso_addr.isoa_genaddr, "{}");
        if (siso->siso_tlen || siso->siso_slen || siso->siso_plen)
 {
        hexprint(siso->siso_nlen, siso->siso_addr.isoa_genaddr, "{}");
        if (siso->siso_tlen || siso->siso_slen || siso->siso_plen)
@@ -717,10 +812,13 @@ int islocal;
                hexprint(siso->siso_plen, PSEL(siso), "<>");
        putchar(' ');
 }
                hexprint(siso->siso_plen, PSEL(siso), "<>");
        putchar(' ');
 }
+
 static char hexlist[] = "0123456789abcdef", obuf[128];
 
 static char hexlist[] = "0123456789abcdef", obuf[128];
 
+static void
 hexprint(n, buf, delim)
 hexprint(n, buf, delim)
-char *buf, *delim;
+       int n;
+       char *buf, *delim;
 {
        register u_char *in = (u_char *)buf, *top = in + n;
        register char *out = obuf;
 {
        register u_char *in = (u_char *)buf, *top = in + n;
        register char *out = obuf;