Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/ifmcstat Don't give up just because inet6 sysctl kn...



details:   https://anonhg.NetBSD.org/src/rev/0ab7c82f588d
branches:  trunk
changeset: 820451:0ab7c82f588d
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Tue Jan 10 05:43:27 2017 +0000

description:
Don't give up just because inet6 sysctl knobs aren't available

It can happen normally, for example run a kernel without INET6 or
run a rump_server without librumpnet_netinet6.so.

diffstat:

 usr.sbin/ifmcstat/ifmcstat.c |  18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diffs (50 lines):

diff -r 6751edd57368 -r 0ab7c82f588d usr.sbin/ifmcstat/ifmcstat.c
--- a/usr.sbin/ifmcstat/ifmcstat.c      Tue Jan 10 05:42:34 2017 +0000
+++ b/usr.sbin/ifmcstat/ifmcstat.c      Tue Jan 10 05:43:27 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ifmcstat.c,v 1.19 2014/06/13 16:04:41 joerg Exp $      */
+/*     $NetBSD: ifmcstat.c,v 1.20 2017/01/10 05:43:27 ozaki-r Exp $    */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -29,7 +29,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: ifmcstat.c,v 1.19 2014/06/13 16:04:41 joerg Exp $");
+__RCSID("$NetBSD: ifmcstat.c,v 1.20 2017/01/10 05:43:27 ozaki-r Exp $");
 
 #include <err.h>
 #include <errno.h>
@@ -79,19 +79,29 @@
                return "(invalid)";
 }
 
+static bool
+check_inet6_availability(void)
+{
+       size_t dummy;
+       
+       return sysctlnametomib("net.inet6.multicast", NULL, &dummy) == 0;
+}
+
 int
 main(void)
 {
        struct if_nameindex  *ifps;
        size_t i;
-
+       bool inet6_available = check_inet6_availability();
 
        ifps = if_nameindex();
        if (ifps == NULL)
                errx(1, "failed to obtain list of interfaces");
+
        for (i = 0; ifps[i].if_name != NULL; ++i) {
                printf("%s:\n", ifps[i].if_name);
-               print_inet6_mcast(ifps[i].if_index, ifps[i].if_name);
+               if (inet6_available)
+                       print_inet6_mcast(ifps[i].if_index, ifps[i].if_name);
                print_ether_mcast(ifps[i].if_index);
        }
        if_freenameindex(ifps);



Home | Main Index | Thread Index | Old Index