Here is a better patch for the netstat output. I haven't had time to
look at the kernel yet.
If this patch is good for you I'll commit it on -CURRENT. It cleans up
the group membership output significantly and displays the Link-layer
information separately.
If anyone 'out there' has been relying on this output in scripts, please
tell me.
BMS
--- mcast.c.orig Sat Feb 17 18:12:28 2007
+++ mcast.c Tue Feb 20 23:26:41 2007
@@ -71,21 +71,39 @@
#define MYIFNAME_SIZE 128
void
-ifmalist_dump(void)
+ifmalist_dump_af(struct ifmaddrs *ifmap, int af)
{
- struct ifmaddrs *ifmap, *ifma;
+ struct ifmaddrs *ifma;
sockunion_t *psa;
char myifname[MYIFNAME_SIZE];
char addrbuf[INET6_ADDRSTRLEN];
char *pcolon;
void *addr;
- char *pifname, *plladdr, *pgroup;
+ char *pafname, *pifname, *plladdr, *pgroup;
- if (getifmaddrs(&ifmap))
- err(EX_OSERR, "getifmaddrs");
+ if (!((af == AF_INET) || (af == AF_LINK)
+#ifdef INET6
+ || (af == AF_INET6)
+#endif
+ ))
+ return;
+
+ switch (af) {
+ case AF_INET:
+ pafname = "IPv4";
+ break;
+ case AF_INET6:
+ pafname = "IPv6";
+ break;
+ case AF_LINK:
+ pafname = "Link-layer";
+ break;
+ }
- fputs("IPv4/IPv6 Multicast Group Memberships\n", stdout);
- fprintf(stdout, "%-20s\t%-16s\t%s\n", "Group", "Gateway", "Netif");
+ fprintf(stdout, "%s Multicast Group Memberships\n", pafname);
+ fprintf(stdout, "%-20s\t%-16s\t%s\n", "Group",
+ "Next Hop/L2 Address",
+ "Netif");
for (ifma = ifmap; ifma; ifma = ifma->ifma_next) {
@@ -94,16 +112,32 @@
/* Group address */
psa = (sockunion_t *)ifma->ifma_addr;
+ if (psa->sa.sa_family != af)
+ continue;
switch (psa->sa.sa_family) {
case AF_INET:
pgroup = inet_ntoa(psa->sin.sin_addr);
break;
+#ifdef INET6
case AF_INET6:
addr = &psa->sin6.sin6_addr;
inet_ntop(psa->sa.sa_family, addr, addrbuf,
sizeof(addrbuf));
pgroup = addrbuf;
break;
+#endif
+ case AF_LINK:
+ if ((psa->sdl.sdl_alen == ETHER_ADDR_LEN) ||
+ (psa->sdl.sdl_type == IFT_ETHER)) {
+ pgroup =
+ether_ntoa((struct ether_addr *)&psa->sdl.sdl_data);
+ } else {
+ pgroup = addr2ascii(AF_LINK,
+ &psa->sdl,
+ sizeof(struct sockaddr_dl),
+ addrbuf);
+ }
+ break;
default:
continue; /* XXX */
}
@@ -116,14 +150,20 @@
plladdr = inet_ntoa(psa->sin.sin_addr);
break;
case AF_LINK:
- if (psa->sdl.sdl_type == IFT_ETHER)
- plladdr = ether_ntoa((struct ether_addr *)&psa->sdl.sdl_data);
- else
- plladdr = link_ntoa(&psa->sdl);
+ if (psa->sdl.sdl_type == IFT_ETHER) {
+ plladdr =
+ether_ntoa((struct ether_addr *)&psa->sdl.sdl_data);
+ } else {
+ plladdr = addr2ascii(AF_LINK,
+ &psa->sdl,
+ sizeof(struct sockaddr_dl),
+ addrbuf);
+ }
break;
}
- } else
+ } else {
plladdr = "<none>";
+ }
/* Interface upon which the membership exists */
psa = (sockunion_t *)ifma->ifma_name;
@@ -143,6 +183,23 @@
fprintf(stdout, "%-20s\t%-16s\t%s\n", pgroup, plladdr, pifname);
}
+}
+
+void
+ifmalist_dump(void)
+{
+ struct ifmaddrs *ifmap;
+
+ if (getifmaddrs(&ifmap))
+ err(EX_OSERR, "getifmaddrs");
+
+ ifmalist_dump_af(ifmap, AF_LINK);
+ fputs("\n", stdout);
+ ifmalist_dump_af(ifmap, AF_INET);
+ fputs("\n", stdout);
+#ifdef INET6
+ ifmalist_dump_af(ifmap, AF_INET6);
+#endif
freeifmaddrs(ifmap);
}
_______________________________________________
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "[EMAIL PROTECTED]"