summaryrefslogtreecommitdiffstats
path: root/src/freebsd
diff options
context:
space:
mode:
authorSteffen Winter <steffen.winter@proton.me>2024-02-09 13:53:42 +0100
committerSteffen Winter <steffen.winter@proton.me>2024-02-09 14:03:06 +0100
commitab0bef204a248609ac05948e531108a8032b8e63 (patch)
treee03da6d045fc80b90c1fe52844b234ad1254138e /src/freebsd
parentee46dba838da69e066232af79fe373a8533a7bc2 (diff)
collect: Share ifaddrs wrapper and use uniq_ptr-like syntax
Diffstat (limited to 'src/freebsd')
-rw-r--r--src/freebsd/btop_collect.cpp19
1 files changed, 4 insertions, 15 deletions
diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp
index 094d78a..d64a878 100644
--- a/src/freebsd/btop_collect.cpp
+++ b/src/freebsd/btop_collect.cpp
@@ -811,17 +811,6 @@ namespace Net {
bool rescale = true;
uint64_t timestamp = 0;
- //* RAII wrapper for getifaddrs
- class getifaddr_wrapper {
- struct ifaddrs *ifaddr;
-
- public:
- int status;
- getifaddr_wrapper() { status = getifaddrs(&ifaddr); }
- ~getifaddr_wrapper() { freeifaddrs(ifaddr); }
- auto operator()() -> struct ifaddrs * { return ifaddr; }
- };
-
auto collect(bool no_update) -> net_info & {
auto &net = current_net;
auto &config_iface = Config::getS("net_iface");
@@ -831,10 +820,10 @@ namespace Net {
if (not no_update and errors < 3) {
//? Get interface list using getifaddrs() wrapper
- getifaddr_wrapper if_wrap{};
- if (if_wrap.status != 0) {
+ IfAddrsPtr if_addrs {};
+ if (if_addrs.get_status() != 0) {
errors++;
- Logger::error("Net::collect() -> getifaddrs() failed with id " + to_string(if_wrap.status));
+ Logger::error("Net::collect() -> getifaddrs() failed with id " + to_string(if_addrs.get_status()));
redraw = true;
return empty_net;
}
@@ -846,7 +835,7 @@ namespace Net {
string ipv4, ipv6;
//? Iteration over all items in getifaddrs() list
- for (auto *ifa = if_wrap(); ifa != nullptr; ifa = ifa->ifa_next) {
+ for (auto *ifa = if_addrs.get(); ifa != nullptr; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == nullptr) continue;
family = ifa->ifa_addr->sa_family;
const auto &iface = ifa->ifa_name;