arp output formatting patch

Richard Moore rich at richud.com
Sat Oct 18 20:50:40 UTC 2014


Hi,

I found BB's arp default output not well aligned and rather hard to read 
for example with a mix of long and short hostnames.

I made this little patch (for my purposes on a wireless router) to make 
it look more like the 'default' aligned output style on my system (from 
net-tools). I have tried to alter as little original code as possible. 
Just thought I would post it in case it is of use to someone.

Cheers

Rich






--- a/busybox-1.22.1/networking/arp.c.orig    2014-01-09 
18:15:44.000000000 +0000
+++ b/busybox-1.22.1/networking/arp.c    2014-10-04 22:12:25.896657593 +0100
@@ -372,22 +372,25 @@
      if (xhw == NULL)
          xhw = get_hwtype(DFLT_HW);

-    printf("%s (%s) at ", name, ip);
+    printf("%-35s %-18s ", name, ip);

      if (!(arp_flags & ATF_COM)) {
          if (arp_flags & ATF_PUBL)
-            printf("* ");
+            printf("%-18s %-10s ", "*", "-");
          else
-            printf("<incomplete> ");
+            printf("%-18s %-10s ", "<incomplete>", "-");
      } else {
-        printf("%s [%s] ", hwa, xhw->name);
+        printf("%-18s %-10s ", hwa, xhw->name);
      }

-    if (arp_flags & ATF_NETMASK)
-        printf("netmask %s ", mask);
+    if (arp_flags & ATF_NETMASK) {
+        printf("%-18s ", mask);
+    } else {
+        printf("%-18s  ", "-");
+    }

      print_flags_separated(arp_masks, arp_labels, arp_flags, " ");
-    printf(" on %s\n", dev);
+    printf("%-5s\n", dev);
  }

  /* Display the contents of the ARP cache in the kernel. */
@@ -419,6 +422,9 @@
      /* Bypass header -- read one line */
      fgets(line, sizeof(line), fp);

+    /* Column headers. */
+    printf("%-35s %-18s %-18s %-10s %-18s %-5s\n", "Hostname", 
"IPaddress", "HWaddress", "HWType", "Mask", "Iface");
+
      /* Read the ARP cache entries. */
      while (fgets(line, sizeof(line), fp)) {

@@ -453,7 +459,7 @@
              else
                  hostname = ap->sprint(&sa, (option_mask32 & ARP_OPT_n) 
| 0x8000);
              if (strcmp(hostname, ip) == 0)
-                hostname = "?";
+                hostname = "<unknown>";
          }

          arp_disp(hostname, ip, type, flags, hwa, mask, dev);

-------------- next part --------------
A non-text attachment was scrubbed...
Name: busybox_networking_arp.c.patch
Type: text/x-patch
Size: 1512 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20141018/949f68bd/attachment.bin>


More information about the busybox mailing list