Ensure entire sockaddr_dl is obtained. May not have

been the case previously for interfaces with long names.
This commit is contained in:
seanb 2012-10-26 16:52:52 +00:00
parent 1eddef034c
commit c3008a4839
1 changed files with 13 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ifmcstat.c,v 1.10 2009/04/19 07:49:07 lukem Exp $ */
/* $NetBSD: ifmcstat.c,v 1.11 2012/10/26 16:52:52 seanb Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -140,7 +140,12 @@ int main()
struct arpcom arpcom;
#else
struct ethercom ec;
struct sockaddr_dl sdl;
union {
struct sockaddr_storage st;
struct sockaddr_dl sdl;
} su;
struct sockaddr_dl *sdlp;
sdlp = &su.sdl;
#endif
if ((kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, buf)) == NULL) {
@ -172,10 +177,13 @@ int main()
#endif
#ifdef __NetBSD__
KREAD(ifnet.if_sadl, &sdl, struct sockaddr_dl);
if (sdl.sdl_type == IFT_ETHER) {
KREAD(ifnet.if_sadl, sdlp, struct sockaddr_dl);
if (sdlp->sdl_type == IFT_ETHER) {
/* If we didn't get all of it, try again */
if (sdlp->sdl_len > sizeof(struct sockaddr_dl))
kread((u_long)ifnet.if_sadl, (void *)sdlp, sdlp->sdl_len);
printf("\tenaddr %s",
ether_ntoa((struct ether_addr *)LLADDR(&sdl)));
ether_ntoa((struct ether_addr *)LLADDR(sdlp)));
KREAD(ifp, &ec, struct ethercom);
printf(" multicnt %d", ec.ec_multicnt);
acmc(ec.ec_multiaddrs.lh_first);