Release 6
[unix-history] / usr / src / usr.bin / netstat / ns.c
index 383db7e..1883535 100644 (file)
@@ -1,24 +1,15 @@
 /*
 /*
- * Copyright (c) 1985,1988 Regents of the University of California.
+ * Copyright (c) 1983, 1988 Regents of the University of California.
  * All rights reserved.
  *
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that this notice is preserved and that due credit is given
- * to the University of California at Berkeley. The name of the University
- * may not be used to endorse or promote products derived from this
- * software without specific prior written permission. This software
- * is provided ``as is'' without express or implied warranty.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ns.c       5.7 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)ns.c       5.16 (Berkeley) %G%";
+#endif /* not lint */
 
 
-#include <stdio.h>
-#include <errno.h>
-#include <nlist.h>
-
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <sys/mbuf.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <sys/mbuf.h>
@@ -28,7 +19,6 @@ static char sccsid[] = "@(#)ns.c      5.7 (Berkeley) %G%";
 #include <net/if.h>
 
 #include <netinet/tcp_fsm.h>
 #include <net/if.h>
 
 #include <netinet/tcp_fsm.h>
-#include <netinet/tcp_timer.h>
 
 #include <netns/ns.h>
 #include <netns/ns_pcb.h>
 
 #include <netns/ns.h>
 #include <netns/ns_pcb.h>
@@ -37,20 +27,23 @@ static char sccsid[] = "@(#)ns.c    5.7 (Berkeley) %G%";
 #include <netns/ns_error.h>
 #include <netns/sp.h>
 #include <netns/spidp.h>
 #include <netns/ns_error.h>
 #include <netns/sp.h>
 #include <netns/spidp.h>
+#include <netns/spp_timer.h>
 #include <netns/spp_var.h>
 #define SANAMES
 #include <netns/spp_debug.h>
 
 #include <netns/spp_var.h>
 #define SANAMES
 #include <netns/spp_debug.h>
 
+#include <nlist.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include "netstat.h"
 
 struct nspcb nspcb;
 struct sppcb sppcb;
 struct socket sockb;
 
 struct nspcb nspcb;
 struct sppcb sppcb;
 struct socket sockb;
-extern int kmem;
-extern int Aflag;
-extern int aflag;
-extern int nflag;
-extern char *plural();
-char *ns_prpr();
+
+static char *ns_prpr __P((struct ns_addr *));
+static void ns_erputil __P((int, int));
 
 static int first = 1;
 
 
 static int first = 1;
 
@@ -61,8 +54,9 @@ static        int first = 1;
  * -a (all) flag is specified.
  */
 
  * -a (all) flag is specified.
  */
 
+void
 nsprotopr(off, name)
 nsprotopr(off, name)
