More network interface up fix
This commit is contained in:
@@ -181,8 +181,8 @@ namespace display::ui::hostblock
|
||||
int by = cursorY +
|
||||
row * (config.hostblock.networks.height + config.hostblock.networks.gap_v);
|
||||
|
||||
float value_rx = std::clamp(network.rxBps / network.rxMaxBps, 0.0f, 1.0f);
|
||||
float value_tx = std::clamp(network.txBps / network.txMaxBps, 0.0f, 1.0f);
|
||||
float value_rx = std::clamp(network.rxBps / std::max(network.rxMaxBps, 1048576.0f), 0.0f, 1.0f);
|
||||
float value_tx = std::clamp(network.txBps / std::max(network.txMaxBps, 1048576.0f), 0.0f, 1.0f);
|
||||
|
||||
netBar.draw(fb, bx, by, value_rx, 0, network.online && online, true);
|
||||
netBar.draw(fb, bx + config.hostblock.networks.width, by, value_tx, 0, network.online && online);
|
||||
@@ -190,7 +190,7 @@ namespace display::ui::hostblock
|
||||
text.drawTextOutlined(fb,
|
||||
bx + config.hostblock.networks.font.padding,
|
||||
by + 8,
|
||||
display::ui::text::formatSpeed(network.rxBps) + " " + network.name,
|
||||
network.name,
|
||||
network.online && online ? display::ui::theme::text::TEXT : display::ui::theme::text::OFFLINE,
|
||||
display::ui::theme::text::OUTLINE,
|
||||
display::ui::text::Font{config.hostblock.networks.font.name, config.hostblock.networks.font.size});
|
||||
|
||||
@@ -331,6 +331,18 @@ namespace metrics
|
||||
|
||||
bool Collector::isInterfaceOnline(const std::string &iface)
|
||||
{
|
||||
std::ifstream f("/sys/class/net/" + iface + "/operstate");
|
||||
if (f)
|
||||
{
|
||||
std::string state;
|
||||
f >> state;
|
||||
if (state == "up")
|
||||
return true;
|
||||
if (state != "unknown")
|
||||
return false;
|
||||
}
|
||||
|
||||
// fallback: check IFF_UP
|
||||
int fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0)
|
||||
return false;
|
||||
@@ -340,9 +352,7 @@ namespace metrics
|
||||
|
||||
bool online = false;
|
||||
if (ioctl(fd, SIOCGIFFLAGS, &ifr) == 0)
|
||||
{
|
||||
online = (ifr.ifr_flags & IFF_UP) != 0;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return online;
|
||||
|
||||
Reference in New Issue
Block a user