fe5d9a77b4
Patch differentials came from FreeBSD ports.
120 lines
3.1 KiB
Text
120 lines
3.1 KiB
Text
$NetBSD: patch-aa,v 1.5 2012/08/11 17:22:18 marino Exp $
|
|
|
|
--- ioctl_stat.c.orig 2000-02-01 07:49:01.000000000 +0000
|
|
+++ ioctl_stat.c
|
|
@@ -30,6 +30,15 @@
|
|
#include <fcntl.h> /* open */
|
|
#include <sys/ioctl.h> /* ioctl */
|
|
#include <errno.h>
|
|
+#if defined(__FreeBSD__) || defined(__DragonFly__)
|
|
+#define __FreeFly__ 1
|
|
+#endif
|
|
+#if __FreeFly__
|
|
+#include <sys/sysctl.h>
|
|
+#include <sys/socket.h>
|
|
+#include <net/if.h>
|
|
+#include <net/if_mib.h>
|
|
+#endif
|
|
|
|
#ifndef STREAMS /* Linux, FreeBSD, NetBSD, Ultrix */
|
|
# include <sys/socket.h> /* socket */
|
|
@@ -39,8 +48,10 @@
|
|
# include <linux/if_ppp.h>
|
|
# else /* most everything else */
|
|
# include <net/if.h>
|
|
+# ifndef __FreeFly__
|
|
# include <net/ppp_defs.h>
|
|
# include <net/if_ppp.h>
|
|
+# endif /* FreeBSD | DragonFly */
|
|
# endif /* linux && __GLIBC__ < 2 */
|
|
#else /* STREAMS */ /* Solaris, SunOS, OSF/1, SVR4 */
|
|
# include <net/ppp_defs.h>
|
|
@@ -61,7 +72,21 @@ void getsocket(if_data *ifd)
|
|
void ioctl_stat(if_data *ifd)
|
|
{
|
|
struct ifreq ifr;
|
|
+#if __FreeFly__
|
|
+ static int if_ix = -1;
|
|
+ struct ifmibdata ifmd;
|
|
+ size_t ifmd_sz = sizeof(ifmd);
|
|
+ int nr_ifs;
|
|
+ size_t nr_ifs_sz = sizeof(nr_ifs);
|
|
+ int name[6];
|
|
+ int i;
|
|
+#else
|
|
+#ifdef SIOCGIFDATA
|
|
+ struct ifdatareq ifdr;
|
|
+ struct if_data * const ifi = &ifdr.ifdr_data;
|
|
+#endif
|
|
struct ifpppstatsreq req;
|
|
+#endif /* FreeBSD | DragonFly */
|
|
|
|
if (!ifd->s) getsocket(ifd);
|
|
|
|
@@ -76,7 +101,9 @@ void ioctl_stat(if_data *ifd)
|
|
return;
|
|
}
|
|
|
|
+#ifndef __FreeFly__
|
|
memset(&req, 0, sizeof(req));
|
|
+#endif
|
|
|
|
#ifdef linux
|
|
req.stats_ptr = (caddr_t) &req.stats;
|
|
@@ -84,6 +111,48 @@ void ioctl_stat(if_data *ifd)
|
|
#define ifr_name ifr__name
|
|
#endif
|
|
|
|
+#if __FreeFly__
|
|
+ name[0] = CTL_NET;
|
|
+ name[1] = PF_LINK;
|
|
+ name[2] = NETLINK_GENERIC;
|
|
+ name[3] = IFMIB_IFDATA;
|
|
+ name[5] = IFDATA_GENERAL;
|
|
+
|
|
+ if (if_ix < 0) {
|
|
+ if (sysctlbyname("net.link.generic.system.ifcount", (void *) &nr_ifs, &nr_ifs_sz, (void *) 0, 0) < 0) {
|
|
+ return;
|
|
+ }
|
|
+ for (i = 1; i <= nr_ifs; i++) {
|
|
+ name[4] = i; /* row of the ifmib table */
|
|
+
|
|
+ if (sysctl(name, 6, (void *) &ifmd, &ifmd_sz, (void *) 0, 0) < 0) {
|
|
+ continue;
|
|
+ }
|
|
+ if (strncmp(ifmd.ifmd_name, ifr.ifr_name, strlen(ifr.ifr_name)) == 0) {
|
|
+ if_ix = i;
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ name[4] = if_ix;
|
|
+ if (sysctl(name, 6, (void *) &ifmd, &ifmd_sz, (void *) 0, 0) >= 0) {
|
|
+ ifd->in_bytes = ifmd.ifmd_data.ifi_ibytes;
|
|
+ ifd->out_bytes = ifmd.ifmd_data.ifi_obytes;
|
|
+ }
|
|
+#elif 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 +164,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;
|
|
}
|