Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Output format improvment for ifconfig(8)



Some time ago, I created the snprintb_m(3) to print bit field values across multiple output lines, rather than on a single, potentially very long line, and cpuctl(8) (for i386/amd64) was modified to use this for the multiple CPU features lines.

I'd like to make similar changes to ifconfig(8) for the capabilities, enabled, and flags field.

The following diffs shows how the output would change. (I am certain that my mailer will screw up the presentation of the long lines, so I have also attached the diffs!) The code changes are also attached.

Any objections or suggestions?


--- ifconfig.out.old    2012-10-31 16:20:21.000000000 -0700
+++ ifconfig.out.new    2012-10-31 16:20:58.000000000 -0700
@@ -1,6 +1,10 @@
 wm0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
-       
capabilities=7ff80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Rx,TCP6CSUM_Tx,UDP6CSUM_Rx,UDP6CSUM_Tx,TSO6>
-       
enabled=7ff80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Rx,TCP6CSUM_Tx,UDP6CSUM_Rx,UDP6CSUM_Tx,TSO6>
+       capable=7ff80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx>
+       capable=7ff80<UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Rx,TCP6CSUM_Tx>
+       capable=7ff80<UDP6CSUM_Rx,UDP6CSUM_Tx,TSO6>
+       enabled=7ff80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx>
+       enabled=7ff80<UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Rx,TCP6CSUM_Tx>
+       enabled=7ff80<UDP6CSUM_Rx,UDP6CSUM_Tx,TSO6>
        address: bc:ae:c5:30:d9:8a
        media: Ethernet autoselect (1000baseT 
full-duplex,flowcontrol,rxpause,txpause)
        status: active


-------------------------------------------------------------------------
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:       |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com    |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |                          | pgoyette at netbsd.org  |
-------------------------------------------------------------------------
--- ifconfig.out.old    2012-10-31 16:20:21.000000000 -0700
+++ ifconfig.out.new    2012-10-31 16:20:58.000000000 -0700
@@ -1,6 +1,10 @@
 wm0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
-       
capabilities=7ff80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Rx,TCP6CSUM_Tx,UDP6CSUM_Rx,UDP6CSUM_Tx,TSO6>
-       
enabled=7ff80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Rx,TCP6CSUM_Tx,UDP6CSUM_Rx,UDP6CSUM_Tx,TSO6>
+       capable=7ff80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx>
+       capable=7ff80<UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Rx,TCP6CSUM_Tx>
+       capable=7ff80<UDP6CSUM_Rx,UDP6CSUM_Tx,TSO6>
+       enabled=7ff80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx>
+       enabled=7ff80<UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Rx,TCP6CSUM_Tx>
+       enabled=7ff80<UDP6CSUM_Rx,UDP6CSUM_Tx,TSO6>
        address: bc:ae:c5:30:d9:8a
        media: Ethernet autoselect (1000baseT 
full-duplex,flowcontrol,rxpause,txpause)
        status: active
Index: ifconfig.c
===================================================================
RCS file: /cvsroot/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.227
diff -u -p -r1.227 ifconfig.c
--- ifconfig.c  28 Jan 2012 15:01:44 -0000      1.227
+++ ifconfig.c  31 Oct 2012 23:20:01 -0000
@@ -1163,6 +1163,9 @@ print_human_bytes(bool humanize, uint64_
  * Print the status of the interface.  If an address family was
  * specified, show it and it only; otherwise, show them all.
  */
+
+#define MAX_PRINT_LEN 60       /* XXX need a better way to determine this! */
+
 void
 status(const struct sockaddr *sdl, prop_dictionary_t env,
     prop_dictionary_t oenv)
@@ -1174,6 +1177,7 @@ status(const struct sockaddr *sdl, prop_
        struct ifreq ifr;
        struct ifdrv ifdrv;
        char fbuf[BUFSIZ];
+       char *bp;
        int af, s;
        const char *ifname;
        struct ifcapreq ifcr;
@@ -1193,8 +1197,12 @@ status(const struct sockaddr *sdl, prop_
        if ((ifname = getifinfo(env, oenv, &flags)) == NULL)
                err(EXIT_FAILURE, "%s: getifinfo", __func__);
 
-       (void)snprintb(fbuf, sizeof(fbuf), IFFBITS, flags);
-       printf("%s: flags=%s", ifname, &fbuf[2]);
+       (void)snprintb_m(fbuf, sizeof(fbuf), IFFBITS, flags, MAX_PRINT_LEN);
+       bp = fbuf;
+       while (*bp != '\0') {
+               printf("%s: flags=%s", ifname, &bp[2]);
+               bp += strlen(bp) + 1;
+       }
 
        estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
        if (prog_ioctl(s, SIOCGIFMETRIC, &ifr) == -1)
@@ -1211,12 +1219,20 @@ status(const struct sockaddr *sdl, prop_
                err(EXIT_FAILURE, "%s: getifcaps", __func__);
 
        if (ifcr.ifcr_capabilities != 0) {
-               (void)snprintb(fbuf, sizeof(fbuf), IFCAPBITS,
-                   ifcr.ifcr_capabilities);
-               printf("\tcapabilities=%s\n", &fbuf[2]);
-               (void)snprintb(fbuf, sizeof(fbuf), IFCAPBITS,
-                   ifcr.ifcr_capenable);
-               printf("\tenabled=%s\n", &fbuf[2]);
+               (void)snprintb_m(fbuf, sizeof(fbuf), IFCAPBITS,
+                   ifcr.ifcr_capabilities, MAX_PRINT_LEN);
+               bp = fbuf;
+               while (*bp != '\0') {
+                       printf("\tcapable=%s\n", &bp[2]);
+                       bp += strlen(bp) + 1;
+               }
+               (void)snprintb_m(fbuf, sizeof(fbuf), IFCAPBITS,
+                   ifcr.ifcr_capenable, MAX_PRINT_LEN);
+               bp = fbuf;
+               while (*bp != '\0') {
+                       printf("\tenabled=%s\n", &bp[2]);
+                       bp += strlen(bp) + 1;
+               }
        }
 
        SIMPLEQ_FOREACH(status_f, &status_funcs, f_next)


Home | Main Index | Thread Index | Old Index