-       off_t off;
+       u_long off;
        char *name;
 {
        struct nspcb cb;
        char *name;
 {
        struct nspcb cb;
@@ -72,18 +66,16 @@ nsprotopr(off, name)
        if (off == 0)
                return;
        isspp = strcmp(name, "spp") == 0;
        if (off == 0)
                return;
        isspp = strcmp(name, "spp") == 0;
-       klseek(kmem, off, 0);
-       read(kmem, (char *)&cb, sizeof (struct nspcb));
+       kread(off, (char *)&cb, sizeof (struct nspcb));
        nspcb = cb;
        prev = (struct nspcb *)off;
        if (nspcb.nsp_next == (struct nspcb *)off)
                return;
        for (;nspcb.nsp_next != (struct nspcb *)off; prev = next) {
        nspcb = cb;
        prev = (struct nspcb *)off;
        if (nspcb.nsp_next == (struct nspcb *)off)
                return;
        for (;nspcb.nsp_next != (struct nspcb *)off; prev = next) {
-               off_t ppcb;
+               u_long ppcb;
 
                next = nspcb.nsp_next;
 
                next = nspcb.nsp_next;
-               klseek(kmem, (off_t)next, 0);
-               read(kmem, (char *)&nspcb, sizeof (nspcb));
+               kread((u_long)next, (char *)&nspcb, sizeof (nspcb));
                if (nspcb.nsp_prev != prev) {
                        printf("???\n");
                        break;
                if (nspcb.nsp_prev != prev) {
                        printf("???\n");
                        break;
@@ -91,13 +83,12 @@ nsprotopr(off, name)
                if (!aflag && ns_nullhost(nspcb.nsp_faddr) ) {
                        continue;
                }
                if (!aflag && ns_nullhost(nspcb.nsp_faddr) ) {
                        continue;
                }
-               klseek(kmem, (off_t)nspcb.nsp_socket, 0);
-               read(kmem, (char *)&sockb, sizeof (sockb));
-               ppcb = (off_t) nspcb.nsp_pcb;
+               kread((u_long)nspcb.nsp_socket,
+                               (char *)&sockb, sizeof (sockb));
+               ppcb = (u_long) nspcb.nsp_pcb;
                if (ppcb) {
                        if (isspp) {
                if (ppcb) {
                        if (isspp) {
-                               klseek(kmem, ppcb, 0);
-                               read(kmem, (char *)&sppcb, sizeof (sppcb));
+                               kread(ppcb, (char *)&sppcb, sizeof (sppcb));
                        } else continue;
                } else
                        if (isspp) continue;
                        } else continue;
                } else
                        if (isspp) continue;
@@ -132,13 +123,15 @@ nsprotopr(off, name)
                prev = next;
        }
 }
                prev = next;
        }
 }
-#define ANY(x,y,z)  ((x) ? printf("\t%d %s%s%s -- %s\n",x,y,plural(x),z,"x") : 0)
+#define ANY(x,y,z) \
+       ((x) ? printf("\t%d %s%s%s -- %s\n",x,y,plural(x),z,"x") : 0)
 
 /*
  * Dump SPP statistics structure.
  */
 
 /*
  * Dump SPP statistics structure.
  */
+void
 spp_stats(off, name)
 spp_stats(off, name)
-       off_t off;
+       u_long off;
        char *name;
 {
        struct spp_istat spp_istat;
        char *name;
 {
        struct spp_istat spp_istat;
@@ -146,14 +139,16 @@ spp_stats(off, name)
 
        if (off == 0)
                return;
 
        if (off == 0)
                return;
-       klseek(kmem, off, 0);
-       read(kmem, (char *)&spp_istat, sizeof (spp_istat));
+       kread(off, (char *)&spp_istat, sizeof (spp_istat));
        printf("%s:\n", name);
        ANY(spp_istat.nonucn, "connection", " dropped due to no new sockets ");
        ANY(spp_istat.gonawy, "connection", " terminated due to our end dying");
        printf("%s:\n", name);
        ANY(spp_istat.nonucn, "connection", " dropped due to no new sockets ");
        ANY(spp_istat.gonawy, "connection", " terminated due to our end dying");
-       ANY(spp_istat.nonucn, "connection", " dropped due to inability to connect");
-       ANY(spp_istat.noconn, "connection", " dropped due to inability to connect");
-       ANY(spp_istat.notme, "connection", " incompleted due to mismatched id's");
+       ANY(spp_istat.nonucn, "connection",
+           " dropped due to inability to connect");
+       ANY(spp_istat.noconn, "connection",
+           " dropped due to inability to connect");
+       ANY(spp_istat.notme, "connection",
+           " incompleted due to mismatched id's");
        ANY(spp_istat.wrncon, "connection", " dropped due to mismatched id's");
        ANY(spp_istat.bdreas, "packet", " dropped out of sequence");
        ANY(spp_istat.lstdup, "packet", " duplicating the highest packet");
        ANY(spp_istat.wrncon, "connection", " dropped due to mismatched id's");
        ANY(spp_istat.bdreas, "packet", " dropped out of sequence");
        ANY(spp_istat.lstdup, "packet", " duplicating the highest packet");
@@ -212,16 +207,16 @@ spp_stats(off, name)
 /*
  * Dump IDP statistics structure.
  */
 /*
  * Dump IDP statistics structure.
  */
+void
 idp_stats(off, name)
 idp_stats(off, name)
-       off_t off;
+       u_long off;
        char *name;
 {
        struct idpstat idpstat;
 
        if (off == 0)
                return;
        char *name;
 {
        struct idpstat idpstat;
 
        if (off == 0)
                return;
-       klseek(kmem, off, 0);
-       read(kmem, (char *)&idpstat, sizeof (idpstat));
+       kread(off, (char *)&idpstat, sizeof (idpstat));
        printf("%s:\n", name);
        ANY(idpstat.idps_toosmall, "packet", " smaller than a header");
        ANY(idpstat.idps_tooshort, "packet", " smaller than advertised");
        printf("%s:\n", name);
        ANY(idpstat.idps_toosmall, "packet", " smaller than a header");
        ANY(idpstat.idps_tooshort, "packet", " smaller than advertised");
@@ -248,8 +243,9 @@ static      struct {
  * Dump NS Error statistics structure.
  */
 /*ARGSUSED*/
  * Dump NS Error statistics structure.
  */
 /*ARGSUSED*/
+void
 nserr_stats(off, name)
 nserr_stats(off, name)
-       off_t off;
+       u_long off;
        char *name;
 {
        struct ns_errstat ns_errstat;
        char *name;
 {
        struct ns_errstat ns_errstat;
@@ -259,8 +255,7 @@ nserr_stats(off, name)
 
        if (off == 0)
                return;
 
        if (off == 0)
                return;
-       klseek(kmem, off, 0);
-       read(kmem, (char *)&ns_errstat, sizeof (ns_errstat));
+       kread(off, (char *)&ns_errstat, sizeof (ns_errstat));
        printf("NS error statistics:\n");
        ANY(ns_errstat.ns_es_error, "call", " to ns_error");
        ANY(ns_errstat.ns_es_oldshort, "error",
        printf("NS error statistics:\n");
        ANY(ns_errstat.ns_es_error, "call", " to ns_error");
        ANY(ns_errstat.ns_es_oldshort, "error",
@@ -290,12 +285,15 @@ nserr_stats(off, name)
                ns_erputil(z, ns_errstat.ns_es_codes[j]);
        }
 }
                ns_erputil(z, ns_errstat.ns_es_codes[j]);
        }
 }
-static
+
+static void
 ns_erputil(z, c)
 ns_erputil(z, c)
+       int z, c;
 {
        int j;
        char codebuf[30];
        char *name, *where;
 {
        int j;
        char codebuf[30];
        char *name, *where;
+
        for(j = 0;; j ++) {
                if ((name = ns_errnames[j].name) == 0)
                        break;
        for(j = 0;; j ++) {
                if ((name = ns_errnames[j].name) == 0)
                        break;
@@ -309,17 +307,19 @@ ns_erputil(z, c)
                        where = "at destination";
                sprintf(codebuf, "Unknown XNS error code 0%o", c);
                name = codebuf;
                        where = "at destination";
                sprintf(codebuf, "Unknown XNS error code 0%o", c);
                name = codebuf;
-       } else 
+       } else
                where =  ns_errnames[j].where;
        ANY(z, name, where);
 }
                where =  ns_errnames[j].where;
        ANY(z, name, where);
 }
+
 static struct sockaddr_ns ssns = {AF_NS};
 
 static struct sockaddr_ns ssns = {AF_NS};
 
+static
 char *ns_prpr(x)
 char *ns_prpr(x)
-struct ns_addr *x;
+       struct ns_addr *x;
 {
 {
-       extern char *ns_print();
        struct sockaddr_ns *sns = &ssns;
        struct sockaddr_ns *sns = &ssns;
+
        sns->sns_addr = *x;
        sns->sns_addr = *x;
-       return(ns_print(sns));
+       return(ns_print((struct sockaddr *)sns));
 }
 }