Module Name:    src
Committed By:   seanb
Date:           Fri Oct 26 16:52:52 UTC 2012

Modified Files:
        src/usr.sbin/ifmcstat: ifmcstat.c

Log Message:
Ensure entire sockaddr_dl is obtained.  May not have
been the case previously for interfaces with long names.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/ifmcstat/ifmcstat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/ifmcstat/ifmcstat.c
diff -u src/usr.sbin/ifmcstat/ifmcstat.c:1.10 src/usr.sbin/ifmcstat/ifmcstat.c:1.11
--- src/usr.sbin/ifmcstat/ifmcstat.c:1.10	Sun Apr 19 07:49:07 2009
+++ src/usr.sbin/ifmcstat/ifmcstat.c	Fri Oct 26 16:52:52 2012
@@ -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);

Reply via email to