/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: ifmcstat.c,v 1.22 2020/03/03 08:56:05 nisimura Exp $");
static void
print_ether_mcast(u_short ifindex)
{
static int ems_oids[4], sdl_oids[3];
size_t i, ems_len, sdl_len;
void *hwaddr;
struct ether_multi_sysctl *ems;
if (ems_oids[0] == 0) {
size_t oidlen = __arraycount(ems_oids);
if (sysctlnametomib("net.ether.multicast", ems_oids, &oidlen) == -1)
errx(1, "net.ether.multicast not found");
if (oidlen != 3)
errx(1, "Wrong OID path for net.ether.multicast");
}
if (sdl_oids[0] == 0) {
size_t oidlen = __arraycount(sdl_oids);
if (sysctlnametomib("net.sdl", sdl_oids, &oidlen) == -1)
errx(1, "net.sdl not found");
if (oidlen != 2)
errx(1, "Wrong OID path for net.sdl");
}
if (mcast_oids[0] == 0) {
size_t oidlen = __arraycount(mcast_oids);
if (sysctlnametomib("net.inet6.multicast", mcast_oids,
&oidlen) == -1)
errx(1, "net.inet6.multicast not found");
if (oidlen != 3)
errx(1, "Wrong OID path for net.inet6.multicast");
}
mcast_oids[3] = ifindex;
mcast_addrs = asysctl(mcast_oids, 4, &len);
if (mcast_addrs == NULL && len != 0) {
warn("failed to read net.inet6.multicast");
return;
}
if (len) {
p = mcast_addrs;
last_p = NULL;
while (len >= 2 * sizeof(struct in6_addr) + sizeof(uint32_t)) {
if (last_p == NULL ||
memcmp(p, last_p, sizeof(struct in6_addr)))
printf("\tinet6 %s\n", inet6_n2a(p));
last_p = p;
p += sizeof(struct in6_addr);
addr = inet6_n2a(p);
p += sizeof(struct in6_addr);
memcpy(&refcnt, p, sizeof(refcnt));
p += sizeof(refcnt);
printf("\t\tgroup %s refcount %" PRIu32 "\n", addr,
refcnt);
len -= 2 * sizeof(struct in6_addr) + sizeof(uint32_t);
}
}
free(mcast_addrs);
}