Source-Changes-HG archive

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

[src/trunk]: src/sbin/ifconfig Use snprintb_m(3) to split flags/capabilities/...



details:   https://anonhg.NetBSD.org/src/rev/f42896ed0f23
branches:  trunk
changeset: 782388:f42896ed0f23
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Thu Nov 01 13:43:23 2012 +0000

description:
Use snprintb_m(3) to split flags/capabilities/enabled across multiple
output lines.

As discussed on current-users

diffstat:

 sbin/ifconfig/ether.c    |  27 +++++++++++++++++++--------
 sbin/ifconfig/ifconfig.c |  36 ++++++++++++++++++++++++++----------
 2 files changed, 45 insertions(+), 18 deletions(-)

diffs (138 lines):

diff -r 174ae319b429 -r f42896ed0f23 sbin/ifconfig/ether.c
--- a/sbin/ifconfig/ether.c     Thu Nov 01 11:33:34 2012 +0000
+++ b/sbin/ifconfig/ether.c     Thu Nov 01 13:43:23 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ether.c,v 1.1 2012/10/31 10:17:34 msaitoh Exp $        */
+/*     $NetBSD: ether.c,v 1.2 2012/11/01 13:43:23 pgoyette Exp $       */
 
 /*
  * Copyright (c) 1983, 1993
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ether.c,v 1.1 2012/10/31 10:17:34 msaitoh Exp $");
+__RCSID("$NetBSD: ether.c,v 1.2 2012/11/01 13:43:23 pgoyette Exp $");
 #endif /* not lint */
 
 #include <sys/param.h> 
@@ -58,11 +58,14 @@
 
 static status_func_t status;
 
+#define MAX_PRINT_LEN 55
+
 void
 ether_status(prop_dictionary_t env, prop_dictionary_t oenv)
 {
        struct eccapreq eccr;
        char fbuf[BUFSIZ];
+       char *bp;
 
        memset(&eccr, 0, sizeof(eccr));
 
@@ -70,12 +73,20 @@
                return;
 
        if (eccr.eccr_capabilities != 0) {
-               (void)snprintb(fbuf, sizeof(fbuf), ECCAPBITS,
-                   eccr.eccr_capabilities);
-               printf("\tec_capabilities=%s\n", &fbuf[2]);
-               (void)snprintb(fbuf, sizeof(fbuf), ECCAPBITS,
-                   eccr.eccr_capenable);
-               printf("\tec_enabled=%s\n", &fbuf[2]);
+               (void)snprintb_m(fbuf, sizeof(fbuf), ECCAPBITS,
+                   eccr.eccr_capabilities, MAX_PRINT_LEN);
+               bp = fbuf;
+               while (*bp != '\0') {
+                       printf("\tec_capabilities=%s\n", &bp[2]);
+                       bp += strlen(bp) + 1;
+               }
+               (void)snprintb_m(fbuf, sizeof(fbuf), ECCAPBITS,
+                   eccr.eccr_capenable, MAX_PRINT_LEN);
+               bp = fbuf;
+               while (*bp != '\0') {
+                       printf("\tec_enabled=%s\n", &bp[2]);
+                       bp += strlen(bp) + 1;
+               }
        }
 }
 
diff -r 174ae319b429 -r f42896ed0f23 sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c  Thu Nov 01 11:33:34 2012 +0000
+++ b/sbin/ifconfig/ifconfig.c  Thu Nov 01 13:43:23 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ifconfig.c,v 1.227 2012/01/28 15:01:44 mbalmer Exp $   */
+/*     $NetBSD: ifconfig.c,v 1.228 2012/11/01 13:43:23 pgoyette Exp $  */
 
 /*-
  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1983, 1993\
  The Regents of the University of California.  All rights reserved.");
-__RCSID("$NetBSD: ifconfig.c,v 1.227 2012/01/28 15:01:44 mbalmer Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.228 2012/11/01 13:43:23 pgoyette Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -1163,6 +1163,9 @@
  * 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 58       /* 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 @@
        struct ifreq ifr;
        struct ifdrv ifdrv;
        char fbuf[BUFSIZ];
+       char *bp;
        int af, s;
        const char *ifname;
        struct ifcapreq ifcr;
@@ -1193,8 +1197,12 @@
        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 @@
                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("\tcapabilities=%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