sync with latest KAME. cleanup on interface type determination.

This commit is contained in:
itojun 1999-12-09 15:34:19 +00:00
parent 119ee78fd0
commit 4265f28e51
2 changed files with 86 additions and 105 deletions

View File

@ -12,7 +12,7 @@
.\" LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR .\" LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
.\" A PARTICULAR PURPOSE. .\" A PARTICULAR PURPOSE.
.\" .\"
.\" $NetBSD: ifmcstat.8,v 1.2 1999/07/06 13:16:33 itojun Exp $ .\" $NetBSD: ifmcstat.8,v 1.3 1999/12/09 15:34:19 itojun Exp $
.\" .\"
.Dd May 21, 1998 .Dd May 21, 1998
.Dt IFMCSTAT 8 .Dt IFMCSTAT 8
@ -31,7 +31,4 @@ dumps multicast group information in the kernel.
There are no command-line options. There are no command-line options.
.\" .\"
.\" .Sh SEE ALSO .\" .Sh SEE ALSO
.\" RFC2080 -- RIPng for IPv6. G. Malkin, R. Minnear. January 1997. .\" RFC2080 -- IPng for IPv6. G. Malkin, R. Minnear. January 1997.
.Sh HISTORY
.Nm
first appeared in WIDE hydrangea IPv6 stack kit.

View File

