Check if the given ethernet device is in an "up" state by reading linux file(s)
| 41 | // Check if the given ethernet device is in an "up" state by reading linux |
| 42 | // file(s) |
| 43 | static bool check_eth_adapter_up(const std::string& eth_device_name = "eth0") { |
| 44 | const auto filename_operstate = |
| 45 | fmt::format("/sys/class/net/{}/operstate", eth_device_name); |
| 46 | if (!OHDFilesystemUtil::exists(filename_operstate)) return false; |
| 47 | const auto content_opt = OHDFilesystemUtil::opt_read_file(filename_operstate); |
| 48 | if (!content_opt.has_value()) return false; |
| 49 | const auto& content = content_opt.value(); |
| 50 | if (OHDUtil::contains(content, "up")) { |
| 51 | return true; |
| 52 | } |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | // find / get the ip address in the given string with the following layout |
| 57 | // ...(192.168.2.158)... where "192.168.2.158" can be any ip address |
no test coverage detected