BSD 4_4_Lite1 release
[unix-history] / usr / src / usr.sbin / arp / arp.c
index 11bbd04..2182dc8 100644 (file)
@@ -1,31 +1,58 @@
 /*
 /*
- * Copyright (c) 1984 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1984, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * 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.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1984 Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1984, 1993\n\
      The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)arp.c      5.16 (Berkeley) %G%";
+static char sccsid[] = "@(#)arp.c      8.2 (Berkeley) 1/2/94";
 #endif /* not lint */
 
 /*
  * arp - display, set, and delete arp table entries
  */
 
 #endif /* not lint */
 
 /*
  * arp - display, set, and delete arp table entries
  */
 
+
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/socket.h>
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/socket.h>
-#include <sys/kinfo.h>
+#include <sys/sysctl.h>
 
 #include <net/if.h>
 #include <net/if_dl.h>
 
 #include <net/if.h>
 #include <net/if_dl.h>
@@ -40,12 +67,12 @@ static char sccsid[] = "@(#)arp.c   5.16 (Berkeley) %G%";
 #include <netdb.h>
 #include <errno.h>
 #include <nlist.h>
 #include <netdb.h>
 #include <errno.h>
 #include <nlist.h>
-#include <kvm.h>
 #include <stdio.h>
 #include <paths.h>
 
 extern int errno;
 static int pid;
 #include <stdio.h>
 #include <paths.h>
 
 extern int errno;
 static int pid;
+static int kflag;
 static int nflag;
 static int s = -1;
 
 static int nflag;
 static int s = -1;
 
@@ -317,8 +344,8 @@ delete:
 dump(addr)
 u_long addr;
 {
 dump(addr)
 u_long addr;
 {
-       int sz, needed, rlen;
-       long op = KINFO_RT_FLAGS | (((long)AF_INET) << 16);
+       int mib[6];
+       size_t needed;
        char *host, *malloc(), *lim, *buf, *next;
        struct rt_msghdr *rtm;
        struct sockaddr_inarp *sin;
        char *host, *malloc(), *lim, *buf, *next;
        struct rt_msghdr *rtm;
        struct sockaddr_inarp *sin;
@@ -326,6 +353,28 @@ u_long addr;
        extern int h_errno;
        struct hostent *hp;
 
        extern int h_errno;
        struct hostent *hp;
 
+       mib[0] = CTL_NET;
+       mib[1] = PF_ROUTE;
+       mib[2] = 0;
+       mib[3] = AF_INET;
+       mib[4] = NET_RT_FLAGS;
+       mib[5] = RTF_LLINFO;
+       if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
+               quit("route-sysctl-estimate");
+       if ((buf = malloc(needed)) == NULL)
+               quit("malloc");
+       if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+               quit("actual retrieval of routing table");
+       lim = buf + needed;
+       for (next = buf; next < lim; next += rtm->rtm_msglen) {
+               rtm = (struct rt_msghdr *)next;
+               sin = (struct sockaddr_inarp *)(rtm + 1);
+               sdl = (struct sockaddr_dl *)(sin + 1);
+               if (addr) {
+                       if (addr != sin->sin_addr.s_addr)
+                               continue;
+                       found_entry = 1;
+               }
                if (nflag == 0)
                        hp = gethostbyaddr((caddr_t)&(sin->sin_addr),
                            sizeof sin->sin_addr, AF_INET);
                if (nflag == 0)
                        hp = gethostbyaddr((caddr_t)&(sin->sin_addr),
                            sizeof sin->sin_addr, AF_INET);
@@ -357,6 +406,8 @@ u_long addr;
                }
                printf("\n");
        }
                }
                printf("\n");
        }
+}
+
 ether_print(cp)
        u_char *cp;
 {
 ether_print(cp)
        u_char *cp;
 {
@@ -423,6 +474,7 @@ rtmsg(cmd)
                                rtm->rtm_flags &= ~RTF_HOST;
                        }
                }
                                rtm->rtm_flags &= ~RTF_HOST;
                        }
                }
+               /* FALLTHROUGH */
        case RTM_GET:
                rtm->rtm_addrs |= RTA_DST;
        }
        case RTM_GET:
                rtm->rtm_addrs |= RTA_DST;
        }