Parcourir la source

Don't detach sniffer threads anymore

Jonas Pflanzer il y a 5 ans
Parent
commit
7e041f2cb1

+ 22 - 0
daemon/include/CovertChannel/CovertChannel.h

@@ -1,6 +1,7 @@
 #ifndef COVERTCHANNEL_H
 #define COVERTCHANNEL_H
 
+#include <thread>
 #include <tins/tins.h>
 
 /**
@@ -154,6 +155,27 @@ protected:
 	 * Tins PacketSender which sends packets to the outer network
 	 */
 	Tins::PacketSender outerSender;
+
+private:
+	/**
+	 * Thread for the inner forward sniffer
+	 */
+	std::thread innerForwardSnifferThread;
+
+	/**
+	 * Thread for the outer forward sniffer
+	 */
+	std::thread outerForwardSnifferThread;
+
+	/**
+	 * Thread for the inner channel sniffer
+	 */
+	std::thread innerChannelSnifferThread;
+
+	/**
+	 * Thread for the outer channel sniffer
+	 */
+	std::thread outerChannelSnifferThread;
 };
 
 #endif

+ 8 - 10
daemon/src/CovertChannel/CovertChannel.cpp

@@ -1,7 +1,6 @@
 #include "../../include/CovertChannel/CovertChannel.h"
 #include <cstdlib>
 #include <iostream>
-#include <thread>
 
 CovertChannel::CovertChannel(const std::string &innerInterface, const std::string &outerInterface, const std::string &innerForwardFilter,
                              const std::string &outerForwardFilter, const std::string &innerChannelFilter, const std::string &outerChannelFilter)
@@ -30,6 +29,10 @@ CovertChannel::~CovertChannel() {
 	outerForwardSniffer->stop_sniff();
 	innerChannelSniffer->stop_sniff();
 	outerChannelSniffer->stop_sniff();
+	innerForwardSnifferThread.join();
+	outerForwardSnifferThread.join();
+	innerChannelSnifferThread.join();
+	outerChannelSnifferThread.join();
 	delete (innerForwardSniffer);
 	delete (outerForwardSniffer);
 	delete (innerChannelSniffer);
@@ -45,15 +48,10 @@ void CovertChannel::setFilter(const std::string &innerForwardFilter, const std::
 }
 
 void CovertChannel::startSniffing() {
-	std::thread innerForwardSnifferThread(&CovertChannel::startInnerForwardSniffing, this);
-	std::thread outerForwardSnifferThread(&CovertChannel::startOuterForwardSniffing, this);
-	std::thread innerChannelSnifferThread(&CovertChannel::startInnerChannelSniffing, this);
-	std::thread outerChannelSnifferThread(&CovertChannel::startOuterChannelSniffing, this);
-
-	innerForwardSnifferThread.detach();
-	outerForwardSnifferThread.detach();
-	innerChannelSnifferThread.detach();
-	outerChannelSnifferThread.detach();
+	innerForwardSnifferThread = std::thread(&CovertChannel::startInnerForwardSniffing, this);
+	outerForwardSnifferThread = std::thread(&CovertChannel::startOuterForwardSniffing, this);
+	innerChannelSnifferThread = std::thread(&CovertChannel::startInnerChannelSniffing, this);
+	outerChannelSnifferThread = std::thread(&CovertChannel::startOuterChannelSniffing, this);
 }
 
 void CovertChannel::startInnerForwardSniffing() { innerForwardSniffer->sniff_loop(make_sniffer_handler(this, &CovertChannel::handleForwardFromInner)); }