pkgsrc-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Anyone using xosview?
On Sat, Mar 14, 2015 at 09:08:00PM +0100, Benny Siegert wrote:
> When I launch xosview on NetBSD-7, I get:
>
> xosview: !!! The kernel does not seem to have the symbols needed for
> the NetMeter.
> xosview: !!! The NetMeter has been disabled.
It tries to kvm_read the interface list in old tailq format starting at
_ifnet.
It should instead do ioctl(SIOCGIFDATA) for every interface name found
in the list returned by if_nameindex(3) - much simpler, no kvm needed.
Martin
--8<--
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <machine/int_fmtio.h>
int main(int argc, char **argv)
{
struct ifdatareq ifdr;
const struct if_data *ifi;
struct if_nameindex *p, * iflist = if_nameindex();
int s = socket(AF_LOCAL, SOCK_DGRAM, 0);
for (p = iflist; p->if_index > 0; p++) {
memset(&ifdr, 0, sizeof(ifdr));
strcpy(ifdr.ifdr_name, p->if_name);
if (ioctl(s, SIOCGIFDATA, &ifdr) == -1) {
fprintf(stderr, "failed: %s\n", p->if_name);
return 1;
}
ifi = &ifdr.ifdr_data;
printf("%s in: %"PRIu64" out %"PRIu64"\n", ifdr.ifdr_name, ifi->ifi_ibytes,
ifi->ifi_obytes);
}
close(s);
if_freenameindex(iflist);
return 0;
}
Home |
Main Index |
Thread Index |
Old Index