MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / check_eth_adapter_up

Function check_eth_adapter_up

OpenHD/ohd_interface/src/ethernet_manager.cpp:43–54  ·  view source on GitHub ↗

Check if the given ethernet device is in an "up" state by reading linux file(s)

Source from the content-addressed store, hash-verified

41// Check if the given ethernet device is in an "up" state by reading linux
42// file(s)
43static 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

Calls 1

containsFunction · 0.85

Tested by

no test coverage detected