Date: Tue, 20 Feb 2007 23:38:14 +0000 From: "Bruce M. Simpson" <bms@FreeBSD.org> To: Jouke Witteveen <j.witteveen@gmail.com> Cc: freebsd-net@freebsd.org Subject: Re: ioctl: SIOCADDMULTI (howto?) Message-ID: <45DB8666.7060804@FreeBSD.org> In-Reply-To: <3993a4980702170546t7f9384eaq358986a4cc734582@mail.gmail.com> References: <3993a4980702051233u10c30575kd1f6d27fcd600110@mail.gmail.com> <45C7A1F9.20306@FreeBSD.org> <3993a4980702170546t7f9384eaq358986a4cc734582@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------010709030902010104020002 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------010709030902010104020002 Content-Type: text/x-patch; name="netstat-mcast.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="netstat-mcast.diff" --- 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); } --------------010709030902010104020002--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45DB8666.7060804>