summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJos Dehaes <jos.dehaes@gmail.com>2021-10-22 14:28:40 +0200
committerJos Dehaes <jos.dehaes@gmail.com>2021-10-22 14:28:40 +0200
commit5249be0a40d12081ebdea05d6e3cad5c6bfa9e11 (patch)
treeb726ae3ebc2876880fba276ff6767f9609b11e83
parent96461f4d948a29bbd6748223e8bb014c8d2f2902 (diff)
net stats
-rw-r--r--src/freebsd/btop_collect.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp
index e8df5a2..7334b21 100644
--- a/src/freebsd/btop_collect.cpp
+++ b/src/freebsd/btop_collect.cpp
@@ -20,6 +20,7 @@ tab-size = 4
#include <libproc.h>
#include <net/if.h>
#include <net/if_dl.h>
+#include <net/route.h>
#include <netdb.h>
#include <netinet/tcp_fsm.h>
#include <pwd.h>
@@ -667,13 +668,14 @@ namespace Net {
for (next = buf.get(); next < lim;) {
struct if_msghdr *ifm = (struct if_msghdr *)next;
next += ifm->ifm_msglen;
- if (ifm->ifm_type == NET_RT_IFLISTL) {
- struct if_msghdrl *if2m = (struct if_msghdrl *)ifm;
- struct sockaddr_dl *sdl = (struct sockaddr_dl *)(if2m + 1);
+ struct if_data ifm_data = ifm->ifm_data;
+ if (ifm->ifm_addrs & RTA_IFP) {
+ struct sockaddr_dl *sdl = (struct sockaddr_dl *)(ifm + 1);
char iface[32];
strncpy(iface, sdl->sdl_data, sdl->sdl_nlen);
iface[sdl->sdl_nlen] = 0;
- ifstats[iface] = std::tuple(if2m->ifm_data.ifi_ibytes, if2m->ifm_data.ifi_obytes);
+ Logger::debug("" + string(iface) + " i=" + std::to_string(ifm_data.ifi_ibytes) + " o=" + std::to_string(ifm_data.ifi_obytes));
+ ifstats[iface] = std::tuple(ifm_data.ifi_ibytes, ifm_data.ifi_obytes);
}
}
}