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

Function check_ip_alive

OpenHD/ohd_interface/src/microhard_link.cpp:328–350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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,
330 port);
331
332 int sockfd = socket(AF_INET, SOCK_STREAM, 0);
333 if (sockfd < 0) {
334 openhd::log::get_default()->warn("Failed to create socket for IP check: {}",
335 ip);
336 return false;
337 }
338
339 struct sockaddr_in addr = {AF_INET, htons(port), inet_addr(ip.c_str())};
340 bool connected = connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)) == 0;
341 close(sockfd);
342
343 if (connected) {
344 openhd::log::get_default()->warn("IP {} is alive", ip);
345 } else {
346 openhd::log::get_default()->warn("IP {} is not alive", ip);
347 }
348
349 return connected;
350}
351
352std::string find_device_ip_gnd() {
353 auto ip_addresses = get_ip_addresses(MICROHARD_IP_RANGE);

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected