From 0dbcb28a2c5c8526319accaf19d9478f3629f259 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Sun, 12 Jan 2020 14:00:32 +0100 Subject: [PATCH] fix(net): Query IP addresses for tun/ tap devices Before tuntap devices would never call the generic `network::query` method and just return true. Fixes #1986 --- src/adapters/net.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/adapters/net.cpp b/src/adapters/net.cpp index 0b79e123..40c8b89f 100644 --- a/src/adapters/net.cpp +++ b/src/adapters/net.cpp @@ -52,11 +52,6 @@ namespace net { * Query device driver for information */ bool network::query(bool accumulate) { - struct ifaddrs* ifaddr; - if (getifaddrs(&ifaddr) == -1 || ifaddr == nullptr) { - return false; - } - m_status.previous = m_status.current; m_status.current.transmitted = 0; m_status.current.received = 0; @@ -64,6 +59,11 @@ namespace net { m_status.ip = NO_IP; m_status.ip6 = NO_IP; + struct ifaddrs* ifaddr; + if (getifaddrs(&ifaddr) == -1 || ifaddr == nullptr) { + return false; + } + for (auto ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) { if (ifa->ifa_addr == nullptr) { continue; @@ -248,10 +248,12 @@ namespace net { * Query device driver for information */ bool wired_network::query(bool accumulate) { + if (!network::query(accumulate)) { + return false; + } + if (m_tuntap) { return true; - } else if (!network::query(accumulate)) { - return false; } if(m_bridge) {