Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin ifmcstat: show multicast groups currently joined (i...
details: https://anonhg.NetBSD.org/src/rev/ab60d20f1a06
branches: trunk
changeset: 474228:ab60d20f1a06
user: itojun <itojun%NetBSD.org@localhost>
date: Thu Jul 01 20:41:49 1999 +0000
description:
ifmcstat: show multicast groups currently joined (in per-interface manner).
diffstat:
usr.sbin/Makefile | 4 +-
usr.sbin/ifmcstat/Makefile | 14 +
usr.sbin/ifmcstat/ifmcstat.8 | 34 ++++
usr.sbin/ifmcstat/ifmcstat.c | 351 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 401 insertions(+), 2 deletions(-)
diffs (truncated from 429 to 300 lines):
diff -r 46fbc4e0e9bc -r ab60d20f1a06 usr.sbin/Makefile
--- a/usr.sbin/Makefile Thu Jul 01 20:33:55 1999 +0000
+++ b/usr.sbin/Makefile Thu Jul 01 20:41:49 1999 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.111 1999/07/01 20:33:55 itojun Exp $
+# $NetBSD: Makefile,v 1.112 1999/07/01 20:41:49 itojun Exp $
# from: @(#)Makefile 5.20 (Berkeley) 6/12/93
# XXX Temporary for NO_SENDMAIL and BUILD_POSTFIX
@@ -22,7 +22,7 @@
zdump zic
# IPv6
-SUBDIR+=gifconfig ndp
+SUBDIR+=gifconfig ifmcstat ndp
.if !defined(NO_SENDMAIL)
SUBDIR+= sendmail
diff -r 46fbc4e0e9bc -r ab60d20f1a06 usr.sbin/ifmcstat/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/ifmcstat/Makefile Thu Jul 01 20:41:49 1999 +0000
@@ -0,0 +1,14 @@
+# $NetBSD: Makefile,v 1.1 1999/07/01 20:41:50 itojun Exp $
+# @(#)Makefile 8.1 (Berkeley) 6/5/93
+
+PROG= ifmcstat
+MAN= ifmcstat.8
+
+BINGRP= kmem
+BINMODE=2555
+LDADD= -lkvm
+DPADD= ${LIBKVM}
+
+CPPFLAGS+= -DINET6
+
+.include <bsd.prog.mk>
diff -r 46fbc4e0e9bc -r ab60d20f1a06 usr.sbin/ifmcstat/ifmcstat.8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/ifmcstat/ifmcstat.8 Thu Jul 01 20:41:49 1999 +0000
@@ -0,0 +1,34 @@
+.\" Copyright (c) 1996 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.
+.Dd May 21, 1998
+.Dt IFMCSTAT 8
+.Os
+.Sh NAME
+.Nm ifmcstat
+.Nd dump multicast group management statistics per interface
+.Sh SYNOPSIS
+.Nm
+.\"
+.Sh DESCRIPTION
+The
+.Nm Ifmcstat
+dumps multicast group information in the kernel.
+.Pp
+There are no command-line options.
+.\"
+.\" .Sh SEE ALSO
+.\" RFC2080 -- IPng for IPv6. G. Malkin, R. Minnear. January 1997.
+.Sh HISTORY
+.Nm
+first appeared in WIDE hydrangea IPv6 stack kit.
diff -r 46fbc4e0e9bc -r ab60d20f1a06 usr.sbin/ifmcstat/ifmcstat.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/ifmcstat/ifmcstat.c Thu Jul 01 20:41:49 1999 +0000
@@ -0,0 +1,351 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <kvm.h>
+#include <nlist.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+#include <net/if_var.h>
+#include <net/if_dl.h>
+#endif /* __FreeBSD__ >= 3 */
+#include <netinet/in.h>
+#ifndef __NetBSD__
+#ifdef __FreeBSD__
+#define KERNEL
+#endif
+#include <netinet/if_ether.h>
+#ifdef __FreeBSD__
+#undef KERNEL
+#endif
+#else /* __NetBSD__ */
+#include <net/if_ether.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+#endif /* __NetBSD__ */
+#include <netinet/in_var.h>
+#include <arpa/inet.h>
+
+kvm_t *kvmd;
+
+struct nlist nl[] = {
+#define N_IFNET 0
+ { "_ifnet" },
+ { "" },
+};
+
+const char *inet6_n2a __P((struct in6_addr *));
+int main __P((void));
+char *ifname __P((struct ifnet *));
+#ifndef __NetBSD__
+int havearpcom __P((char *));
+#endif /* __NetBSD__ */
+void kread __P((u_long, void *, int));
+#if !defined(__FreeBSD__) || __FreeBSD__ < 3
+void acmc __P((struct ether_multi *));
+#else
+void ifmamc __P((struct ifmultiaddr *ifma_p));
+#endif /* __FreeBSD__ < 3 */
+void if6_addrlist __P((struct ifaddr *));
+void in6_multilist __P((struct in6_multi *));
+struct in6_multi * in6_multientry __P((struct in6_multi *));
+
+#define KREAD(addr, buf, type) \
+ kread((u_long)addr, (void *)buf, sizeof(type))
+
+const char *inet6_n2a(p)
+ struct in6_addr *p;
+{
+ static char buf[BUFSIZ];
+
+ if (IN6_IS_ADDR_ANY(p))
+ return "*";
+ return inet_ntop(AF_INET6, (void *)p, buf, sizeof(buf));
+}
+
+int main()
+{
+ char buf[BUFSIZ], ifname[IFNAMSIZ];
+ struct ifnet *ifp, ifnet;
+#ifndef __NetBSD__
+ struct arpcom arpcom;
+#else
+ struct ethercom ec;
+ struct sockaddr_dl sdl;
+#endif
+
+ if ((kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, buf)) == NULL) {
+ perror("kvm_openfiles");
+ exit(1);
+ }
+ if (kvm_nlist(kvmd, nl) < 0) {
+ perror("kvm_nlist");
+ exit(1);
+ }
+ if (nl[N_IFNET].n_value == 0) {
+ printf("symbol %s not found\n", nl[N_IFNET].n_name);
+ exit(1);
+ }
+ KREAD(nl[N_IFNET].n_value, &ifp, struct ifnet *);
+ while (ifp) {
+ KREAD(ifp, &ifnet, struct ifnet);
+ printf("%s:\n", if_indextoname(ifnet.if_index, ifname));
+
+#ifndef __NetBSD__
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+ if6_addrlist(TAILQ_FIRST(&ifnet.if_addrhead));
+ ifp = ifnet.if_link.tqe_next;
+#else /* __FreeBSD__ >= 3 */
+ if6_addrlist(ifnet.if_addrlist);
+
+ if (havearpcom(ifname)) {
+ KREAD(ifp, &arpcom, struct arpcom);
+ printf("\tenaddr %02x:%02x:%02x:%02x:%02x:%02x",
+ arpcom.ac_enaddr[0], arpcom.ac_enaddr[1],
+ arpcom.ac_enaddr[2], arpcom.ac_enaddr[3],
+ arpcom.ac_enaddr[4], arpcom.ac_enaddr[5]);
+ printf(" multicnt %d", arpcom.ac_multicnt);
+ acmc(arpcom.ac_multiaddrs);
+ printf("\n");
+ }
+
+ ifp = ifnet.if_next;
+#endif /* __FreeBSD__ >= 3 */
+#else
+ if6_addrlist(ifnet.if_addrlist.tqh_first);
+
+ KREAD(ifnet.if_sadl, &sdl, struct sockaddr_dl);
+ if (sdl.sdl_type == IFT_ETHER) {
+ printf("\tenaddr %s",
+ ether_ntoa((struct ether_addr *)LLADDR(&sdl)));
+ KREAD(ifp, &ec, struct ethercom);
+ printf(" multicnt %d", ec.ec_multicnt);
+ acmc(ec.ec_multiaddrs.lh_first);
+ printf("\n");
+ }
+
+ ifp = ifnet.if_list.tqe_next;
+#endif
+ }
+
+ exit(0);
+ /*NOTREACHED*/
+}
+
+char *ifname(ifp)
+ struct ifnet *ifp;
+{
+ static char buf[BUFSIZ];
+
+#ifndef __NetBSD__
+ KREAD(ifp->if_name, buf, IFNAMSIZ);
+#else
+ KREAD(ifp->if_xname, buf, IFNAMSIZ);
+#endif
+ return buf;
+}
+
+void kread(addr, buf, len)
+ u_long addr;
+ void *buf;
+ int len;
+{
+ if (kvm_read(kvmd, addr, buf, len) != len) {
+ perror("kvm_read");
+ exit(1);
+ }
+}
+
+#ifndef __NetBSD__
+int havearpcom(p)
+ char *p;
+{
+ if (strncmp(p, "ne", 2) == 0) return 1;
+ if (strncmp(p, "eo", 2) == 0) return 1;
+ if (strncmp(p, "ep", 2) == 0) return 1;
+ if (strncmp(p, "tn", 2) == 0) return 1;
+ if (strncmp(p, "de", 2) == 0) return 1;
+ if (strncmp(p, "hpp", 3) == 0) return 1;
+ if (strncmp(p, "re", 2) == 0) return 1;
+ if (strncmp(p, "ef", 2) == 0) return 1;
+ if (strncmp(p, "di", 2) == 0) return 1;
+ if (strncmp(p, "we", 2) == 0) return 1;
+ if (strncmp(p, "el", 2) == 0) return 1;
+ if (strncmp(p, "ex", 2) == 0) return 1;
+ if (strncmp(p, "pe", 2) == 0) return 1;
+ if (strncmp(p, "xir", 3) == 0) return 1;
+ if (strncmp(p, "fxp", 2) == 0) return 1;
+ if (strncmp(p, "fe", 2) == 0) return 1;
+ if (strncmp(p, "cnw", 2) == 0) return 1;
+/* if (strncmp(p, "tr", 2) == 0) return 1; ??? */
+/* if (strncmp(p, "fea", 3) == 0) return 1; ??? */
+/* if (strncmp(p, "fpa", 3) == 0) return 1; ??? */
+/* if (strncmp(p, "te", 2) == 0) return 1; ??? */
+ return 0;
+}
+#endif
+
+#if !defined(__FreeBSD__) || __FreeBSD__ < 3
+void acmc(am)
+ struct ether_multi *am;
Home |
Main Index |
Thread Index |
Old Index