diff --git a/daemon/yasnd.c b/daemon/yasnd.c index 726daba..030d97c 100644 --- a/daemon/yasnd.c +++ b/daemon/yasnd.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include "yasnd.h" @@ -171,11 +173,34 @@ void check_host(int num,host_decl* host) // Set default signal handlers signal(SIGTERM, SIG_DFL); signal(SIGHUP, SIG_DFL); + // Define temporary variable + char tmp[100]; + // Get host address info from hostname + struct addrinfo hints, *res; + memset(&hints, 0, sizeof(hints)); // - char tmp[50]; + // STUB: need to check IPv6 support for current host here! + // + // prefer any address family(both IPv4 and IPv6) + hints.ai_family = AF_UNSPEC; + if ((getaddrinfo(host->hostname, NULL, &hints, &res)) != 0) + { + sprintf(tmp, "Error: Failed to resolve hostname '%s'", host->hostname); + log_event(tmp); + exit(EXIT_FAILURE); + } sprintf(tmp, "Pinging host %s", host->hostname); log_debug(tmp,DEBUG_BASE); - execl("/bin/ping","/bin/ping","-c 1","-n",host->hostname,(char*) 0); + // host is IPv6 capable? + if (res->ai_family == AF_INET6) + { + execl("/bin/ping6","/bin/ping6","-c 1","-n",host->hostname,(char*) 0); + } + else + // host is IPv4 capable? + { + execl("/bin/ping","/bin/ping","-c 1","-n",host->hostname,(char*) 0); + } // STUB: check result of exec call exit(EXIT_SUCCESS); }