incorporate changes for new kvm interfaces from lbl
authorKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Thu, 28 May 1992 09:11:59 +0000 (01:11 -0800)
committerKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Thu, 28 May 1992 09:11:59 +0000 (01:11 -0800)
SCCS-vsn: usr.bin/netstat/ns.c 5.14
SCCS-vsn: usr.bin/netstat/main.c 5.28
SCCS-vsn: usr.bin/netstat/if.c 5.16
SCCS-vsn: usr.bin/netstat/iso.c 5.11
SCCS-vsn: usr.bin/netstat/route.c 5.23
SCCS-vsn: usr.bin/netstat/inet.c 5.16
SCCS-vsn: usr.bin/netstat/unix.c 5.12
SCCS-vsn: usr.bin/netstat/Makefile 5.15
SCCS-vsn: usr.bin/netstat/mbuf.c 5.11
SCCS-vsn: usr.bin/netstat/netstat.h 5.2

usr/src/usr.bin/netstat/Makefile
usr/src/usr.bin/netstat/if.c
usr/src/usr.bin/netstat/inet.c
usr/src/usr.bin/netstat/iso.c
usr/src/usr.bin/netstat/main.c
usr/src/usr.bin/netstat/mbuf.c
usr/src/usr.bin/netstat/netstat.h
usr/src/usr.bin/netstat/ns.c
usr/src/usr.bin/netstat/route.c
usr/src/usr.bin/netstat/unix.c

index f21eac9..4e2eca5 100644 (file)
@@ -1,4 +1,4 @@
-#      @(#)Makefile    5.14 (Berkeley) %G%
+#      @(#)Makefile    5.15 (Berkeley) %G%
 
 PROG=  netstat
 OBJS=  host.o inet.o if.o main.o mbuf.o route.o unix.o ns.o bbnnet.o
 
 PROG=  netstat
 OBJS=  host.o inet.o if.o main.o mbuf.o route.o unix.o ns.o bbnnet.o
index 1c7b6c7..0827685 100644 (file)
@@ -6,12 +6,12 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)if.c       5.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)if.c       5.16 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
+#include <sys/protosw.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
-
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <netinet/in.h>
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <netinet/in.h>
@@ -21,23 +21,22 @@ static char sccsid[] = "@(#)if.c    5.15 (Berkeley) %G%";
 #include <netiso/iso.h>
 #include <netiso/iso_var.h>
 
 #include <netiso/iso.h>
 #include <netiso/iso_var.h>
 
+#include <arpa/inet.h>
 #include <stdio.h>
 #include <stdio.h>
+#include <string.h>
 #include <signal.h>
 #include <signal.h>
+#include "netstat.h"
 
 #define        YES     1
 #define        NO      0
 
 
 #define        YES     1
 #define        NO      0
 
-extern int tflag;
-extern int dflag;
-extern int nflag;
-extern char *interface;
-extern int unit;
-extern char *routename(), *netname(), *ns_phost();
-char *index();
+static void sidewaysintpr __P((unsigned, off_t));
+static void catchalarm __P(());
 
 /*
  * Print a description of the network interfaces.
  */
 
 /*
  * Print a description of the network interfaces.
  */
+void
 intpr(interval, ifnetaddr)
        int interval;
        off_t ifnetaddr;
 intpr(interval, ifnetaddr)
        int interval;
        off_t ifnetaddr;
@@ -61,7 +60,8 @@ intpr(interval, ifnetaddr)
                sidewaysintpr((unsigned)interval, ifnetaddr);
                return;
        }
                sidewaysintpr((unsigned)interval, ifnetaddr);
                return;
        }
-       kvm_read(ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr);
+       if (kread(ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr))
+               return;
        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");
