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.
This commit is contained in:
parent
a94a205118
commit
26e6c607e9
@ -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.
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||||
@ -29,7 +29,7 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#include <sys/cdefs.h>
|
#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 <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -79,18 +79,28 @@ inet6_n2a(void *p)
|
|||||||
return "(invalid)";
|
return "(invalid)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
check_inet6_availability(void)
|
||||||
|
{
|
||||||
|
size_t dummy;
|
||||||
|
|
||||||
|
return sysctlnametomib("net.inet6.multicast", NULL, &dummy) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
struct if_nameindex *ifps;
|
struct if_nameindex *ifps;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
bool inet6_available = check_inet6_availability();
|
||||||
|
|
||||||
ifps = if_nameindex();
|
ifps = if_nameindex();
|
||||||
if (ifps == NULL)
|
if (ifps == NULL)
|
||||||
errx(1, "failed to obtain list of interfaces");
|
errx(1, "failed to obtain list of interfaces");
|
||||||
|
|
||||||
for (i = 0; ifps[i].if_name != NULL; ++i) {
|
for (i = 0; ifps[i].if_name != NULL; ++i) {
|
||||||
printf("%s:\n", ifps[i].if_name);
|
printf("%s:\n", ifps[i].if_name);
|
||||||
|
if (inet6_available)
|
||||||
print_inet6_mcast(ifps[i].if_index, ifps[i].if_name);
|
print_inet6_mcast(ifps[i].if_index, ifps[i].if_name);
|
||||||
print_ether_mcast(ifps[i].if_index);
|
print_ether_mcast(ifps[i].if_index);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user