[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    arp output formatting patch
From:       Richard Moore <rich () richud ! com>
Date:       2014-10-18 20:50:40
Message-ID: 5442D2A0.3080704 () richud ! com
[Download RAW message or body]

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);


["busybox_networking_arp.c.patch" (text/x-patch)]

--- 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);



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic