BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / netstat / ns.c
index 7aa8902..8bdc89c 100644 (file)
@@ -2,28 +2,40 @@
  * Copyright (c) 1985, 1988 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1985, 1988 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, 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'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * 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
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ns.c       5.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)ns.c       5.13 (Berkeley) 3/1/91";
 #endif /* not lint */
 
 #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>
@@ -46,11 +58,14 @@ static char sccsid[] = "@(#)ns.c    5.9 (Berkeley) %G%";
 #define SANAMES
 #include <netns/spp_debug.h>
 
 #define SANAMES
 #include <netns/spp_debug.h>
 
+#include <nlist.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.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 int Aflag;
 extern int aflag;
 extern int nflag;
@@ -77,8 +92,7 @@ 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));
+       kvm_read(off, (char *)&cb, sizeof (struct nspcb));
        nspcb = cb;
        prev = (struct nspcb *)off;
        if (nspcb.nsp_next == (struct nspcb *)off)
        nspcb = cb;
        prev = (struct nspcb *)off;
        if (nspcb.nsp_next == (struct nspcb *)off)
@@ -87,8 +101,7 @@ nsprotopr(off, name)
                off_t ppcb;
 
                next = nspcb.nsp_next;
                off_t ppcb;
 
                next = nspcb.nsp_next;
-               klseek(kmem, (off_t)next, 0);
-               read(kmem, (char *)&nspcb, sizeof (nspcb));
+               kvm_read((off_t)next, (char *)&nspcb, sizeof (nspcb));
                if (nspcb.nsp_prev != prev) {
                        printf("???\n");
                        break;
                if (nspcb.nsp_prev != prev) {
                        printf("???\n");
                        break;
@@ -96,13 +109,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));
+               kvm_read((off_t)nspcb.nsp_socket,
+                               (char *)&sockb, sizeof (sockb));
                ppcb = (off_t) nspcb.nsp_pcb;
                if (ppcb) {
                        if (isspp) {
                ppcb = (off_t) nspcb.nsp_pcb;
                if (ppcb) {
                        if (isspp) {
-                               klseek(kmem, ppcb, 0);
-                               read(kmem, (char *)&sppcb, sizeof (sppcb));
+                               kvm_read(ppcb, (char *)&sppcb, sizeof (sppcb));
                        } else continue;
                } else
                        if (isspp) continue;
                        } else continue;
                } else
                        if (isspp) continue;
@@ -137,7 +149,8 @@ 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.
@@ -151,14 +164,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));
+       kvm_read(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");
@@ -225,8 +240,7 @@ idp_stats(off, name)
 
        if (off == 0)
                return;
 
        if (off == 0)
                return;
-       klseek(kmem, off, 0);
-       read(kmem, (char *)&idpstat, sizeof (idpstat));
+       kvm_read(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");
@@ -264,8 +278,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));
+       kvm_read(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",
@@ -295,12 +308,13 @@ nserr_stats(off, name)
                ns_erputil(z, ns_errstat.ns_es_codes[j]);
        }
 }
                ns_erputil(z, ns_errstat.ns_es_codes[j]);
        }
 }
-static
+
 ns_erputil(z, c)
 {
        int j;
        char codebuf[30];
        char *name, *where;
 ns_erputil(z, c)
 {
        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;
@@ -318,13 +332,15 @@ ns_erputil(z, c)
                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};
 
 char *ns_prpr(x)
 static struct sockaddr_ns ssns = {AF_NS};
 
 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;
+       extern char *ns_print();
+
        sns->sns_addr = *x;
        return(ns_print(sns));
 }
        sns->sns_addr = *x;
        return(ns_print(sns));
 }