Module Name: src
Committed By: pgoyette
Date: Thu Nov 1 13:43:23 UTC 2012
Modified Files:
src/sbin/ifconfig: ether.c ifconfig.c
Log Message:
Use snprintb_m(3) to split flags/capabilities/enabled across multiple
output lines.
As discussed on current-users
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sbin/ifconfig/ether.c
cvs rdiff -u -r1.227 -r1.228 src/sbin/ifconfig/ifconfig.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/ifconfig/ether.c
diff -u src/sbin/ifconfig/ether.c:1.1 src/sbin/ifconfig/ether.c:1.2
--- src/sbin/ifconfig/ether.c:1.1 Wed Oct 31 10:17:34 2012
+++ src/sbin/ifconfig/ether.c Thu Nov 1 13:43:23 2012
@@ -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 void ether_constructor(void) __at
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 @@ ether_status(prop_dictionary_t env, prop
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;
+ }
}
}
Index: src/sbin/ifconfig/ifconfig.c
diff -u src/sbin/ifconfig/ifconfig.c:1.227 src/sbin/ifconfig/ifconfig.c:1.228
--- src/sbin/ifconfig/ifconfig.c:1.227 Sat Jan 28 15:01:44 2012
+++ src/sbin/ifconfig/ifconfig.c Thu Nov 1 13:43:23 2012
@@ -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_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 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 @@ 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("\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)