BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.sbin / arp / arp.c
index 4fef575..8529b77 100644 (file)
@@ -5,19 +5,33 @@
  * This code is derived from software contributed to Berkeley by
  * Sun Microsystems, Inc.
  *
  * This code is derived from software contributed to Berkeley by
  * Sun Microsystems, Inc.
  *
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement:  ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -27,17 +41,14 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)arp.c      5.11 (Berkeley) 6/1/90";
+static char sccsid[] = "@(#)arp.c      5.11.1.1 (Berkeley) 7/22/91";
 #endif /* not lint */
 
 /*
  * arp - display, set, and delete arp table entries
  */
 
 #endif /* not lint */
 
 /*
  * arp - display, set, and delete arp table entries
  */
 
-#include <machine/pte.h>
-
 #include <sys/param.h>
 #include <sys/param.h>
-#include <sys/vmmac.h>
 #include <sys/file.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/file.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
@@ -49,11 +60,11 @@ static char sccsid[] = "@(#)arp.c   5.11 (Berkeley) 6/1/90";
 
 #include <errno.h>
 #include <nlist.h>
 
 #include <errno.h>
 #include <nlist.h>
+#include <kvm.h>
 #include <stdio.h>
 #include <paths.h>
 
 extern int errno;
 #include <stdio.h>
 #include <paths.h>
 
 extern int errno;
-static int kflag;
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -64,16 +75,13 @@ main(argc, argv)
        while ((ch = getopt(argc, argv, "adsf")) != EOF)
                switch((char)ch) {
                case 'a': {
        while ((ch = getopt(argc, argv, "adsf")) != EOF)
                switch((char)ch) {
                case 'a': {
-                       char *mem;
+                       char *mem = 0;
 
                        if (argc > 4)
                                usage();
                        if (argc == 4) {
 
                        if (argc > 4)
                                usage();
                        if (argc == 4) {
-                               kflag = 1;
                                mem = argv[3];
                        }
                                mem = argv[3];
                        }
-                       else
-                               mem = _PATH_KMEM;
                        dump((argc >= 3) ? argv[2] : _PATH_UNIX, mem);
                        exit(0);
                }
                        dump((argc >= 3) ? argv[2] : _PATH_UNIX, mem);
                        exit(0);
                }
@@ -294,15 +302,9 @@ struct nlist nl[] = {
        { "_arptab" },
 #define        X_ARPTAB_SIZE   1
        { "_arptab_size" },
        { "_arptab" },
 #define        X_ARPTAB_SIZE   1
        { "_arptab_size" },
-#define        N_SYSMAP        2
-       { "_Sysmap" },
-#define        N_SYSSIZE       3
-       { "_Syssize" },
        { "" },
 };
 
        { "" },
 };
 
-static struct pte *Sysmap;
-
 /*
  * Dump the entire arp table
  */
 /*
  * Dump the entire arp table
  */
@@ -316,32 +318,17 @@ dump(kernel, mem)
        char *host, *malloc();
        off_t lseek();
 
        char *host, *malloc();
        off_t lseek();
 
-       if (nlist(kernel, nl) < 0 || nl[X_ARPTAB_SIZE].n_type == 0) {
-               fprintf(stderr, "arp: %s: bad namelist\n", kernel);
+       if (kvm_openfiles(kernel, mem, NULL) == -1) {
+               fprintf(stderr, "arp: kvm_openfiles: %s\n", kvm_geterr());
                exit(1);
        }
                exit(1);
        }
-       mf = open(mem, O_RDONLY);
-       if (mf < 0) {
-               fprintf(stderr, "arp: cannot open %s\n", mem);
+       if (kvm_nlist(nl) < 0 || nl[X_ARPTAB_SIZE].n_type == 0) {
+               fprintf(stderr, "arp: %s: bad namelist\n", kernel);
                exit(1);
        }
                exit(1);
        }
-       if (kflag) {
-               off_t off;
-
-               Sysmap = (struct pte *)
-                  malloc((u_int)(nl[N_SYSSIZE].n_value * sizeof(struct pte)));
-               if (!Sysmap) {
-                       fputs("arp: can't get memory for Sysmap.\n", stderr);
-                       exit(1);
-               }
-               off = nl[N_SYSMAP].n_value & ~KERNBASE;
-               (void)lseek(mf, off, L_SET);
-               (void)read(mf, (char *)Sysmap,
-                   (int)(nl[N_SYSSIZE].n_value * sizeof(struct pte)));
-       }
-       klseek(mf, (long)nl[X_ARPTAB_SIZE].n_value, L_SET);
-       read(mf, &arptab_size, sizeof arptab_size);
-       if (arptab_size <= 0 || arptab_size > 1000) {
+       if (kvm_read((void *)(nl[X_ARPTAB_SIZE].n_value),
+                    &arptab_size, sizeof arptab_size) == -1 ||
+           arptab_size <= 0 || arptab_size > 1000) {
                fprintf(stderr, "arp: %s: namelist wrong\n", kernel);
                exit(1);
        }
                fprintf(stderr, "arp: %s: namelist wrong\n", kernel);
                exit(1);
        }
@@ -351,12 +338,10 @@ dump(kernel, mem)
                fputs("arp: can't get memory for arptab.\n", stderr);
                exit(1);
        }
                fputs("arp: can't get memory for arptab.\n", stderr);
                exit(1);
        }
-       klseek(mf, (long)nl[X_ARPTAB].n_value, L_SET);
-       if (read(mf, (char *)at, sz) != sz) {
+       if (kvm_read((void *)(nl[X_ARPTAB].n_value), (char *)at, sz) == -1) {
                perror("arp: error reading arptab");
                exit(1);
        }
                perror("arp: error reading arptab");
                exit(1);
        }
-       close(mf);
        for (bynumber = 0; arptab_size-- > 0; at++) {
                if (at->at_iaddr.s_addr == 0 || at->at_flags == 0)
                        continue;
        for (bynumber = 0; arptab_size-- > 0; at++) {
                if (at->at_iaddr.s_addr == 0 || at->at_flags == 0)
                        continue;
@@ -387,22 +372,6 @@ dump(kernel, mem)
        }
 }
 
        }
 }
 
-/*
- * Seek into the kernel for a value.
- */
-klseek(fd, base, off)
-       int fd, off;
-       off_t base;
-{
-       off_t lseek();
-
-       if (kflag) {    /* get kernel pte */
-               base &= ~KERNBASE;
-               base = ctob(Sysmap[btop(base)].pg_pfnum) + (base & PGOFSET);
-       }
-       (void)lseek(fd, base, off);
-}
-
 ether_print(cp)
        u_char *cp;
 {
 ether_print(cp)
        u_char *cp;
 {