diff --git a/include/Ntop.h b/include/Ntop.h index ddec59d7b1..de1b3e637e 100644 --- a/include/Ntop.h +++ b/include/Ntop.h @@ -87,7 +87,7 @@ class Ntop { FifoStringsQueue *sqlite_alerts_queue, *alerts_notifications_queue; FifoSerializerQueue *internal_alerts_queue; #ifndef WIN32 - ContinuousPing cping; + ContinuousPing *cping; #endif #ifdef __linux__ @@ -490,7 +490,7 @@ class Ntop { ndpi_protocol_category_t get_ndpi_proto_category(u_int protoid); void setnDPIProtocolCategory(u_int16_t protoId, ndpi_protocol_category_t protoCategory); inline void reloadPeriodicScripts() { if(pa) pa->reloadVMs(); }; - inline ContinuousPing* getContinuousPing() { return(&cping); } + inline ContinuousPing* getContinuousPing() { return(cping); } }; extern Ntop *ntop; diff --git a/src/ContinuousPing.cpp b/src/ContinuousPing.cpp index 55f6c621d6..3b5a7798ff 100644 --- a/src/ContinuousPing.cpp +++ b/src/ContinuousPing.cpp @@ -182,6 +182,11 @@ void ContinuousPing::collectResponses(lua_State* vm) { /* ***************************************** */ void ContinuousPing::runPingCampaign() { + if(!ntop->isStarted()) { + sleep(1); + return; + } + try { Ping *pinger = new Ping(); diff --git a/src/LuaEngineNtop.cpp.inc b/src/LuaEngineNtop.cpp.inc index a1e2c0f2c0..56b8e98f21 100644 --- a/src/LuaEngineNtop.cpp.inc +++ b/src/LuaEngineNtop.cpp.inc @@ -1533,7 +1533,14 @@ static int ntop_ping_host(lua_State* vm) { getLuaVMUservalue(vm, ping)->ping(host, is_v6); } else { /* This is a continuous ping */ - ntop->getContinuousPing()->ping(host, is_v6); + ContinuousPing *c = ntop->getContinuousPing(); + + if(c) + c->ping(host, is_v6); + else { + lua_pushnil(vm); + return(CONST_LUA_PARAM_ERROR); + } } return(CONST_LUA_OK); diff --git a/src/Ntop.cpp b/src/Ntop.cpp index 7f87043283..58e4fc21b5 100644 --- a/src/Ntop.cpp +++ b/src/Ntop.cpp @@ -77,7 +77,8 @@ Ntop::Ntop(char *appName) { malicious_ja3 = malicious_ja3_shadow = NULL; new_malicious_ja3 = new std::set(); system_interface = NULL; - + cping = NULL; + /* nDPI handling */ last_ndpi_reload = 0; ndpi_struct_shadow = NULL; @@ -253,7 +254,8 @@ Ntop::~Ntop() { if(system_interface) delete system_interface; if(extract) delete extract; - if(udp_socket != -1) closesocket(udp_socket); + if(cping) delete cping; + if(udp_socket != -1) closesocket(udp_socket); if(trackers_automa) ndpi_free_automa(trackers_automa); if(custom_ndpi_protos) free(custom_ndpi_protos);