@@ -76,11 +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;
-               struct in_addr inet_makeaddr();
 
                if (ifaddraddr == 0) {
 
                if (ifaddraddr == 0) {
-                       kvm_read(ifnetaddr, (char *)&ifnet, sizeof ifnet);
-                       kvm_read((off_t)ifnet.if_name, name, 16);
+                       if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) ||
+                           kread((off_t)ifnet.if_name, name, 16))
+                               return;
                        name[15] = '\0';
                        ifnetaddr = (off_t) ifnet.if_next;
                        if (interface != 0 &&
                        name[15] = '\0';
                        ifnetaddr = (off_t) ifnet.if_next;
                        if (interface != 0 &&
@@ -98,7 +98,10 @@ intpr(interval, ifnetaddr)
                        printf("%-11.11s ", "none");
                        printf("%-15.15s ", "none");
                } else {
                        printf("%-11.11s ", "none");
                        printf("%-15.15s ", "none");
                } else {
-                       kvm_read(ifaddraddr, (char *)&ifaddr, sizeof ifaddr);
+                       if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) {
+                               ifaddraddr = 0;
+                               continue;
+                       }
 #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;
@@ -115,13 +118,15 @@ intpr(interval, ifnetaddr)
                                 */
                                in = inet_makeaddr(ifaddr.in.ia_subnet,
                                        INADDR_ANY);
                                 */
                                in = inet_makeaddr(ifaddr.in.ia_subnet,
                                        INADDR_ANY);
-                               printf("%-11.11s ", netname(in));
+                               printf("%-11.11s ", netname(in.s_addr,
+                                   ifaddr.in.ia_subnetmask));
 #else
                                printf("%-11.11s ",
 #else
                                printf("%-11.11s ",
-                                       netname(htonl(ifaddr.in.ia_subnet),
-                                               ifaddr.in.ia_subnetmask));
+                                   netname(htonl(ifaddr.in.ia_subnet),
+                                   ifaddr.in.ia_subnetmask));
 #endif
 #endif
-                               printf("%-15.15s ", routename(sin->sin_addr));
+                               printf("%-15.15s ",
+                                   routename(sin->sin_addr.s_addr));
                                break;
                        case AF_NS:
                                {
                                break;
                        case AF_NS:
                                {
@@ -129,13 +134,13 @@ intpr(interval, ifnetaddr)
                                        (struct sockaddr_ns *)sa;
                                u_long net;
                                char netnum[8];
                                        (struct sockaddr_ns *)sa;
                                u_long net;
                                char netnum[8];
-                               char *ns_phost();
 
                                *(union ns_net *) &net = sns->sns_addr.x_net;
                sprintf(netnum, "%lxH", ntohl(net));
                                upHex(netnum);
                                printf("ns:%-8s ", netnum);
 
                                *(union ns_net *) &net = sns->sns_addr.x_net;
                sprintf(netnum, "%lxH", ntohl(net));
                                upHex(netnum);
                                printf("ns:%-8s ", netnum);
-                               printf("%-15s ", ns_phost(sns));
+                               printf("%-15s ",
+                                   ns_phost((struct sockaddr *)sns));
                                }
                                break;
                        case AF_LINK:
                                }
                                break;
                        case AF_LINK:
@@ -195,6 +200,7 @@ u_char      signalled;                      /* set if alarm goes off "early" */
  * collected over that interval.  Assumes that interval is non-zero.
  * First line printed at top of screen is always cumulative.
  */
  * collected over that interval.  Assumes that interval is non-zero.
  * First line printed at top of screen is always cumulative.
  */
+static void
 sidewaysintpr(interval, off)
        unsigned interval;
        off_t off;
 sidewaysintpr(interval, off)
        unsigned interval;
        off_t off;
@@ -205,9 +211,9 @@ sidewaysintpr(interval, off)
        register int line;
        struct iftot *lastif, *sum, *interesting;
        int oldmask;
        register int line;
        struct iftot *lastif, *sum, *interesting;
        int oldmask;
-       void catchalarm();
 
 
-       kvm_read(off, (char *)&firstifnet, sizeof (off_t));
+       if (kread(off, (char *)&firstifnet, sizeof (off_t)))
+               return;
        lastif = iftot;
        sum = iftot + MAXIF - 1;
        total = sum - 1;
        lastif = iftot;
        sum = iftot + MAXIF - 1;
        total = sum - 1;
@@ -215,9 +221,11 @@ sidewaysintpr(interval, off)
        for (off = firstifnet, ip = iftot; off;) {
                char *cp;
 
        for (off = firstifnet, ip = iftot; off;) {
                char *cp;
 
-               kvm_read(off, (char *)&ifnet, sizeof ifnet);
+               if (kread(off, (char *)&ifnet, sizeof ifnet))
+                       break;
                ip->ift_name[0] = '(';
                ip->ift_name[0] = '(';
-               kvm_read((off_t)ifnet.if_name, ip->ift_name + 1, 15);
+               if (kread((off_t)ifnet.if_name, ip->ift_name + 1, 15))
+                       break;
                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;
@@ -270,7 +278,10 @@ 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++) {
-               kvm_read(off, (char *)&ifnet, sizeof ifnet);
+               if (kread(off, (char *)&ifnet, sizeof ifnet)) {
+                       off = 0;
+                       continue;
+               }
                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,
@@ -327,7 +338,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
+static void
 catchalarm()
 {
        signalled = YES;
 catchalarm()
 {
        signalled = YES;
index c71fb75..12490ca 100644 (file)
@@ -1,4 +1,4 @@
-/*
+    /*
  * 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.
  *
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)inet.c     5.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)inet.c     5.16 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -34,20 +34,18 @@ static char sccsid[] = "@(#)inet.c  5.15 (Berkeley) %G%";
 #include <netinet/udp.h>
 #include <netinet/udp_var.h>
 
 #include <netinet/udp.h>
 #include <netinet/udp_var.h>
 
+#include <arpa/inet.h>
 #include <netdb.h>
 #include <netdb.h>
-
 #include <stdio.h>
 #include <string.h>
 #include <stdio.h>
 #include <string.h>
+#include "netstat.h"
 
 struct inpcb inpcb;
 struct tcpcb tcpcb;
 struct socket sockb;
 
 struct inpcb inpcb;
 struct tcpcb tcpcb;
 struct socket sockb;
-extern int Aflag;
-extern int aflag;
-extern int nflag;
-extern char *plural();
 
 
-char   *inetname();
+static char *inetname __P((struct in_addr *));
+static void inetprint __P((struct in_addr *, int, char *));
 
 /*
  * Print a summary of connections related to an Internet
 
 /*
  * Print a summary of connections related to an Internet
@@ -55,6 +53,7 @@ char  *inetname();
  * 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
 protopr(off, name)
        off_t off;
        char *name;
 protopr(off, name)
        off_t off;
        char *name;
@@ -67,15 +66,14 @@ protopr(off, name)
        if (off == 0)
                return;
        istcp = strcmp(name, "tcp") == 0;
        if (off == 0)
                return;
        istcp = strcmp(name, "tcp") == 0;
-       kvm_read(off, (char *)&cb, sizeof (struct inpcb));
+       kread(off, (char *)&cb, sizeof (struct inpcb));
        inpcb = cb;
        prev = (struct inpcb *)off;
        if (inpcb.inp_next == (struct inpcb *)off)
                return;
        while (inpcb.inp_next != (struct inpcb *)off) {
        inpcb = cb;
        prev = (struct inpcb *)off;
        if (inpcb.inp_next == (struct inpcb *)off)
                return;
        while (inpcb.inp_next != (struct inpcb *)off) {
-
                next = inpcb.inp_next;
                next = inpcb.inp_next;
-               kvm_read((off_t)next, (char *)&inpcb, sizeof (inpcb));
+               kread((off_t)next, (char *)&inpcb, sizeof (inpcb));
                if (inpcb.inp_prev != prev) {
                        printf("???\n");
                        break;
                if (inpcb.inp_prev != prev) {
                        printf("???\n");
                        break;
@@ -85,11 +83,10 @@ protopr(off, name)
                        prev = next;
                        continue;
                }
                        prev = next;
                        continue;
                }
-               kvm_read((off_t)inpcb.inp_socket,
-                               (char *)&sockb, sizeof (sockb));
+               kread((off_t)inpcb.inp_socket, (char *)&sockb, sizeof (sockb));
                if (istcp) {
                if (istcp) {
-                       kvm_read((off_t)inpcb.inp_ppcb,
-                               (char *)&tcpcb, sizeof (tcpcb));
+                       kread((off_t)inpcb.inp_ppcb,
+                           (char *)&tcpcb, sizeof (tcpcb));
                }
                if (first) {
                        printf("Active Internet connections");
                }
                if (first) {
                        printf("Active Internet connections");
@@ -112,8 +109,8 @@ protopr(off, name)
                                printf("%8x ", next);
                printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
                        sockb.so_snd.sb_cc);
                                printf("%8x ", next);
                printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
                        sockb.so_snd.sb_cc);
-               inetprint(&inpcb.inp_laddr, inpcb.inp_lport, name);
-               inetprint(&inpcb.inp_faddr, inpcb.inp_fport, name);
+               inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport, name);
+               inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport, name);
                if (istcp) {
                        if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
                                printf(" %d", tcpcb.t_state);
                if (istcp) {
                        if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
                                printf(" %d", tcpcb.t_state);
@@ -128,6 +125,7 @@ protopr(off, name)
 /*
  * Dump TCP statistics structure.
  */
 /*
  * Dump TCP statistics structure.
  */
+void
 tcp_stats(off, name)
        off_t off;
        char *name;
 tcp_stats(off, name)
        off_t off;
        char *name;
@@ -137,11 +135,13 @@ tcp_stats(off, name)
        if (off == 0)
                return;
        printf ("%s:\n", name);
        if (off == 0)
                return;
        printf ("%s:\n", name);
-       kvm_read(off, (char *)&tcpstat, sizeof (tcpstat));
+       kread(off, (char *)&tcpstat, sizeof (tcpstat));
+
+#define        p(f, m) if (tcpstat.f || sflag <= 1) \
+    printf(m, tcpstat.f, plural(tcpstat.f))
+#define        p2(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \
+    printf(m, tcpstat.f1, plural(tcpstat.f1), tcpstat.f2, plural(tcpstat.f2))
 
 
-#define        p(f, m)         printf(m, tcpstat.f, plural(tcpstat.f))
-#define        p2(f1, f2, m)   printf(m, tcpstat.f1, plural(tcpstat.f1), tcpstat.f2, plural(tcpstat.f2))
-  
        p(tcps_sndtotal, "\t%d packet%s sent\n");
        p2(tcps_sndpack,tcps_sndbyte,
                "\t\t%d data packet%s (%d byte%s)\n");
        p(tcps_sndtotal, "\t%d packet%s sent\n");
        p2(tcps_sndpack,tcps_sndbyte,
                "\t\t%d data packet%s (%d byte%s)\n");
@@ -194,6 +194,7 @@ tcp_stats(off, name)
 /*
  * Dump UDP statistics structure.
  */
 /*
  * Dump UDP statistics structure.
  */
+void
 udp_stats(off, name)
        off_t off;
        char *name;
 udp_stats(off, name)
        off_t off;
        char *name;
@@ -202,13 +203,16 @@ udp_stats(off, name)
 
        if (off == 0)
                return;
 
        if (off == 0)
                return;
-       kvm_read(off, (char *)&udpstat, sizeof (udpstat));
-       printf("%s:\n\t%u incomplete header%s\n", name,
-               udpstat.udps_hdrops, plural(udpstat.udps_hdrops));
-       printf("\t%u bad data length field%s\n",
-               udpstat.udps_badlen, plural(udpstat.udps_badlen));
-       printf("\t%u bad checksum%s\n",
-               udpstat.udps_badsum, plural(udpstat.udps_badsum));
+       kread(off, (char *)&udpstat, sizeof (udpstat));
+       printf("%s:\n", name);
+#define        p(f, m) if (udpstat.f || sflag <= 1) \
+    printf(m, udpstat.f, plural(udpstat.f))
+       p(udps_hdrops, "\t%u incomplete header%s\n");
+       p(udps_badlen, "\t%u bad data length field%s\n");
+       p(udps_badsum, "\t%u bad checksum%s\n");
+       p(udps_noport, "\t%u no port%s\n");
+       p(udps_noportbcast, "\t%u (arrived as bcast) no port%s\n");
+#undef p
 #ifdef sun
        printf("\t%d socket overflow%s\n",
                udpstat.udps_fullsock, plural(udpstat.udps_fullsock));
 #ifdef sun
        printf("\t%d socket overflow%s\n",
                udpstat.udps_fullsock, plural(udpstat.udps_fullsock));
@@ -218,6 +222,7 @@ udp_stats(off, name)
 /*
  * Dump IP statistics structure.
  */
 /*
  * Dump IP statistics structure.
  */
+void
 ip_stats(off, name)
        off_t off;
        char *name;
 ip_stats(off, name)
        off_t off;
        char *name;
@@ -226,30 +231,25 @@ ip_stats(off, name)
 
        if (off == 0)
                return;
 
        if (off == 0)
                return;
-       kvm_read(off, (char *)&ipstat, sizeof (ipstat));
-#if BSD>=43
-       printf("%s:\n\t%u total packets received\n", name,
-               ipstat.ips_total);
-#endif
-       printf("\t%u bad header checksum%s\n",
-               ipstat.ips_badsum, plural(ipstat.ips_badsum));
-       printf("\t%u with size smaller than minimum\n", ipstat.ips_tooshort);
-       printf("\t%u with data size < data length\n", ipstat.ips_toosmall);
-       printf("\t%u with header length < data size\n", ipstat.ips_badhlen);
-       printf("\t%u with data length < header length\n", ipstat.ips_badlen);
-#if BSD>=43
-       printf("\t%u fragment%s received\n",
-               ipstat.ips_fragments, plural(ipstat.ips_fragments));
-       printf("\t%u fragment%s dropped (dup or out of space)\n",
-               ipstat.ips_fragdropped, plural(ipstat.ips_fragdropped));
-       printf("\t%u fragment%s dropped after timeout\n",
-               ipstat.ips_fragtimeout, plural(ipstat.ips_fragtimeout));
-       printf("\t%u packet%s forwarded\n",
-               ipstat.ips_forward, plural(ipstat.ips_forward));
-       printf("\t%u packet%s not forwardable\n",
-               ipstat.ips_cantforward, plural(ipstat.ips_cantforward));
-       printf("\t%u redirect%s sent\n",
-               ipstat.ips_redirectsent, plural(ipstat.ips_redirectsent));
+       kread(off, (char *)&ipstat, sizeof (ipstat));
+       printf("%s:\n", name);
+
+#define        p(f, m) if (ipstat.f || sflag <= 1) \
+    printf(m, ipstat.f, plural(ipstat.f))
+
+       p(ips_total, "\t%u total packet%s received\n");
+       p(ips_badsum, "\t%u bad header checksum%s\n");
+       p(ips_tooshort, "\t%u with size smaller than minimum\n");
+       p(ips_toosmall, "\t%u with data size < data length\n");
+       p(ips_badhlen, "\t%u with header length < data size\n");
+       p(ips_badlen, "\t%u with data length < header length\n");
+       p(ips_fragments, "\t%u fragment%s received\n");
+       p(ips_fragdropped, "\t%u fragment%s dropped (dup or out of space)\n");
+       p(ips_fragtimeout, "\t%u fragment%s dropped after timeout\n");
+       p(ips_forward, "\t%u packet%s forwarded\n");
+       p(ips_cantforward, "\t%u packet%s not forwardable\n");
+       p(ips_redirectsent, "\t%u redirect%s sent\n");
+#undef p
 #endif
 }
 
 #endif
 }
 
@@ -278,6 +278,7 @@ static      char *icmpnames[] = {
 /*
  * Dump ICMP statistics.
  */
 /*
  * Dump ICMP statistics.
  */
+void
 icmp_stats(off, name)
        off_t off;
        char *name;
 icmp_stats(off, name)
        off_t off;
        char *name;
@@ -287,11 +288,15 @@ icmp_stats(off, name)
 
        if (off == 0)
                return;
 
        if (off == 0)
                return;
-       kvm_read(off, (char *)&icmpstat, sizeof (icmpstat));
-       printf("%s:\n\t%u call%s to icmp_error\n", name,
-               icmpstat.icps_error, plural(icmpstat.icps_error));
-       printf("\t%u error%s not generated 'cuz old message was icmp\n",
-               icmpstat.icps_oldicmp, plural(icmpstat.icps_oldicmp));
+       kread(off, (char *)&icmpstat, sizeof (icmpstat));
+       printf("%s:\n", name);
+
+#define        p(f, m) if (icmpstat.f || sflag <= 1) \
+    printf(m, icmpstat.f, plural(icmpstat.f))
+
+       p(icps_error, "\t%u call%s to icmp_error\n");
+       p(icps_oldicmp,
+           "\t%u error%s not generated 'cuz old message was icmp\n");
        for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
                if (icmpstat.icps_outhist[i] != 0) {
                        if (first) {
        for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
                if (icmpstat.icps_outhist[i] != 0) {
                        if (first) {
@@ -301,14 +306,10 @@ icmp_stats(off, name)
                        printf("\t\t%s: %u\n", icmpnames[i],
                                icmpstat.icps_outhist[i]);
                }
                        printf("\t\t%s: %u\n", icmpnames[i],
                                icmpstat.icps_outhist[i]);
                }
-       printf("\t%u message%s with bad code fields\n",
-               icmpstat.icps_badcode, plural(icmpstat.icps_badcode));
-       printf("\t%u message%s < minimum length\n",
-               icmpstat.icps_tooshort, plural(icmpstat.icps_tooshort));
-       printf("\t%u bad checksum%s\n",
-               icmpstat.icps_checksum, plural(icmpstat.icps_checksum));
-       printf("\t%u message%s with bad length\n",
-               icmpstat.icps_badlen, plural(icmpstat.icps_badlen));
+       p(icps_badcode, "\t%u message%s with bad code fields\n");
+       p(icps_tooshort, "\t%u message%s < minimum length\n");
+       p(icps_checksum, "\t%u bad checksum%s\n");
+       p(icps_badlen, "\t%u message%s with bad length\n");
        for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
                if (icmpstat.icps_inhist[i] != 0) {
                        if (first) {
        for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
                if (icmpstat.icps_inhist[i] != 0) {
                        if (first) {
@@ -318,24 +319,25 @@ icmp_stats(off, name)
                        printf("\t\t%s: %u\n", icmpnames[i],
                                icmpstat.icps_inhist[i]);
                }
                        printf("\t\t%s: %u\n", icmpnames[i],
                                icmpstat.icps_inhist[i]);
                }
-       printf("\t%u message response%s generated\n",
-               icmpstat.icps_reflect, plural(icmpstat.icps_reflect));
+       p(icps_reflect, "\t%u message response%s generated\n");
+#undef p
 }
 
 /*
  * Pretty print an Internet address (net address + port).
  * If the nflag was specified, use numbers instead of names.
  */
 }
 
 /*
  * Pretty print an Internet address (net address + port).
  * If the nflag was specified, use numbers instead of names.
  */
+static void
 inetprint(in, port, proto)
        register struct in_addr *in;
 inetprint(in, port, proto)
        register struct in_addr *in;
-       u_short port; 
+       int port;
        char *proto;
 {
        struct servent *sp = 0;
        char *proto;
 {
        struct servent *sp = 0;
-       char line[80], *cp, *index();
+       char line[80], *cp;
        int width;
 
        int width;
 
-       sprintf(line, "%.*s.", (Aflag && !nflag) ? 12 : 16, inetname(*in));
+       sprintf(line, "%.*s.", (Aflag && !nflag) ? 12 : 16, inetname(in));
        cp = index(line, '\0');
        if (!nflag && port)
                sp = getservbyport((int)port, proto);
        cp = index(line, '\0');
        if (!nflag && port)
                sp = getservbyport((int)port, proto);
@@ -349,12 +351,12 @@ inetprint(in, port, proto)
 
 /*
  * Construct an Internet address representation.
 
 /*
  * Construct an Internet address representation.
- * If the nflag has been supplied, give 
+ * If the nflag has been supplied, give
  * numeric value, otherwise try for symbolic name.
  */
  * numeric value, otherwise try for symbolic name.
  */
-char *
-inetname(in)
-       struct in_addr in;
+static char *
+inetname(inp)
+       struct in_addr *inp;
 {
        register char *cp;
        static char line[50];
 {
        register char *cp;
        static char line[50];
@@ -372,9 +374,9 @@ inetname(in)
                        domain[0] = 0;
        }
        cp = 0;
                        domain[0] = 0;
        }
        cp = 0;
-       if (!nflag && in.s_addr != INADDR_ANY) {
-               int net = inet_netof(in);
-               int lna = inet_lnaof(in);
+       if (!nflag && inp->s_addr != INADDR_ANY) {
+               int net = inet_netof(*inp);
+               int lna = inet_lnaof(*inp);
 
                if (lna == INADDR_ANY) {
                        np = getnetbyaddr(net, AF_INET);
 
                if (lna == INADDR_ANY) {
                        np = getnetbyaddr(net, AF_INET);
@@ -382,7 +384,7 @@ inetname(in)
                                cp = np->n_name;
                }
                if (cp == 0) {
                                cp = np->n_name;
                }
                if (cp == 0) {
-                       hp = gethostbyaddr((char *)&in, sizeof (in), AF_INET);
+                       hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET);
                        if (hp) {
                                if ((cp = index(hp->h_name, '.')) &&
                                    !strcmp(cp + 1, domain))
                        if (hp) {
                                if ((cp = index(hp->h_name, '.')) &&
                                    !strcmp(cp + 1, domain))
@@ -391,15 +393,15 @@ inetname(in)
                        }
                }
        }
                        }
                }
        }
-       if (in.s_addr == INADDR_ANY)
+       if (inp->s_addr == INADDR_ANY)
                strcpy(line, "*");
        else if (cp)
                strcpy(line, cp);
        else {
                strcpy(line, "*");
        else if (cp)
                strcpy(line, cp);
        else {
-               in.s_addr = ntohl(in.s_addr);
+               inp->s_addr = ntohl(inp->s_addr);
 #define C(x)   ((x) & 0xff)
 #define C(x)   ((x) & 0xff)
-               sprintf(line, "%u.%u.%u.%u", C(in.s_addr >> 24),
-                       C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr));
+               sprintf(line, "%u.%u.%u.%u", C(inp->s_addr >> 24),
+                   C(inp->s_addr >> 16), C(inp->s_addr >> 8), C(inp->s_addr));
        }
        return (line);
 }
        }
        return (line);
 }
index 984ada7..f227814 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)iso.c      5.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)iso.c      5.11 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
index e69f212..524ecd1 100644 (file)
@@ -12,21 +12,24 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.27 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.28 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
+#include <sys/protosw.h>
 #include <sys/socket.h>
 #include <sys/file.h>
 #include <errno.h>
 #include <netdb.h>
 #include <nlist.h>
 #include <kvm.h>
 #include <sys/socket.h>
 #include <sys/file.h>
 #include <errno.h>
 #include <netdb.h>
 #include <nlist.h>
 #include <kvm.h>
+#include <limits.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
 #include <paths.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
 #include <paths.h>
+#include "netstat.h"
 
 struct nlist nl[] = {
 #define        N_MBSTAT        0
 
 struct nlist nl[] = {
 #define        N_MBSTAT        0
@@ -77,10 +80,6 @@ struct nlist nl[] = {
        { "_cltb"},
 #define N_CLTPSTAT     23
        { "_cltpstat"},
        { "_cltb"},
 #define N_CLTPSTAT     23
        { "_cltpstat"},
-#define        N_NFILE         24
-       { "_nfile" },
-#define        N_FILE          25
-       { "_file" },
 
     /* BBN Internet protocol implementation */
 #define        N_TCP           23
 
     /* BBN Internet protocol implementation */
 #define        N_TCP           23
@@ -95,23 +94,12 @@ struct nlist nl[] = {
        "",
 };
 
        "",
 };
 
-/* internet protocols */
-extern int protopr(), bbnprotopr();
-extern int tcp_stats(), udp_stats(), ip_stats(), icmp_stats();
-/* ns protocols */
-extern int tcpstats(), udpstats(), ipstats(), icmpstats(), rdpstats();
-extern int nsprotopr();
-extern int spp_stats(), idp_stats(), nserr_stats();
-/* iso protocols */
-extern int iso_protopr();
-extern int tp_stats(), esis_stats(), clnp_stats(), cltp_stats();
-
 struct protox {
        u_char  pr_index;               /* index into nlist of cb head */
        u_char  pr_sindex;              /* index into nlist of stat block */
        u_char  pr_wanted;              /* 1 if wanted, 0 otherwise */
 struct protox {
        u_char  pr_index;               /* index into nlist of cb head */
        u_char  pr_sindex;              /* index into nlist of stat block */
        u_char  pr_wanted;              /* 1 if wanted, 0 otherwise */
-       int     (*pr_cblocks)();        /* control blocks printing routine */
-       int     (*pr_stats)();          /* statistics printing routine */
+       void    (*pr_cblocks)();        /* control blocks printing routine */
+       void    (*pr_stats)();          /* statistics printing routine */
        char    *pr_name;               /* well-known name */
 };
 
        char    *pr_name;               /* well-known name */
 };
 
@@ -171,27 +159,14 @@ struct protox isoprotox[] = {
 
 struct protox *protoprotox[] = { protox, nsprotox, isoprotox, NULL };
 
 
 struct protox *protoprotox[] = { protox, nsprotox, isoprotox, NULL };
 
-char   *nlistf;
-char   *memf;
-int    kmem;
-int    kflag;
-int    Aflag;
-int    aflag;
-int    hflag;
-int    iflag;
-int    mflag;
-int    nflag;
-int    pflag;
-int    rflag;
-int    sflag;
-int    tflag;
-int    dflag;
-int    interval;
-char   *interface;
-int    unit;
-
-int    af = AF_UNSPEC;
+static void printproto __P((struct protox *, char *));
+static void usage __P(());
+static struct protox *name2protox __P((char *));
+static struct protox *knownname __P((char *));
+
+kvm_t *kvmd;
 
 
+int
 main(argc, argv)
        int argc;
        char **argv;
 main(argc, argv)
        int argc;
        char **argv;
@@ -200,9 +175,16 @@ main(argc, argv)
        extern int optind;
        register struct protoent *p;
        register struct protox *tp;     /* for printing cblocks & stats */
        extern int optind;
        register struct protoent *p;
        register struct protox *tp;     /* for printing cblocks & stats */
-       struct protox *name2protox();   /* for -p */
+       register char *cp;
        int ch;
        int ch;
-       void usage(); 
+       char *nlistf = NULL, *memf = NULL;
+       char buf[_POSIX2_LINE_MAX];
+
+       if (cp = rindex(argv[0], '/'))
+               prog = cp + 1;
+       else
+               prog = argv[0];
+       af = AF_UNSPEC;
 
        while ((ch = getopt(argc, argv, "Aadf:hI:iM:mN:np:rstuw")) != EOF)
                switch((char)ch) {
 
        while ((ch = getopt(argc, argv, "Aadf:hI:iM:mN:np:rstuw")) != EOF)
                switch((char)ch) {
@@ -226,7 +208,8 @@ main(argc, argv)
                                af = AF_ISO;
                        else {
                                (void)fprintf(stderr,
                                af = AF_ISO;
                        else {
                                (void)fprintf(stderr,
-                                   "%s: unknown address family\n", optarg);
+                                   "%s: %s: unknown address family\n",
+                                   prog, optarg);
                                exit(1);
                        }
                        break;
                                exit(1);
                        }
                        break;
@@ -237,7 +220,8 @@ main(argc, argv)
                        char *cp;
 
                        iflag = 1;
                        char *cp;
 
                        iflag = 1;
-                       for (cp = interface = optarg; isalpha(*cp); cp++);
+                       for (cp = interface = optarg; isalpha(*cp); cp++)
+                               continue;
                        unit = atoi(cp);
                        *cp = '\0';
                        break;
                        unit = atoi(cp);
                        *cp = '\0';
                        break;
@@ -247,7 +231,6 @@ main(argc, argv)
                        break;
                case 'M':
                        memf = optarg;
                        break;
                case 'M':
                        memf = optarg;
-                       kflag = 1;
                        break;
                case 'm':
                        mflag = 1;
                        break;
                case 'm':
                        mflag = 1;
@@ -261,8 +244,8 @@ main(argc, argv)
                case 'p':
                        if ((tp = name2protox(optarg)) == NULL) {
                                (void)fprintf(stderr,
                case 'p':
                        if ((tp = name2protox(optarg)) == NULL) {
                                (void)fprintf(stderr,
-                                   "%s: unknown or uninstrumented protocol\n",
-                                   optarg);
+                                   "%s: %s: unknown or uninstrumented protocol\n",
+                                   prog, optarg);
                                exit(1);
                        }
                        pflag = 1;
                                exit(1);
                        }
                        pflag = 1;
@@ -271,7 +254,7 @@ main(argc, argv)
                        rflag = 1;
                        break;
                case 's':
                        rflag = 1;
                        break;
                case 's':
-                       sflag = 1;
+                       ++sflag;
                        break;
                case 't':
                        tflag = 1;
                        break;
                case 't':
                        tflag = 1;
@@ -301,13 +284,12 @@ main(argc, argv)
                }
                if (*argv) {
                        nlistf = *argv;
                }
                if (*argv) {
                        nlistf = *argv;
-                       if (*++argv) {
+                       if (*++argv)
                                memf = *argv;
                                memf = *argv;
-                               kflag = 1;
-                       }
                }
        }
 #endif
                }
        }
 #endif
+
        /*
         * Discard setgid privileges if not the running kernel so that bad
         * guys can't print interesting stuff from kernel memory.
        /*
         * Discard setgid privileges if not the running kernel so that bad
         * guys can't print interesting stuff from kernel memory.
@@ -315,12 +297,15 @@ main(argc, argv)
        if (nlistf != NULL || memf != NULL)
                setgid(getgid());
 
        if (nlistf != NULL || memf != NULL)
                setgid(getgid());
 
-       if (kvm_openfiles(nlistf, memf, NULL) == -1) {
-               fprintf(stderr, "netstat: kvm_openfiles: %s\n", kvm_geterr());
+       if ((kvmd = kvm_open(nlistf, memf, NULL, O_RDONLY, prog)) == NULL) {
+               fprintf(stderr, "%s: kvm_open: %s\n", prog, buf);
                exit(1);
        }
                exit(1);
        }
-       if (kvm_nlist(nl) < 0 || nl[0].n_type == 0) {
-               fprintf(stderr, "netstat: no namelist\n");
+       if (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0) {
+               if (nlistf)
+                       fprintf(stderr, "%s: %s: no namelist\n", prog, nlistf);
+               else
+                       fprintf(stderr, "%s: no namelist\n", prog);
                exit(1);
        }
        if (mflag) {
                exit(1);
        }
        if (mflag) {
@@ -356,16 +341,7 @@ main(argc, argv)
                        routepr((off_t)nl[N_RTREE].n_value);
                exit(0);
        }
                        routepr((off_t)nl[N_RTREE].n_value);
                exit(0);
        }
-    if (af == AF_INET || af == AF_UNSPEC) {
-       struct protox *head;
-
-       head = (nl[N_TCB].n_type == 0) ? bbnprotox : berkprotox;
-       setprotoent(1);
-       setservent(1);
 
 
-       for (tp = head; tp->pr_name; tp++) {
-               if (tp->pr_wanted == 0)
-                       continue;
 
                if (sflag) {
                        if (tp->pr_stats)
 
                if (sflag) {
                        if (tp->pr_stats)
@@ -373,38 +349,27 @@ main(argc, argv)
                } else if (tp->pr_cblocks)
                        (*tp->pr_cblocks)(nl[tp->pr_index].n_value, tp->pr_name);
        }
                } else if (tp->pr_cblocks)
                        (*tp->pr_cblocks)(nl[tp->pr_index].n_value, tp->pr_name);
        }
-       endprotoent();
-    }
-    if (af == AF_NS || af == AF_UNSPEC) {
-       for (tp = nsprotox; tp->pr_name; tp++) {
-               if (sflag) {
-                       if (tp->pr_stats)
-                               (*tp->pr_stats)(nl[tp->pr_sindex].n_value,
-                                       tp->pr_name);
-               } else
-                       if (tp->pr_cblocks)
-                               (*tp->pr_cblocks)(nl[tp->pr_index].n_value,
-                                       tp->pr_name);
-       }
-    }
-    if (af == AF_ISO || af == AF_UNSPEC) {
-       for (tp = isoprotox; tp->pr_name; tp++) {
-               if (sflag) {
-                       if (tp->pr_stats)
-                               (*tp->pr_stats)(nl[tp->pr_sindex].n_value,
-                                       tp->pr_name);
-               } else
-                       if (tp->pr_cblocks)
-                               (*tp->pr_cblocks)(nl[tp->pr_index].n_value,
-                                       tp->pr_name);
+       if (pr != NULL && (off || af != AF_UNSPEC))
+               (*pr)(off, name);
+}
+
+/*
+ * Read kernel memory, return 0 on success.
+ */
+int
+kread(addr, buf, size)
+       off_t addr;
+       char *buf;
+       int size;
+{
+
+       if (kvm_read(kvmd, addr, buf, size) != size) {
+               /* XXX this duplicates kvm_read's error printout */
+               (void)fprintf(stderr, "%s: kvm_read %s\n", prog,
+                   kvm_geterr(kvmd));
+               return (-1);
        }
        }
-    }
-    if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag)
-           unixpr((off_t)nl[N_NFILE].n_value, (off_t)nl[N_FILE].n_value,
-               (struct protosw *)nl[N_UNIXSW].n_value);
-    if (af == AF_UNSPEC && sflag)
-       impstats(nl[N_IMP].n_value, nl[N_NIMP].n_value);
-    exit(0);
+       return (0);
 }
 
 char *
 }
 
 char *
