[OpenWrt-Devel] [PATCH] busybox: support output new-linux model for arp

daxiong lxliu at ikuai8.com
Mon Nov 4 04:06:00 EST 2019


Compatible with the output of net-tools.
Using new-linux model by default.

arp -n:
  Address                  HWtype  HWaddress           Flags Mask            Iface
  192.168.1.1              ether   00:11:22:33:44:55   C                     eth1

arp -an:
  ? (192.168.1.1) at 00:11:22:33:44:55 [ether]  on eth1

Signed-off-by: daxiong <lxliu at ikuai8.com>
---
 .../patches/540-arpshow-support-new-linux.patch    | 94 ++++++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 package/utils/busybox/patches/540-arpshow-support-new-linux.patch

diff --git a/package/utils/busybox/patches/540-arpshow-support-new-linux.patch b/package/utils/busybox/patches/540-arpshow-support-new-linux.patch
new file mode 100644
index 0000000..1bb6629
--- /dev/null
+++ b/package/utils/busybox/patches/540-arpshow-support-new-linux.patch
@@ -0,0 +1,94 @@
+--- a/networking/arp.c	2019-11-04 15:42:52.171010629 +0800
++++ b/networking/arp.c	2019-11-04 16:39:46.455539779 +0800
+@@ -353,6 +353,56 @@ static int arp_set(char **args)
+ 
+ 
+ /* Print the contents of an ARP request block. */
++static void arp_disp_2(char *name, int type, int arp_flags, char *hwa, char *mask, char *dev)
++{
++    static int title = 0;
++    const struct hwtype *xhw;
++    char flags[10];
++
++    xhw = get_hwntype(type);
++    if (xhw == NULL)
++	xhw = get_hwtype(DFLT_HW);
++
++    if (title++ == 0) {
++	printf("Address                  HWtype  HWaddress           Flags Mask            Iface\n");
++    }
++    /* Setup the flags. */
++    flags[0] = '\0';
++    if (arp_flags & ATF_COM)
++	strcat(flags, "C");
++    if (arp_flags & ATF_PERM)
++	strcat(flags, "M");
++    if (arp_flags & ATF_PUBL)
++	strcat(flags, "P");
++#ifdef HAVE_ATF_MAGIC
++    if (arp_flags & ATF_MAGIC)
++	strcat(flags, "A");
++#endif
++#ifdef HAVE_ATF_DONTPUB
++    if (arp_flags & ATF_DONTPUB)
++	strcat(flags, "!");
++#endif
++    if (arp_flags & ATF_USETRAILERS)
++	strcat(flags, "T");
++
++    if (!(arp_flags & ATF_NETMASK))
++	mask = (char *)"";
++
++    printf("%-23.23s  ", name);
++
++    if (!(arp_flags & ATF_COM)) {
++	if (arp_flags & ATF_PUBL)
++	    printf("%-8.8s%-20.20s", "*", "*");
++	else
++	    printf("%-8.8s%-20.20s", "", "(incomplete)");
++    } else {
++	printf("%-8.8s%-20.20s", xhw->name, hwa);
++    }
++
++    printf("%-6.6s%-15.15s %s\n", flags, mask, dev);
++}
++
++/* Print the contents of an ARP request block. */
+ static void
+ arp_disp(const char *name, char *ip, int type, int arp_flags,
+ 		char *hwa, char *mask, char *dev)
+@@ -457,18 +507,25 @@ static int arp_show(char *name)
+ 
+ 		shown++;
+ 		/* This IS ugly but it works -be */
+-		hostname = "?";
+-		if (!(option_mask32 & ARP_OPT_n)) {
+-			if (ap->input(ip, &sa) < 0)
+-				hostname = ip;
+-			else
+-				hostname = ap->sprint(&sa, (option_mask32 & ARP_OPT_n) | 0x8000);
+-			if (strcmp(hostname, ip) == 0)
+-				hostname = "?";
++		if (option_mask32 & ARP_OPT_n) {
++			hostname = "?";
++		} else {
++			if (!(option_mask32 & ARP_OPT_n)) {
++				if (ap->input(ip, &sa) < 0)
++					hostname = ip;
++				else
++					hostname = ap->sprint(&sa, (option_mask32 & ARP_OPT_n) | 0x8000);
++				if (strcmp(hostname, ip) == 0)
++					hostname = "?";
++			}
+ 		}
+ 
+-		arp_disp(hostname, ip, type, flags, hwa, mask, dev);
++		if (option_mask32 & ARP_OPT_a)
++			arp_disp(hostname, ip, type, flags, hwa, mask, dev);
++		else
++			arp_disp_2((char *)(hostname[0] == '?' ? ip : hostname), type, flags, hwa, mask, dev);
+ 	}
++
+ 	if (option_mask32 & ARP_OPT_v)
+ 		printf("Entries: %u\tSkipped: %u\tFound: %u\n",
+ 				entries, entries - shown, shown);
-- 
1.9.1





_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list