$NetBSD: patch-aa,v 1.4 2004/11/27 00:15:30 abs Exp $

--- ioctl_stat.c.orig	2000-02-01 07:49:01.000000000 +0000
+++ ioctl_stat.c
@@ -62,6 +62,10 @@ void ioctl_stat(if_data *ifd)
 {
 	struct ifreq ifr;
 	struct ifpppstatsreq req;
+#ifdef SIOCGIFDATA	 /* Supported on at least NetBSD */
+	struct ifdatareq ifdr;
+ 	struct if_data * const ifi = &ifdr.ifdr_data;
+#endif
 	
 	if (!ifd->s) getsocket(ifd);
 	
@@ -84,6 +88,19 @@ void ioctl_stat(if_data *ifd)
 #define ifr_name ifr__name
 #endif	
 
+#if defined(SIOCGIFDATA)
+	/* prefer generic interface statistics over PPP specific ones */
+	strncpy(ifdr.ifdr_name, ifd->device, sizeof(ifdr.ifdr_name));
+	if (ioctl(ifd->s, SIOCGIFDATA, &ifdr) == -1)
+	{
+		/* non-existant device? */
+		ifd->in_bytes = 0UL;
+		ifd->out_bytes = 0UL;
+		return;
+	}
+	ifd->in_bytes = (unsigned long)ifi->ifi_ibytes;
+	ifd->out_bytes = (unsigned long)ifi->ifi_obytes;
+#else
 	strncpy(req.ifr_name, ifd->device, sizeof(req.ifr_name));
 	if (ioctl(ifd->s, SIOCGPPPSTATS, &req) != 0)
 	{
@@ -95,6 +112,7 @@ void ioctl_stat(if_data *ifd)
 	
 	ifd->in_bytes = (unsigned long)req.stats.p.ppp_ibytes;
 	ifd->out_bytes = (unsigned long)req.stats.p.ppp_obytes;
+#endif
 	
 	return;
 }
