Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

Added cleanup functions

Andrei Vladescu0f83e79f02b5
diff --git a/src/Services/ICMPService.cpp b/src/Services/ICMPService.cpp
index 95b887f9..14ff936f 100644
--- a/src/Services/ICMPService.cpp
+++ b/src/Services/ICMPService.cpp
@@ -25,6 +25,20 @@ struct ICMPTaskParams
ICMPService::ICMPService() {}
+ICMPService::~ICMPService() {
+ cleanupICMPService();
+}
+
+void ICMPService::cleanupICMPService(){
+ // Reset last results
+ ready = false;
+ ping_up = false;
+ ping_median_ms = -1;
+ ping_sent = 0;
+ ping_recv = 0;
+ report.clear();
+}
+
static bool resolve_ipv4_to_ip_addr(const std::string &host, ip_addr_t &out)
{
// literal first
@@ -60,14 +74,9 @@ static int median_ms(std::vector<uint32_t> &v)
void ICMPService::startPingTask(const std::string &host, int count, int timeout_ms, int interval_ms)
{
- // Reset last results
- ready = false;
- ping_up = false;
- ping_median_ms = -1;
- ping_sent = 0;
- ping_recv = 0;
- report.clear();
-
+ // Cleanup first
+ this->cleanupICMPService();
+
auto *params = new ICMPTaskParams{host,
count > 0 ? count : 5,
timeout_ms > 0 ? timeout_ms : 1000,
diff --git a/src/Services/ICMPService.h b/src/Services/ICMPService.h
index b26eb813..2a3c1c49 100644
--- a/src/Services/ICMPService.h
+++ b/src/Services/ICMPService.h
@@ -4,15 +4,16 @@
class ICMPService {
public:
ICMPService();
+ ~ICMPService();
void startPingTask(const std::string& host, int count = 5, int timeout_ms = 1000, int interval_ms = 200);
// Results
bool isReady() const { return ready; }
bool lastPingUp() const { return ping_up; }
- int lastMedianMs() const { return ping_median_ms; }
- int lastSent() const { return ping_sent; }
- int lastRecv() const { return ping_recv; }
+ int lastMedianMs() const { return ping_median_ms; }
+ int lastSent() const { return ping_sent; }
+ int lastRecv() const { return ping_recv; }
const std::string& getReport() const { return report; }
// Task entry
@@ -25,4 +26,6 @@ private:
int ping_sent = 0;
int ping_recv = 0;
std::string report;
+
+ void cleanupICMPService();
};