@@ -417,23 +382,23 @@ plural(n)
 /*
  * Find the protox for the given "well-known" name.
  */
 /*
  * Find the protox for the given "well-known" name.
  */
-struct protox *
+static struct protox *
 knownname(name)
        char *name;
 {
        struct protox **tpp, *tp;
 
        for (tpp = protoprotox; *tpp; tpp++)
 knownname(name)
        char *name;
 {
        struct protox **tpp, *tp;
 
        for (tpp = protoprotox; *tpp; tpp++)
-           for (tp = *tpp; tp->pr_name; tp++)
-               if (strcmp(tp->pr_name, name) == 0)
-                       return(tp);
-       return(NULL);
+               for (tp = *tpp; tp->pr_name; tp++)
+                       if (strcmp(tp->pr_name, name) == 0)
+                               return (tp);
+       return (NULL);
 }
 
 /*
  * Find the protox corresponding to name.
  */
 }
 
 /*
  * Find the protox corresponding to name.
  */
-struct protox *
+static struct protox *
 name2protox(name)
        char *name;
 {
 name2protox(name)
        char *name;
 {
@@ -446,7 +411,7 @@ name2protox(name)
         * fails, check if name is an alias for an Internet protocol.
         */
        if (tp = knownname(name))
         * fails, check if name is an alias for an Internet protocol.
         */
        if (tp = knownname(name))
-               return(tp);
+               return (tp);
 
        setprotoent(1);                 /* make protocol lookup cheaper */
        while (p = getprotoent()) {
 
        setprotoent(1);                 /* make protocol lookup cheaper */
        while (p = getprotoent()) {
@@ -454,18 +419,18 @@ name2protox(name)
                for (alias = p->p_aliases; *alias; alias++)
                        if (strcmp(name, *alias) == 0) {
                                endprotoent();
                for (alias = p->p_aliases; *alias; alias++)
                        if (strcmp(name, *alias) == 0) {
                                endprotoent();
-                               return(knownname(p->p_name));
+                               return (knownname(p->p_name));
                        }
        }
        endprotoent();
                        }
        }
        endprotoent();
-       return(NULL);
+       return (NULL);
 }
 
 }
 
