| 326 | } |
| 327 | |
| 328 | bool 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 | |
| 352 | std::string find_device_ip_gnd() { |
| 353 | auto ip_addresses = get_ip_addresses(MICROHARD_IP_RANGE); |
no outgoing calls
no test coverage detected