rm unused/broken x25 hooks
[unix-history] / usr / src / usr.bin / netstat / if.c
index 1a82fa8..1c7b6c7 100644 (file)
@@ -2,21 +2,11 @@
  * 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.
  *
- * 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.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)if.c       5.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)if.c       5.15 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -28,6 +18,8 @@ static char sccsid[] = "@(#)if.c      5.11 (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>
@@ -35,13 +27,13 @@ static char sccsid[] = "@(#)if.c    5.11 (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.
@@ -55,6 +47,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;
@@ -68,8 +61,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");
@@ -84,14 +76,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 &&
@@ -109,8 +98,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;
@@ -154,26 +142,22 @@ intpr(interval, ifnetaddr)
                                {
                                struct sockaddr_dl *sdl =
                                        (struct sockaddr_dl *)sa;
                                {
                                struct sockaddr_dl *sdl =
                                        (struct sockaddr_dl *)sa;
-                               printf("<Link>      ");
-                               cp = (char *)LLADDR(sdl);
-                               n = sdl->sdl_alen;
-                               if (n > 0) goto hexprint;
-                               printf("%-15s ", "");
+                                   cp = (char *)LLADDR(sdl);
+                                   n = sdl->sdl_alen;
                                }
                                }
-                               break;
+                               m = printf("<Link>");
+                               goto hexprint;
                        default:
                        default:
-                               printf("af%2d: ", sa->sa_family);
-                               for (cp = sa->sa_data + sa->sa_len;
-                                                   cp >= sa->sa_data; --cp)
-                                       if (*cp != 0)
-                                               break;
+                               m = printf("(%d)", sa->sa_family);
+                               for (cp = sa->sa_len + (char *)sa;
+                                       --cp > sa->sa_data && (*cp == 0);) {}
                                n = cp - sa->sa_data + 1;
                                cp = sa->sa_data;
                        hexprint:
                                n = cp - sa->sa_data + 1;
                                cp = sa->sa_data;
                        hexprint:
-                               m = 12 - (3 * n);
-                               while (--n)
-                                       printf("%02x.", *cp++ & 0xff);
-                               printf("%02x ", *cp & 0xff);
+                               while (--n >= 0)
+                                       m += printf("%x%c", *cp++ & 0xff,
+                                                   n > 0 ? '.' : ' ');
+                               m = 28 - m;
                                while (m-- > 0)
                                        putchar(' ');
                                break;
                                while (m-- > 0)
                                        putchar(' ');
                                break;
@@ -221,10 +205,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;
@@ -232,11 +215,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;
@@ -289,8 +270,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,
@@ -347,6 +327,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;