-void
+static void
 usage()
 {
        (void)fprintf(stderr,
 usage()
 {
        (void)fprintf(stderr,
-"usage: netstat [-Aan] [-f address_family] [-M core] [-N system]\n");
+"usage: %s [-Aan] [-f address_family] [-M core] [-N system]\n", prog);
        (void)fprintf(stderr,
 "               [-himnrs] [-f address_family] [-M core] [-N system]\n");
        (void)fprintf(stderr,
        (void)fprintf(stderr,
 "               [-himnrs] [-f address_family] [-M core] [-N system]\n");
        (void)fprintf(stderr,
index a6f837a..44e8854 100644 (file)
@@ -6,12 +6,17 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)mbuf.c     5.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)mbuf.c     5.11 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include <stdio.h>
 #include <sys/param.h>
 #include <sys/param.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
 #include <sys/mbuf.h>
 #include <sys/mbuf.h>
+
+#include <stdio.h>
+#include "netstat.h"
+
 #define        YES     1
 typedef int bool;
 
 #define        YES     1
 typedef int bool;
 
@@ -34,7 +39,7 @@ static struct mbtypes {
        { MT_SONAME,    "socket names and addresses" },
        { MT_SOOPTS,    "socket options" },
        { MT_RIGHTS,    "access rights" },
        { MT_SONAME,    "socket names and addresses" },
        { MT_SOOPTS,    "socket options" },
        { MT_RIGHTS,    "access rights" },
-       { MT_IFADDR,    "interface addresses" },                /* XXX */
+       { MT_IFADDR,    "interface addresses" },                /* XXX */
        { 0, 0 }
 };
 
        { 0, 0 }
 };
 
@@ -44,6 +49,7 @@ bool seen[256];                       /* "have we seen this type yet?" */
 /*
  * Print mbuf statistics.
  */
 /*
  * Print mbuf statistics.
  */
+void
 mbpr(mbaddr)
        off_t mbaddr;
 {
 mbpr(mbaddr)
        off_t mbaddr;
 {
@@ -52,18 +58,16 @@ mbpr(mbaddr)
        register struct mbtypes *mp;
 
        if (nmbtypes != 256) {
        register struct mbtypes *mp;
 
        if (nmbtypes != 256) {
-               fprintf(stderr, "unexpected change to mbstat; check source\n");
+               fprintf(stderr,
+                   "%s: unexpected change to mbstat; check source\n", prog);
                return;
        }
        if (mbaddr == 0) {
                return;
        }
        if (mbaddr == 0) {
-               printf("mbstat: symbol not in namelist\n");
+               fprintf(stderr, "%s: mbstat: symbol not in namelist\n", prog);
                return;
        }
                return;
        }
-       if (kvm_read(mbaddr, (char *)&mbstat, sizeof (mbstat))
-                                               != sizeof (mbstat)) {
-               printf("mbstat: bad read\n");
+       if (kread(mbaddr, (char *)&mbstat, sizeof (mbstat)))
                return;
                return;
-       }
        totmbufs = 0;
        for (mp = mbtypes; mp->mt_name; mp++)
                totmbufs += mbstat.m_mtypes[mp->mt_type];
        totmbufs = 0;
        for (mp = mbtypes; mp->mt_name; mp++)
                totmbufs += mbstat.m_mtypes[mp->mt_type];
index 16237a0..1ed5fb2 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)netstat.h   5.1 (Berkeley) %G%
+ *     @(#)netstat.h   5.2 (Berkeley) %G%
  */
 
 #include <sys/cdefs.h>
  */
 
 #include <sys/cdefs.h>
@@ -65,7 +65,7 @@ void  ns_erputil __P((int, int));
 
 void   intpr __P((int, off_t));
 
 
 void   intpr __P((int, off_t));
 
-void   unixpr __P((off_t, off_t, struct protosw *));
+void   unixpr __P((struct protosw *));
 
 void   esis_stats __P((off_t, char *));
 void   clnp_stats __P((off_t, char *));
 
 void   esis_stats __P((off_t, char *));
 void   clnp_stats __P((off_t, char *));
index 6df994f..eacae0d 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ns.c       5.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)ns.c       5.14 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -36,15 +36,13 @@ static char sccsid[] = "@(#)ns.c    5.13 (Berkeley) %G%";
 #include <errno.h>
 #include <stdio.h>
 #include <string.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 Aflag;
-extern int aflag;
-extern int nflag;
-extern char *plural();
-char *ns_prpr();
+
+static char *ns_prpr __P((struct ns_addr *));
 
 static int first = 1;
 
 
 static int first = 1;
 
@@ -55,6 +53,7 @@ static        int first = 1;
  * -a (all) flag is specified.
  */
 
  * -a (all) flag is specified.
  */
 
+void
 nsprotopr(off, name)
        off_t off;
        char *name;
 nsprotopr(off, name)
        off_t off;
        char *name;
@@ -66,7 +65,7 @@ nsprotopr(off, name)
        if (off == 0)
                return;
        isspp = strcmp(name, "spp") == 0;
        if (off == 0)
                return;
        isspp = strcmp(name, "spp") == 0;
-       kvm_read(off, (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)
        nspcb = cb;
        prev = (struct nspcb *)off;
        if (nspcb.nsp_next == (struct nspcb *)off)
@@ -75,7 +74,7 @@ nsprotopr(off, name)
                off_t ppcb;
 
                next = nspcb.nsp_next;
                off_t ppcb;
 
                next = nspcb.nsp_next;
-               kvm_read((off_t)next, (char *)&nspcb, sizeof (nspcb));
+               kread((off_t)next, (char *)&nspcb, sizeof (nspcb));
                if (nspcb.nsp_prev != prev) {
                        printf("???\n");
                        break;
                if (nspcb.nsp_prev != prev) {
                        printf("???\n");
                        break;
@@ -83,12 +82,12 @@ nsprotopr(off, name)
                if (!aflag && ns_nullhost(nspcb.nsp_faddr) ) {
                        continue;
                }
                if (!aflag && ns_nullhost(nspcb.nsp_faddr) ) {
                        continue;
                }
-               kvm_read((off_t)nspcb.nsp_socket,
+               kread((off_t)nspcb.nsp_socket,
                                (char *)&sockb, sizeof (sockb));
                ppcb = (off_t) nspcb.nsp_pcb;
                if (ppcb) {
                        if (isspp) {
                                (char *)&sockb, sizeof (sockb));
                ppcb = (off_t) nspcb.nsp_pcb;
                if (ppcb) {
                        if (isspp) {
-                               kvm_read(ppcb, (char *)&sppcb, sizeof (sppcb));
+                               kread(ppcb, (char *)&sppcb, sizeof (sppcb));
                        } else continue;
                } else
                        if (isspp) continue;
                        } else continue;
                } else
                        if (isspp) continue;
@@ -129,6 +128,7 @@ nsprotopr(off, name)
 /*
  * Dump SPP statistics structure.
  */
 /*
  * Dump SPP statistics structure.
  */
+void
 spp_stats(off, name)
        off_t off;
        char *name;
 spp_stats(off, name)
        off_t off;
        char *name;
@@ -138,7 +138,7 @@ spp_stats(off, name)
 
        if (off == 0)
                return;
 
        if (off == 0)
                return;
-       kvm_read(off, (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");
@@ -206,6 +206,7 @@ spp_stats(off, name)
 /*
  * Dump IDP statistics structure.
  */
 /*
  * Dump IDP statistics structure.
  */
+void
 idp_stats(off, name)
        off_t off;
        char *name;
 idp_stats(off, name)
        off_t off;
        char *name;
@@ -214,7 +215,7 @@ idp_stats(off, name)
 
        if (off == 0)
                return;
 
        if (off == 0)
                return;
-       kvm_read(off, (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");
@@ -241,6 +242,7 @@ static      struct {
  * Dump NS Error statistics structure.
  */
 /*ARGSUSED*/
  * Dump NS Error statistics structure.
  */
 /*ARGSUSED*/
+void
 nserr_stats(off, name)
        off_t off;
        char *name;
 nserr_stats(off, name)
        off_t off;
        char *name;
@@ -252,7 +254,7 @@ nserr_stats(off, name)
 
        if (off == 0)
                return;
 
        if (off == 0)
                return;
-       kvm_read(off, (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",
@@ -283,7 +285,9 @@ nserr_stats(off, name)
        }
 }
 
        }
 }
 
+static void
 ns_erputil(z, c)
 ns_erputil(z, c)
+       int z, c;
 {
        int j;
        char codebuf[30];
 {
        int j;
        char codebuf[30];
@@ -302,19 +306,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);
 }
 
 static struct sockaddr_ns ssns = {AF_NS};
 
                where =  ns_errnames[j].where;
        ANY(z, name, where);
 }
 
 static struct sockaddr_ns ssns = {AF_NS};
 
+static
 char *ns_prpr(x)
        struct ns_addr *x;
 {
        struct sockaddr_ns *sns = &ssns;
 char *ns_prpr(x)
        struct ns_addr *x;
 {
        struct sockaddr_ns *sns = &ssns;
-       extern char *ns_print();
 
        sns->sns_addr = *x;
 
        sns->sns_addr = *x;
-       return(ns_print(sns));
+       return(ns_print((struct sockaddr *)sns));
 }
 }
index 3279491..a509740 100644 (file)
@@ -6,10 +6,11 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)route.c    5.22 (Berkeley) %G%";
+static char sccsid[] = "@(#)route.c    5.23 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
+#include <sys/protosw.h>
 #include <sys/socket.h>
 #include <sys/mbuf.h>
 
 #include <sys/socket.h>
 #include <sys/mbuf.h>
 
@@ -23,17 +24,16 @@ static char sccsid[] = "@(#)route.c 5.22 (Berkeley) %G%";
 
 #include <netns/ns.h>
 
 
 #include <netns/ns.h>
 
-#include <netdb.h>
 #include <sys/kinfo.h>
 
 #include <sys/kinfo.h>
 
+#include <netdb.h>
 #include <stdio.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <string.h>
+#include "netstat.h"
 
 
-extern int nflag, aflag, Aflag, af;
-extern char *routename(), *netname(), *ns_print(), *plural();
-extern char *malloc();
 #define kget(p, d) \
 #define kget(p, d) \
-       (kvm_read((off_t)(p), (char *)&(d), sizeof (d)))
+       (kread((off_t)(p), (char *)&(d), sizeof (d)))
 
 /*
  * Definitions for showing gateway flags.
 
 /*
  * Definitions for showing gateway flags.
@@ -67,9 +67,19 @@ struct       radix_mask rmask;
 
 int    NewTree = 0;
 
 
 int    NewTree = 0;
 
+static struct sockaddr *kgetsa __P((struct sockaddr *));
+static void p_tree __P((struct radix_node *));
+static void p_rtnode __P(());
+static void ntreestuff __P(());
+static void np_rtentry __P((struct rt_msghdr *));
+static void p_sockaddr __P((struct sockaddr *, int, int));
+static void p_flags __P((int, char *));
+static void p_rtentry __P((struct rtentry *));
+
 /*
  * Print routing tables.
  */
 /*
  * Print routing tables.
  */
+void
 routepr(rtree)
        off_t rtree;
 {
 routepr(rtree)
        off_t rtree;
 {
@@ -92,7 +102,7 @@ routepr(rtree)
                                continue;
                        kget(rnh, head);
                        if (i == AF_UNSPEC) {
                                continue;
                        kget(rnh, head);
                        if (i == AF_UNSPEC) {
-                               if (Aflag && af == 0) { 
+                               if (Aflag && af == 0) {
                                        printf("Netmasks:\n");
                                        p_tree(head.rnh_treetop);
                                }
                                        printf("Netmasks:\n");
                                        p_tree(head.rnh_treetop);
                                }
@@ -109,6 +119,7 @@ routepr(rtree)
 /*
  * Print address family header before a section of the routing table.
  */
 /*
  * Print address family header before a section of the routing table.
  */
+void
 pr_family(af)
        int af;
 {
 pr_family(af)
        int af;
 {
@@ -144,6 +155,7 @@ pr_family(af)
 /*
  * Print header for routing table columns.
  */
 /*
  * Print header for routing table columns.
  */
+void
 pr_rthdr()
 {
 
 pr_rthdr()
 {
 
@@ -155,17 +167,18 @@ pr_rthdr()
                "Flags", "Refs", "Use", "Interface");
 }
 
                "Flags", "Refs", "Use", "Interface");
 }
 
-struct sockaddr *
+static struct sockaddr *
 kgetsa(dst)
        register struct sockaddr *dst;
 {
 
        kget(dst, pt_u.u_sa);
        if (pt_u.u_sa.sa_len > sizeof (pt_u.u_sa))
 kgetsa(dst)
        register struct sockaddr *dst;
 {
 
        kget(dst, pt_u.u_sa);
        if (pt_u.u_sa.sa_len > sizeof (pt_u.u_sa))
-               kvm_read((off_t)dst, pt_u.u_data, pt_u.u_sa.sa_len);
+               kread((off_t)dst, (char *)pt_u.u_data, pt_u.u_sa.sa_len);
        return (&pt_u.u_sa);
 }
 
        return (&pt_u.u_sa);
 }
 
+static void
 p_tree(rn)
        struct radix_node *rn;
 {
 p_tree(rn)
        struct radix_node *rn;
 {
@@ -204,6 +217,7 @@ again:
 
 char   nbuf[20];
 
 
 char   nbuf[20];
 
+static void
 p_rtnode()
 {
        struct radix_mask *rm = rnode.rn_mklist;
 p_rtnode()
 {
        struct radix_mask *rm = rnode.rn_mklist;
@@ -232,6 +246,7 @@ p_rtnode()
        putchar('\n');
 }
 
        putchar('\n');
 }
 
+static void
 ntreestuff()
 {
        int needed;
 ntreestuff()
 {
        int needed;
@@ -251,11 +266,15 @@ ntreestuff()
        }
 }
 
        }
 }
 
+static void
 np_rtentry(rtm)
        register struct rt_msghdr *rtm;
 {
        register struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
 np_rtentry(rtm)
        register struct rt_msghdr *rtm;
 {
        register struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
-       static int masks_done, old_af, banner_printed;
+#ifdef notdef
+       static int masks_done, banner_printed;
+#endif
+       static int old_af;
        int af = 0, interesting = RTF_UP | RTF_GATEWAY | RTF_HOST;
 
 #ifdef notdef
        int af = 0, interesting = RTF_UP | RTF_GATEWAY | RTF_HOST;
 
 #ifdef notdef
@@ -289,11 +308,12 @@ np_rtentry(rtm)
        putchar('\n');
 }
 
        putchar('\n');
 }
 
+static void
 p_sockaddr(sa, flags, width)
        struct sockaddr *sa;
        int flags, width;
 {
 p_sockaddr(sa, flags, width)
        struct sockaddr *sa;
        int flags, width;
 {
-       char format[20], workbuf[128], *cplim;
+       char workbuf[128], *cplim;
        register char *cp = workbuf;
 
        switch(sa->sa_family) {
        register char *cp = workbuf;
 
        switch(sa->sa_family) {
@@ -303,18 +323,18 @@ p_sockaddr(sa, flags, width)
 
                cp = (sin->sin_addr.s_addr == 0) ? "default" :
                      ((flags & RTF_HOST) ?
 
                cp = (sin->sin_addr.s_addr == 0) ? "default" :
                      ((flags & RTF_HOST) ?
-                       routename(sin->sin_addr) : netname(sin->sin_addr, 0L));
+                       routename(sin->sin_addr.s_addr) :
+                       netname(sin->sin_addr.s_addr, 0L));
                break;
            }
 
        case AF_NS:
                break;
            }
 
        case AF_NS:
-               cp = ns_print((struct sockaddr_ns *)sa);
+               cp = ns_print(sa);
                break;
 
        case AF_LINK:
            {
                register struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
                break;
 
        case AF_LINK:
            {
                register struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
-               extern char *link_ntoa();
 
                if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 &&
                    sdl->sdl_slen == 0)
 
                if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 &&
                    sdl->sdl_slen == 0)
@@ -364,6 +384,7 @@ p_sockaddr(sa, flags, width)
        }
 }
 
        }
 }
 
+static void
 p_flags(f, format)
        register int f;
        char *format;
 p_flags(f, format)
        register int f;
        char *format;
@@ -378,10 +399,10 @@ p_flags(f, format)
        printf(format, name);
 }
 
        printf(format, name);
 }
 
+static void
 p_rtentry(rt)
 p_rtentry(rt)
-register struct rtentry *rt;
+       register struct rtentry *rt;
 {
 {
-       register struct sockaddr *sa;
        static struct ifnet ifnet, *lastif;
        static char name[16];
 
        static struct ifnet ifnet, *lastif;
        static char name[16];
 
@@ -392,7 +413,7 @@ register struct rtentry *rt;
        if (rt->rt_ifp) {
                if (rt->rt_ifp != lastif) {
                        kget(rt->rt_ifp, ifnet);
        if (rt->rt_ifp) {
                if (rt->rt_ifp != lastif) {
                        kget(rt->rt_ifp, ifnet);
-                       kvm_read((off_t)ifnet.if_name, name, 16);
+                       kread((off_t)ifnet.if_name, name, 16);
                        lastif = rt->rt_ifp;
                }
                printf(" %.15s%d%s", name, ifnet.if_unit,
                        lastif = rt->rt_ifp;
                }
                printf(" %.15s%d%s", name, ifnet.if_unit,
@@ -403,14 +424,13 @@ register struct rtentry *rt;
 
 char *
 routename(in)
 
 char *
 routename(in)
-       struct in_addr in;
+       u_long in;
 {
        register char *cp;
        static char line[MAXHOSTNAMELEN + 1];
        struct hostent *hp;
        static char domain[MAXHOSTNAMELEN + 1];
        static int first = 1;
 {
        register char *cp;
        static char line[MAXHOSTNAMELEN + 1];
        struct hostent *hp;
        static char domain[MAXHOSTNAMELEN + 1];
        static int first = 1;
-       char *index();
 
        if (first) {
                first = 0;
 
        if (first) {
                first = 0;
@@ -435,9 +455,9 @@ routename(in)
                strncpy(line, cp, sizeof(line) - 1);
        else {
 #define C(x)   ((x) & 0xff)
                strncpy(line, cp, sizeof(line) - 1);
        else {
 #define C(x)   ((x) & 0xff)
-               in.s_addr = ntohl(in.s_addr);
-               sprintf(line, "%u.%u.%u.%u", C(in.s_addr >> 24),
-                       C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr));
+               in = ntohl(in);
+               sprintf(line, "%u.%u.%u.%u",
+                   C(in >> 24), C(in >> 16), C(in >> 8), C(in));
        }
        return (line);
 }
        }
        return (line);
 }
@@ -448,17 +468,16 @@ routename(in)
  */
 char *
 netname(in, mask)
  */
 char *
 netname(in, mask)
-       struct in_addr in;
-       u_long mask;
+       u_long in, mask;
 {
        char *cp = 0;
        static char line[MAXHOSTNAMELEN + 1];
        struct netent *np = 0;
        u_long net;
 {
        char *cp = 0;
        static char line[MAXHOSTNAMELEN + 1];
        struct netent *np = 0;
        u_long net;
-       register i;
+       register int i;
        int subnetshift;
 
        int subnetshift;
 
-       i = ntohl(in.s_addr);
+       i = ntohl(in);
        if (!nflag && i) {
                if (mask == 0) {
                        if (IN_CLASSA(i)) {
        if (!nflag && i) {
                if (mask == 0) {
                        if (IN_CLASSA(i)) {
@@ -486,7 +505,7 @@ netname(in, mask)
                np = getnetbyaddr(net, AF_INET);
                if (np)
                        cp = np->n_name;
                np = getnetbyaddr(net, AF_INET);
                if (np)
                        cp = np->n_name;
-       }       
+       }
        if (cp)
                strncpy(line, cp, sizeof(line) - 1);
        else if ((i & 0xffffff) == 0)
        if (cp)
                strncpy(line, cp, sizeof(line) - 1);
        else if ((i & 0xffffff) == 0)
@@ -504,6 +523,7 @@ netname(in, mask)
 /*
  * Print routing statistics
  */
 /*
  * Print routing statistics
  */
+void
 rt_stats(off)
        off_t off;
 {
 rt_stats(off)
        off_t off;
 {
@@ -513,7 +533,7 @@ rt_stats(off)
                printf("rtstat: symbol not in namelist\n");
                return;
        }
                printf("rtstat: symbol not in namelist\n");
                return;
        }
-       kvm_read(off, (char *)&rtstat, sizeof (rtstat));
+       kread(off, (char *)&rtstat, sizeof (rtstat));
        printf("routing:\n");
        printf("\t%u bad routing redirect%s\n",
                rtstat.rts_badredirect, plural(rtstat.rts_badredirect));
        printf("routing:\n");
        printf("\t%u bad routing redirect%s\n",
                rtstat.rts_badredirect, plural(rtstat.rts_badredirect));
@@ -530,9 +550,10 @@ short ns_nullh[] = {0,0,0};
 short ns_bh[] = {-1,-1,-1};
 
 char *
 short ns_bh[] = {-1,-1,-1};
 
 char *
-ns_print(sns)
-struct sockaddr_ns *sns;
+ns_print(sa)
+       register struct sockaddr *sa;
 {
 {
+       register struct sockaddr_ns *sns = (struct sockaddr_ns*)sa;
        struct ns_addr work;
        union { union ns_net net_e; u_long long_e; } net;
        u_short port;
        struct ns_addr work;
        union { union ns_net net_e; u_long long_e; } net;
        u_short port;
@@ -561,7 +582,8 @@ struct sockaddr_ns *sns;
                q = work.x_host.c_host;
                sprintf(chost, "%02x%02x%02x%02x%02x%02xH",
                        q[0], q[1], q[2], q[3], q[4], q[5]);
                q = work.x_host.c_host;
                sprintf(chost, "%02x%02x%02x%02x%02x%02xH",
                        q[0], q[1], q[2], q[3], q[4], q[5]);
-               for (p = chost; *p == '0' && p < chost + 12; p++);
+               for (p = chost; *p == '0' && p < chost + 12; p++)
+                       continue;
                host = p;
        }
        if (port)
                host = p;
        }
        if (port)
@@ -575,23 +597,26 @@ struct sockaddr_ns *sns;
 }
 
 char *
 }
 
 char *
-ns_phost(sns)
-struct sockaddr_ns *sns;
+ns_phost(sa)
+       struct sockaddr *sa;
 {
 {
+       register struct sockaddr_ns *sns = (struct sockaddr_ns *)sa;
        struct sockaddr_ns work;
        static union ns_net ns_zeronet;
        char *p;
        struct sockaddr_ns work;
        static union ns_net ns_zeronet;
        char *p;
-       
+
        work = *sns;
        work.sns_addr.x_port = 0;
        work.sns_addr.x_net = ns_zeronet;
 
        work = *sns;
        work.sns_addr.x_port = 0;
        work.sns_addr.x_net = ns_zeronet;
 
-       p = ns_print(&work);
+       p = ns_print((struct sockaddr *)&work);
        if (strncmp("0H.", p, 3) == 0) p += 3;
        return(p);
 }
        if (strncmp("0H.", p, 3) == 0) p += 3;
        return(p);
 }
+
+void
 upHex(p0)
 upHex(p0)
-char *p0;
+       char *p0;
 {
        register char *p = p0;
        for (; *p; p++) switch (*p) {
 {
        register char *p = p0;
        for (; *p; p++) switch (*p) {
index 8475b4a..9ff30eb 100644 (file)
@@ -6,78 +6,65 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)unix.c     5.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)unix.c     5.12 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
  * Display protocol blocks in the unix domain.
  */
 #endif /* not lint */
 
 /*
  * Display protocol blocks in the unix domain.
  */
+#include <kvm.h>
 #include <sys/param.h>
 #include <sys/protosw.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <sys/mbuf.h>
 #include <sys/param.h>
 #include <sys/protosw.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <sys/mbuf.h>
+#include <sys/kinfo.h>
 #include <sys/un.h>
 #include <sys/unpcb.h>
 #define KERNEL
 struct uio;
 #include <sys/un.h>
 #include <sys/unpcb.h>
 #define KERNEL
 struct uio;
+struct proc;
 #include <sys/file.h>
 #include <sys/file.h>
-struct file *file, *fileNFILE;
-int nfile;
+#include <stdlib.h>
+#include "netstat.h"
+
+static void unixdomainpr __P((struct socket *, caddr_t));
 
 
-int    Aflag;
-extern char *calloc();
+struct file *file, *fileNFILE;
+int nfiles;
+extern kvm_t *kvmd;
 
 
-unixpr(nfileaddr, fileaddr, unixsw)
-       off_t nfileaddr, fileaddr;
+void
+unixpr(unixsw)
        struct protosw *unixsw;
 {
        register struct file *fp;
        struct protosw *unixsw;
 {
        register struct file *fp;
-       struct file *filep;
        struct socket sock, *so = &sock;
        struct socket sock, *so = &sock;
+       char *filebuf;
 
 
-       if (nfileaddr == 0 || fileaddr == 0) {
-               printf("nfile or file not in namelist.\n");
-               return;
-       }
-       if (kvm_read(nfileaddr, (char *)&nfile, sizeof (nfile)) !=
-                                               sizeof (nfile)) {
-               printf("nfile: bad read.\n");
-               return;
-       }
-       if (kvm_read(fileaddr, (char *)&filep, sizeof (filep))
-                                               != sizeof (filep)) {
-               printf("File table address, bad read.\n");
-               return;
-       }
-       file = (struct file *)calloc(nfile, sizeof (struct file));
-       if (file == (struct file *)0) {
+       filebuf = (char *)kvm_getfiles(kvmd, KINFO_FILE, 0, &nfiles);
+       if (filebuf == 0) {
                printf("Out of memory (file table).\n");
                return;
        }
                printf("Out of memory (file table).\n");
                return;
        }
-       if (kvm_read((off_t)filep, (char *)file, nfile * sizeof (struct file))
-                                       != nfile * sizeof (struct file)) {
-               printf("File table read error.\n");
-               return;
-       }
-       fileNFILE = file + nfile;
+       file = (struct file *)(filebuf + sizeof(fp));
+       fileNFILE = file + nfiles;
        for (fp = file; fp < fileNFILE; fp++) {
                if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET)
                        continue;
        for (fp = file; fp < fileNFILE; fp++) {
                if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET)
                        continue;
-               if (kvm_read((off_t)fp->f_data, (char *)so, sizeof (*so))
-                                       != sizeof (*so))
+               if (kread((off_t)fp->f_data, (char *)so, sizeof (*so)))
                        continue;
                /* kludge */
                if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
                        if (so->so_pcb)
                                unixdomainpr(so, fp->f_data);
        }
                        continue;
                /* kludge */
                if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
                        if (so->so_pcb)
                                unixdomainpr(so, fp->f_data);
        }
-       free((char *)file);
 }
 
 static char *socktype[] =
     { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
 
 }
 
 static char *socktype[] =
     { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
 
+static void
 unixdomainpr(so, soaddr)
        register struct socket *so;
        caddr_t soaddr;
 unixdomainpr(so, soaddr)
        register struct socket *so;
        caddr_t soaddr;
@@ -87,13 +74,11 @@ unixdomainpr(so, soaddr)
        struct sockaddr_un *sa;
        static int first = 1;
 
        struct sockaddr_un *sa;
        static int first = 1;
 
-       if (kvm_read((off_t)so->so_pcb, (char *)unp, sizeof (*unp))
-                               != sizeof (*unp))
+       if (kread((off_t)so->so_pcb, (char *)unp, sizeof (*unp)))
                return;
        if (unp->unp_addr) {
                m = &mbuf;
                return;
        if (unp->unp_addr) {
                m = &mbuf;
-               if (kvm_read((off_t)unp->unp_addr, (char *)m, sizeof (*m))
-                               != sizeof (*m))
+               if (kread((off_t)unp->unp_addr, (char *)m, sizeof (*m)))
                        m = (struct mbuf *)0;
                sa = (struct sockaddr_un *)(m->m_dat);
        } else
                        m = (struct mbuf *)0;
                sa = (struct sockaddr_un *)(m->m_dat);
        } else