diff options
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ifmcstat/ifmcstat.8 | 67 | ||||
-rw-r--r-- | usr.sbin/ifmcstat/ifmcstat.c | 44 |
2 files changed, 70 insertions, 41 deletions
diff --git a/usr.sbin/ifmcstat/ifmcstat.8 b/usr.sbin/ifmcstat/ifmcstat.8 index d9f0ab1a9eb..c472e82b0c2 100644 --- a/usr.sbin/ifmcstat/ifmcstat.8 +++ b/usr.sbin/ifmcstat/ifmcstat.8 @@ -1,18 +1,33 @@ -.\" $OpenBSD: ifmcstat.8,v 1.7 2001/07/20 19:09:47 mpech Exp $ +.\" $OpenBSD: ifmcstat.8,v 1.8 2001/11/16 04:46:54 itojun Exp $ +.\" $KAME: ifmcstat.8,v 1.5 2001/07/15 06:15:07 jinmei Exp $ .\" -.\" Copyright (c) 1996 WIDE Project. All rights reserved. +.\" Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. +.\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without -.\" modifications, are permitted provided that the above copyright notice -.\" and this paragraph are duplicated in all such forms and that any -.\" documentation, advertising materials, and other materials related to -.\" such distribution and use acknowledge that the software was developed -.\" by the WIDE Project, Japan. The name of the Project may not be used to -.\" endorse or promote products derived from this software without -.\" specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' -.\" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT -.\" LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -.\" A PARTICULAR PURPOSE. +.\" 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. +.\" .Dd May 21, 1998 .Dt IFMCSTAT 8 .Os @@ -20,23 +35,17 @@ .Nm ifmcstat .Nd dump multicast group management statistics per interface .Sh SYNOPSIS -.Nm ifmcstat +.Nm +.Op Ar kernel +.\" .Sh DESCRIPTION The -.Nm ifmcstat -program dumps multicast group information from the kernel. -It is similar but not identical to the output from -.Nm netstat -.Fl inav . -.Pp -There are no command line options. -.Pp -Only root can use -.Nm ifmcstat . -.Sh SEE ALSO -.Xr netstat 8 +.Nm +command dumps multicast group information in the kernel. .Pp -.%A G. Malkin -.%A R. Minnear -.%R IPng for IPv6 -.%N RFC2080 +.Ar kernel +specifies the kernel binary file the program uses, like +.Pa /netbsd.test . +.Sh BUGS +.Nm +needs superuser privilege. diff --git a/usr.sbin/ifmcstat/ifmcstat.c b/usr.sbin/ifmcstat/ifmcstat.c index 492bfd8bd7b..aa8a73e8530 100644 --- a/usr.sbin/ifmcstat/ifmcstat.c +++ b/usr.sbin/ifmcstat/ifmcstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifmcstat.c,v 1.2 2000/02/26 08:15:38 itojun Exp $ */ +/* $OpenBSD: ifmcstat.c,v 1.3 2001/11/16 04:46:54 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -39,6 +39,8 @@ #include <sys/types.h> #include <sys/socket.h> +#include <sys/queue.h> + #include <net/if.h> #if defined(__FreeBSD__) && __FreeBSD__ >= 3 # include <net/if_var.h> @@ -75,7 +77,7 @@ struct nlist nl[] = { }; const char *inet6_n2a __P((struct in6_addr *)); -int main __P((void)); +int main __P((int, char **)); char *ifname __P((struct ifnet *)); void kread __P((u_long, void *, int)); #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3) @@ -111,11 +113,7 @@ const char *inet6_n2a(p) static char buf[NI_MAXHOST]; struct sockaddr_in6 sin6; u_int32_t scopeid; -#ifdef NI_WITHSCOPEID - const int niflags = NI_NUMERICHOST | NI_WITHSCOPEID; -#else const int niflags = NI_NUMERICHOST; -#endif memset(&sin6, 0, sizeof(sin6)); sin6.sin6_family = AF_INET6; @@ -136,7 +134,9 @@ const char *inet6_n2a(p) return "(invalid)"; } -int main() +int main(argc, argv) + int argc; + char **argv; { char buf[_POSIX2_LINE_MAX], ifname[IFNAMSIZ]; struct ifnet *ifp, *nifp, ifnet; @@ -146,8 +146,21 @@ int main() struct ethercom ec; struct sockaddr_dl sdl; #endif + const char *kernel = NULL; + + switch (argc) { + case 1: + kernel = NULL; + break; + case 2: + kernel = argv[1]; + break; + default: + fprintf(stderr, "usage: ifmcstat [kernel]\n"); + exit(1); + } - if ((kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, buf)) == NULL) { + if ((kvmd = kvm_openfiles(kernel, NULL, NULL, O_RDONLY, buf)) == NULL) { perror("kvm_openfiles"); exit(1); } @@ -214,15 +227,18 @@ char *ifname(ifp) struct ifnet *ifp; { static char buf[BUFSIZ]; -#if defined(__NetBSD__) || defined(__OpenBSD__) struct ifnet ifnet; +#if !(defined(__NetBSD__) || defined(__OpenBSD__)) + char ifnamebuf[IFNAMSIZ]; #endif -#if defined(__NetBSD__) || defined(__OpenBSD__) KREAD(ifp, &ifnet, struct ifnet); - strncpy(buf, ifnet.if_xname, BUFSIZ); +#if defined(__NetBSD__) || defined(__OpenBSD__) + strlcpy(buf, ifnet.if_xname, sizeof(buf)); #else - KREAD(ifp->if_name, buf, IFNAMSIZ); + KREAD(ifnet.if_name, ifnamebuf, sizeof(ifnamebuf)); + snprintf(buf, sizeof(buf), "%s%d", ifnamebuf, + ifnet.if_unit); /* does snprintf allow overlap copy?? */ #endif return buf; } @@ -338,6 +354,10 @@ if6_addrlist(ifap) KREAD(ifap0, &ifa, struct ifaddr); nam = strdup(ifname(ifa.ifa_ifp)); + if (!nam) { + fprintf(stderr, "ifmcstat: not enough core\n"); + exit(1); + } for (mkp = in6_mk.lh_first; mkp; mkp = mk.mk_entry.le_next) { KREAD(mkp, &mk, struct multi6_kludge); |