@ -1,4 +1,4 @@
/* $NetBSD: ifmcstat.c,v 1.4 1999/09/03 04:31:48 itojun Exp $ */ /* $NetBSD: ifmcstat.c,v 1.5 1999/12/09 15:34:19 itojun Exp $ */
/* /*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -41,23 +41,22 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <net/if.h> #include <net/if.h>
#if defined(__FreeBSD__) && __FreeBSD__ >= 3 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
#include <net/if_var.h> # include <net/if_var.h>
#endif
#include <net/if_types.h>
#include <net/if_dl.h> #include <net/if_dl.h>
#endif /* __FreeBSD__ >= 3 */
#include <netinet/in.h> #include <netinet/in.h>
#ifndef __NetBSD__ #ifndef __NetBSD__
#ifdef __FreeBSD__ # ifdef __FreeBSD__
#define KERNEL # define KERNEL
# endif
# include <netinet/if_ether.h>
# ifdef __FreeBSD__
# undef KERNEL
# endif
#else
# include <net/if_ether.h>
#endif #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 <netinet/in_var.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -72,19 +71,23 @@ struct nlist nl[] = {
const char *inet6_n2a __P((struct in6_addr *)); const char *inet6_n2a __P((struct in6_addr *));
int main __P((void)); int main __P((void));
char *ifname __P((struct ifnet *)); char *ifname __P((struct ifnet *));
#ifndef __NetBSD__
int havearpcom __P((char *));
#endif /* __NetBSD__ */
void kread __P((u_long, void *, int)); void kread __P((u_long, void *, int));
#if !defined(__FreeBSD__) || __FreeBSD__ < 3 #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3)
void acmc __P((struct ether_multi *)); void acmc __P((struct ether_multi *));
#else #endif
void ifmamc __P((struct ifmultiaddr *ifma_p));
#endif /* __FreeBSD__ < 3 */
void if6_addrlist __P((struct ifaddr *)); void if6_addrlist __P((struct ifaddr *));
void in6_multilist __P((struct in6_multi *)); void in6_multilist __P((struct in6_multi *));
struct in6_multi * in6_multientry __P((struct in6_multi *)); struct in6_multi * in6_multientry __P((struct in6_multi *));
#if !defined(__NetBSD__) && !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(__OpenBSD__)
#ifdef __bsdi__
struct ether_addr {
u_int8_t ether_addr_octet[6];
};
#endif
static char *ether_ntoa __P((struct ether_addr *));
#endif
#define KREAD(addr, buf, type) \ #define KREAD(addr, buf, type) \
kread((u_long)addr, (void *)buf, sizeof(type)) kread((u_long)addr, (void *)buf, sizeof(type))
@ -101,7 +104,7 @@ const char *inet6_n2a(p)
int main() int main()
{ {
char buf[_POSIX2_LINE_MAX], ifname[IFNAMSIZ]; char buf[_POSIX2_LINE_MAX], ifname[IFNAMSIZ];
struct ifnet *ifp, ifnet; struct ifnet *ifp, *nifp, ifnet;
#ifndef __NetBSD__ #ifndef __NetBSD__
struct arpcom arpcom; struct arpcom arpcom;
#else #else
@ -126,29 +129,18 @@ int main()
KREAD(ifp, &ifnet, struct ifnet); KREAD(ifp, &ifnet, struct ifnet);
printf("%s:\n", if_indextoname(ifnet.if_index, ifname)); printf("%s:\n", if_indextoname(ifnet.if_index, ifname));
#ifndef __NetBSD__ #if defined(__NetBSD__) || defined(__OpenBSD__)
#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); if6_addrlist(ifnet.if_addrlist.tqh_first);
nifp = ifnet.if_list.tqe_next;
#elif defined(__FreeBSD__) && __FreeBSD__ >= 3
if6_addrlist(TAILQ_FIRST(&ifnet.if_addrhead));
nifp = ifnet.if_link.tqe_next;
#else
if6_addrlist(ifnet.if_addrlist);
nifp = ifnet.if_next;
#endif
#ifdef __NetBSD__
KREAD(ifnet.if_sadl, &sdl, struct sockaddr_dl); KREAD(ifnet.if_sadl, &sdl, struct sockaddr_dl);
if (sdl.sdl_type == IFT_ETHER) { if (sdl.sdl_type == IFT_ETHER) {
printf("\tenaddr %s", printf("\tenaddr %s",
@ -158,9 +150,25 @@ int main()
acmc(ec.ec_multiaddrs.lh_first); acmc(ec.ec_multiaddrs.lh_first);
printf("\n"); printf("\n");
} }
#elif defined(__FreeBSD__) && __FreeBSD__ >= 3
ifp = ifnet.if_list.tqe_next; /* not supported */
#else
if (ifnet.if_type == IFT_ETHER) {
KREAD(ifp, &arpcom, struct arpcom);
printf("\tenaddr %s",
ether_ntoa((struct ether_addr *)arpcom.ac_enaddr));
KREAD(ifp, &arpcom, struct arpcom);
printf(" multicnt %d", arpcom.ac_multicnt);
#ifdef __OpenBSD__
acmc(arpcom.ac_multiaddrs.lh_first);
#else
acmc(arpcom.ac_multiaddrs);
#endif #endif
printf("\n");
}
#endif
ifp = nifp;
} }
exit(0); exit(0);
@ -172,10 +180,10 @@ char *ifname(ifp)
{ {
static char buf[BUFSIZ]; static char buf[BUFSIZ];
#ifndef __NetBSD__ #if defined(__NetBSD__) || defined(__OpenBSD__)
KREAD(ifp->if_name, buf, IFNAMSIZ);
#else
KREAD(ifp->if_xname, buf, IFNAMSIZ); KREAD(ifp->if_xname, buf, IFNAMSIZ);
#else
KREAD(ifp->if_name, buf, IFNAMSIZ);
#endif #endif
return buf; return buf;
} }
@ -191,36 +199,7 @@ void kread(addr, buf, len)
} }
} }
#ifndef __NetBSD__ #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3)
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) void acmc(am)
struct ether_multi *am; struct ether_multi *am;
{ {
@ -230,26 +209,17 @@ void acmc(am)
KREAD(am, &em, struct ether_multi); KREAD(am, &em, struct ether_multi);
printf("\n\t\t"); printf("\n\t\t");
#ifndef __NetBSD__ printf("%s -- ", ether_ntoa((struct ether_addr *)em.enm_addrlo));
printf("%02x:%02x:%02x:%02x:%02x:%02x--",
em.enm_addrlo[0], em.enm_addrlo[1],
em.enm_addrlo[2], em.enm_addrlo[3],
em.enm_addrlo[4], em.enm_addrlo[5]);
printf("%02x:%02x:%02x:%02x:%02x:%02x",
em.enm_addrhi[0], em.enm_addrhi[1],
em.enm_addrhi[2], em.enm_addrhi[3],
em.enm_addrhi[4], em.enm_addrhi[5]);
printf(" %d", em.enm_refcount);
am = em.enm_next;
#else
printf("%s -- ", ether_ntoa((struct ether_addr *)&em.enm_addrlo));
printf("%s ", ether_ntoa((struct ether_addr *)&em.enm_addrhi)); printf("%s ", ether_ntoa((struct ether_addr *)&em.enm_addrhi));
printf("%d", em.enm_refcount); printf("%d", em.enm_refcount);
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
am = em.enm_next;
#else
am = em.enm_list.le_next; am = em.enm_list.le_next;
#endif #endif
} }
} }
#endif /* __FreeBSD__ < 3 */ #endif
void void
if6_addrlist(ifap) if6_addrlist(ifap)
@ -279,19 +249,17 @@ if6_addrlist(ifap)
inet_ntop(AF_INET6, inet_ntop(AF_INET6,
(const void *)&if6a.ia_addr.sin6_addr, (const void *)&if6a.ia_addr.sin6_addr,
in6buf, sizeof(in6buf))); in6buf, sizeof(in6buf)));
#if !defined(__FreeBSD__) || __FreeBSD__ < 3 #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3)
mc = mc ? mc : if6a.ia6_multiaddrs.lh_first; mc = mc ? mc : if6a.ia6_multiaddrs.lh_first;
#endif /* !__FreeBSD__ || __FreeBSD__ < 3 */ #endif
nextifap: nextifap:
#ifndef __NetBSD__ #if defined(__NetBSD__) || defined(__OpenBSD__)
#if defined(__FreeBSD__) && __FreeBSD__ >= 3 ifap = ifa.ifa_list.tqe_next;
#elif defined(__FreeBSD__) && __FreeBSD__ >= 3
ifap = ifa.ifa_link.tqe_next; ifap = ifa.ifa_link.tqe_next;
#else #else
ifap = ifa.ifa_next; ifap = ifa.ifa_next;
#endif /* __FreeBSD__ >= 3 */ #endif /* __FreeBSD__ >= 3 */
#else
ifap = ifa.ifa_list.tqe_next;
#endif
} }
#if defined(__FreeBSD__) && __FreeBSD__ >= 3 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
if (ifap0) { if (ifap0) {
@ -328,7 +296,7 @@ if6_addrlist(ifap)
#else #else
if (mc) if (mc)
in6_multilist(mc); in6_multilist(mc);
#endif /* !__FreeBSD__ || __FreeBSD__ < 3 */ #endif
} }
struct in6_multi * struct in6_multi *
@ -352,3 +320,19 @@ in6_multilist(mc)
while (mc) while (mc)
mc = in6_multientry(mc); mc = in6_multientry(mc);
} }
#if !defined(__NetBSD__) && !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(__OpenBSD__)
static char *
ether_ntoa(e)
struct ether_addr *e;
{
static char buf[20];
u_char *p;
p = (u_char *)e;
snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x",
p[0], p[1], p[2], p[3], p[4], p[5]);
return buf;
}
#endif