1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
$NetBSD: patch-aa,v 1.3 2002/05/24 18:12:36 martin Exp $
--- ioctl_stat.c.orig Thu Mar 4 08:33:03 1999
+++ ioctl_stat.c Fri May 24 20:03:05 2002
@@ -68,6 +68,13 @@
void ioctl_stat(if_data *ifd)
{
+#ifdef __NetBSD__
+ struct ifreq ifr;
+#ifdef SIOCGIFDATA
+ struct ifdatareq ifdr;
+ struct if_data * const ifi = &ifdr.ifdr_data;
+#endif
+#endif
struct ifpppstatsreq req;
if (s < 0) getsocket();
@@ -78,8 +85,33 @@
#define ifr_name ifr__name
req.stats_ptr = (caddr_t) &req.stats;
#endif
- sprintf(req.ifr_name, ifd->device);
+#ifdef __NetBSD__
+ sprintf(ifr.ifr_name, ifd->device);
+ if (ioctl(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)
+ /* prefere the generic interface statistics over the PPP specific ones */
+ strncpy(ifdr.ifdr_name, ifd->device, sizeof(ifdr.ifdr_name));
+ if (ioctl(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
+ sprintf(req.ifr_name, ifd->device);
if (ioctl(s, SIOCGPPPSTATS, &req) != 0)
{
/* non-existant device? */
@@ -90,6 +122,7 @@
ifd->in_bytes = (unsigned long)req.stats.p.ppp_ibytes;
ifd->out_bytes = (unsigned long)req.stats.p.ppp_obytes;
+#endif
return;
}
|