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

Function get_gateway_ip

OpenHD/ohd_interface/src/microhard_link.cpp:301–326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

299}
300
301std::string get_gateway_ip() {
302 std::string cmd =
303 "ip route show default | awk '/default/ {print $3}' | grep "
304 "'^192\\.168\\.168'";
305 FILE* pipe = popen(cmd.c_str(), "r");
306 if (!pipe) {
307 openhd::log::get_default()->warn("Failed to run command: {}", cmd.c_str());
308 throw std::runtime_error("Failed to run command.");
309 }
310
311 char buffer[128];
312 std::string result;
313 if (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
314 result = buffer;
315 }
316 pclose(pipe);
317
318 // Trim trailing newline
319 if (!result.empty()) {
320 result.erase(result.find_last_not_of("\n\r") + 1);
321 }
322
323 openhd::log::get_default()->warn("Filtered Gateway IP: {}", result.c_str());
324
325 return result;
326}
327
328bool check_ip_alive(const std::string& ip, int port = 23) {
329 openhd::log::get_default()->warn("Checking if IP {} is alive on port {}", ip,

Callers 3

log_ip_addressesFunction · 0.85
MicrohardLinkMethod · 0.85

Calls 1

eraseMethod · 0.80

Tested by

no test coverage detected