pkgsrc/net/pload/patches/patch-aa
wiz c414df5d94 Update to 0.9.5, provided by Sergey Svishchev in private mail:
- Fixed stats not being cleared when disconnected
- Added user specified format for labels.
- Added user customizable label for the not connected condition.
- Removed global variables in stats gathering functions.

pkgsrc fix: don't cast 64-bit counters to unsigned long.
2007-12-09 23:41:11 +00:00

55 lines
1.5 KiB
Text

$NetBSD: patch-aa,v 1.4 2007/12/09 23:41:11 wiz Exp $
--- ioctl_stat.c.orig 2000-02-01 07:11:24.000000000 +0000
+++ ioctl_stat.c
@@ -61,6 +61,10 @@ void getsocket(if_data *ifd)
void ioctl_stat(if_data *ifd)
{
struct ifreq ifr;
+#ifdef SIOCGIFDATA
+ struct ifdatareq ifdr;
+ struct if_data * const ifi = &ifdr.ifdr_data;
+#endif
struct ifpppstatsreq req;
if (!ifd->s) getsocket(ifd);
@@ -84,6 +88,31 @@ void ioctl_stat(if_data *ifd)
#define ifr_name ifr__name
#endif
+#ifdef __NetBSD__
+ strncpy(ifr.ifr_name, ifd->device, sizeof(ifr.ifr_name));
+ if (ioctl(ifd->s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0 ||
+ !(ifr.ifr_flags&IFF_UP))
+ {
+ /* invalid interface, or interface down */
+ ifd->in_bytes = 0UL;
+ ifd->out_bytes = 0UL;
+ return;
+ }
+#endif
+
+#if defined(__NetBSD__) && defined(SIOCGIFDATA)
+ /* prefer the generic interface statistics over the PPP specific ones */
+ strncpy(ifdr.ifdr_name, ifd->device, sizeof(ifdr.ifdr_name));
+ if (ioctl(ifd->s, SIOCGIFDATA, &ifdr) == -1)
+ {
+ /* non-existent device? */
+ ifd->in_bytes = 0UL;
+ ifd->out_bytes = 0UL;
+ return;
+ }
+ ifd->in_bytes = ifi->ifi_ibytes;
+ ifd->out_bytes = ifi->ifi_obytes;
+#else
strncpy(req.ifr_name, ifd->device, sizeof(req.ifr_name));
if (ioctl(ifd->s, SIOCGPPPSTATS, &req) != 0)
{
@@ -95,6 +124,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;
}