BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / netstat / if.c
index 7e5616a..acfa528 100644 (file)
@@ -2,11 +2,37 @@
  * Copyright (c) 1983, 1988 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1983, 1988 Regents of the University of California.
  * All rights reserved.
  *
- * %sccs.include.redist.c%
+ * 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[] = "@(#)if.c       5.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)if.c       5.15 (Berkeley) 3/1/91";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -18,6 +44,8 @@ static char sccsid[] = "@(#)if.c      5.13 (Berkeley) %G%";
 #include <netinet/in_var.h>
 #include <netns/ns.h>
 #include <netns/ns_if.h>
 #include <netinet/in_var.h>
 #include <netns/ns.h>
 #include <netns/ns_if.h>
+#include <netiso/iso.h>
+#include <netiso/iso_var.h>
 
 #include <stdio.h>
 #include <signal.h>
 
 #include <stdio.h>
 #include <signal.h>
@@ -25,13 +53,13 @@ static char sccsid[] = "@(#)if.c    5.13 (Berkeley) %G%";
 #define        YES     1
 #define        NO      0
 
 #define        YES     1
 #define        NO      0
 
-extern int kmem;
 extern int tflag;
 extern int dflag;
 extern int nflag;
 extern char *interface;
 extern int unit;
 extern char *routename(), *netname(), *ns_phost();
 extern int tflag;
 extern int dflag;
 extern int nflag;
 extern char *interface;
 extern int unit;
 extern char *routename(), *netname(), *ns_phost();
+char *index();
 
 /*
  * Print a description of the network interfaces.
 
 /*
  * Print a description of the network interfaces.
@@ -45,6 +73,7 @@ intpr(interval, ifnetaddr)
                struct ifaddr ifa;
                struct in_ifaddr in;
                struct ns_ifaddr ns;
                struct ifaddr ifa;
                struct in_ifaddr in;
                struct ns_ifaddr ns;
+               struct iso_ifaddr iso;
        } ifaddr;
        off_t ifaddraddr;
        struct sockaddr *sa;
        } ifaddr;
        off_t ifaddraddr;
        struct sockaddr *sa;
@@ -58,8 +87,7 @@ intpr(interval, ifnetaddr)
                sidewaysintpr((unsigned)interval, ifnetaddr);
                return;
        }
                sidewaysintpr((unsigned)interval, ifnetaddr);
                return;
        }
-       klseek(kmem, ifnetaddr, 0);
-       read(kmem, (char *)&ifnetaddr, sizeof ifnetaddr);
+       kvm_read(ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr);
        printf("%-5.5s %-5.5s %-11.11s %-15.15s %8.8s %5.5s %8.8s %5.5s",
                "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
                "Opkts", "Oerrs");
        printf("%-5.5s %-5.5s %-11.11s %-15.15s %8.8s %5.5s %8.8s %5.5s",
                "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
                "Opkts", "Oerrs");
@@ -74,14 +102,11 @@ intpr(interval, ifnetaddr)
                struct sockaddr_in *sin;
                register char *cp;
                int n, m;
                struct sockaddr_in *sin;
                register char *cp;
                int n, m;
-               char *index();
                struct in_addr inet_makeaddr();
 
                if (ifaddraddr == 0) {
                struct in_addr inet_makeaddr();
 
                if (ifaddraddr == 0) {
-                       klseek(kmem, ifnetaddr, 0);
-                       read(kmem, (char *)&ifnet, sizeof ifnet);
-                       klseek(kmem, (off_t)ifnet.if_name, 0);
-                       read(kmem, name, 16);
+                       kvm_read(ifnetaddr, (char *)&ifnet, sizeof ifnet);
+                       kvm_read((off_t)ifnet.if_name, name, 16);
                        name[15] = '\0';
                        ifnetaddr = (off_t) ifnet.if_next;
                        if (interface != 0 &&
                        name[15] = '\0';
                        ifnetaddr = (off_t) ifnet.if_next;
                        if (interface != 0 &&
@@ -99,8 +124,7 @@ intpr(interval, ifnetaddr)
                        printf("%-11.11s ", "none");
                        printf("%-15.15s ", "none");
                } else {
                        printf("%-11.11s ", "none");
                        printf("%-15.15s ", "none");
                } else {
-                       klseek(kmem, ifaddraddr, 0);
-                       read(kmem, (char *)&ifaddr, sizeof ifaddr);
+                       kvm_read(ifaddraddr, (char *)&ifaddr, sizeof ifaddr);
 #define CP(x) ((char *)(x))
                        cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
                                CP(&ifaddr); sa = (struct sockaddr *)cp;
 #define CP(x) ((char *)(x))
                        cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
                                CP(&ifaddr); sa = (struct sockaddr *)cp;
@@ -207,10 +231,9 @@ sidewaysintpr(interval, off)
        register int line;
        struct iftot *lastif, *sum, *interesting;
        int oldmask;
        register int line;
        struct iftot *lastif, *sum, *interesting;
        int oldmask;
-       int catchalarm();
+       void catchalarm();
 
 
-       klseek(kmem, off, 0);
-       read(kmem, (char *)&firstifnet, sizeof (off_t));
+       kvm_read(off, (char *)&firstifnet, sizeof (off_t));
        lastif = iftot;
        sum = iftot + MAXIF - 1;
        total = sum - 1;
        lastif = iftot;
        sum = iftot + MAXIF - 1;
        total = sum - 1;
@@ -218,11 +241,9 @@ sidewaysintpr(interval, off)
        for (off = firstifnet, ip = iftot; off;) {
                char *cp;
 
        for (off = firstifnet, ip = iftot; off;) {
                char *cp;
 
-               klseek(kmem, off, 0);
-               read(kmem, (char *)&ifnet, sizeof ifnet);
-               klseek(kmem, (off_t)ifnet.if_name, 0);
+               kvm_read(off, (char *)&ifnet, sizeof ifnet);
                ip->ift_name[0] = '(';
                ip->ift_name[0] = '(';
-               read(kmem, ip->ift_name + 1, 15);
+               kvm_read((off_t)ifnet.if_name, ip->ift_name + 1, 15);
                if (interface && strcmp(ip->ift_name + 1, interface) == 0 &&
                    unit == ifnet.if_unit)
                        interesting = ip;
                if (interface && strcmp(ip->ift_name + 1, interface) == 0 &&
                    unit == ifnet.if_unit)
                        interesting = ip;
@@ -275,8 +296,7 @@ loop:
        sum->ift_co = 0;
        sum->ift_dr = 0;
        for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
        sum->ift_co = 0;
        sum->ift_dr = 0;
        for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
-               klseek(kmem, off, 0);
-               read(kmem, (char *)&ifnet, sizeof ifnet);
+               kvm_read(off, (char *)&ifnet, sizeof ifnet);
                if (ip == interesting) {
                        printf("%8d %5d %8d %5d %5d",
                                ifnet.if_ipackets - ip->ift_ip,
                if (ip == interesting) {
                        printf("%8d %5d %8d %5d %5d",
                                ifnet.if_ipackets - ip->ift_ip,
@@ -333,6 +353,7 @@ loop:
  * Called if an interval expires before sidewaysintpr has completed a loop.
  * Sets a flag to not wait for the alarm.
  */
  * Called if an interval expires before sidewaysintpr has completed a loop.
  * Sets a flag to not wait for the alarm.
  */
+void
 catchalarm()
 {
        signalled = YES;
 catchalarm()
 {
        signalled = YES;