X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/641204dfbdb9fc870cdd2e7f9e3169a44693e7bf..79c8c4ef19419fd58a7aab7efd6a299b295e55b3:/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp diff --git a/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp b/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp index 799e399d..0ba91bbb 100644 --- a/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp +++ b/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp @@ -28,18 +28,24 @@ $Date: 2009/03/19 20:03:35 $ $Author: faust $ */ -#include +#include "debug_cap.h" + +#include "libpal.h" + +#include "stg/plugin_creator.h" +#include "stg/traffcounter.h" +#include "stg/common.h" + +#include +#include + #include -#include #include -#include #include #include #include -#include "debug_cap.h" -#include "../../../traffcounter.h" -#include "libpal.h" +extern volatile time_t stgTime; //----------------------------------------------------------------------------- void WriteStat(uint32_t u, uint32_t d) @@ -53,55 +59,41 @@ fprintf(f, "up %5.2f Mbit, down %5.2f Mbit, sum %5.2f Mbit\n", fclose(f); } //----------------------------------------------------------------------------- - -class CAP_DEBUG_CREATOR -{ -private: - DEBUG_CAP * dc; - -public: - CAP_DEBUG_CREATOR() - : dc(new DEBUG_CAP()) - { - }; - ~CAP_DEBUG_CREATOR() - { - delete dc; - }; - - DEBUG_CAP * GetCapturer() - { - return dc; - }; -}; -//----------------------------------------------------------------------------- -RAW_PACKET MakeTCPPacket(const char * src, - const char * dst, - uint16_t sport, - uint16_t dport, - uint16_t len); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -CAP_DEBUG_CREATOR cdc; +namespace +{ +PLUGIN_CREATOR cdc; +} + +extern "C" PLUGIN * GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -BASE_PLUGIN * GetPlugin() +PLUGIN * GetPlugin() { -return cdc.GetCapturer(); +return cdc.GetPlugin(); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -const string DEBUG_CAP::GetVersion() const + +//----------------------------------------------------------------------------- +RAW_PACKET MakeTCPPacket(const char * src, + const char * dst, + uint16_t sport, + uint16_t dport, + uint16_t len); +std::string DEBUG_CAP::GetVersion() const { -return "Debug_cap v.0.01a"; +return "cap_debug v.0.01a"; } //----------------------------------------------------------------------------- DEBUG_CAP::DEBUG_CAP() + : nonstop(false), + isRunning(false), + traffCnt(NULL) { -isRunning = false; -nonstop = false; } //----------------------------------------------------------------------------- void DEBUG_CAP::SetTraffcounter(TRAFFCOUNTER * tc) @@ -109,7 +101,7 @@ void DEBUG_CAP::SetTraffcounter(TRAFFCOUNTER * tc) traffCnt = tc; } //----------------------------------------------------------------------------- -const string & DEBUG_CAP::GetStrError() const +const std::string & DEBUG_CAP::GetStrError() const { return errorStr; } @@ -146,7 +138,7 @@ for (i = 0; i < 25; i++) if (!isRunning) break; - stgUsleep(200000); + usleep(200000); //printf("."); } @@ -176,7 +168,7 @@ void * DEBUG_CAP::Run1(void * data) { printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid()); -DEBUG_CAP * dc = (DEBUG_CAP *)data; +DEBUG_CAP * dc = static_cast(data); dc->isRunning = true; RAW_PACKET rp; @@ -197,24 +189,20 @@ int dsize; t = stgTime; tm = localtime(&t); int min = tm->tm_min; -int sec = tm->tm_sec; char cliIP[20]; char srvIP[20]; -char trashIP1[20]; -char trashIP2[20]; while (dc->nonstop) { for (int i = 8; i <= 252; i++) { - usize = random()%100 + 100; - dsize = random()%500 + 900; - + dsize = random()%500 + 900; + for (int j = 2; j < 11; j++) { - sprintf(cliIP, "192.168.%d.%d", j, i); + sprintf(cliIP, "192.168.%d.%d", j, i); sprintf(srvIP, "10.1.%d.%d", random()%8, 1); rp = MakeTCPPacket(srvIP, cliIP, 80, random()%2 + 2000, dsize); @@ -249,7 +237,7 @@ void * DEBUG_CAP::Run2(void * data) { printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid()); -DEBUG_CAP * dc = (DEBUG_CAP *)data; +DEBUG_CAP * dc = static_cast(data); dc->isRunning = true; RAW_PACKET rp; @@ -329,7 +317,7 @@ void * DEBUG_CAP::Run3(void * data) { printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid()); -DEBUG_CAP * dc = (DEBUG_CAP *)data; +DEBUG_CAP * dc = static_cast(data); dc->isRunning = true; RAW_PACKET rp; @@ -337,7 +325,6 @@ rp = MakeTCPPacket("192.168.1.1", "192.168.1.21", 255, 255, 200); int a = 0; sleep(3); -struct tm * tm; time_t t; uint32_t u = 0; uint32_t d = 0; @@ -348,7 +335,6 @@ int usize = 200; int dsize = 1500; t = stgTime; -tm = localtime(&t); char cliIP[20]; char srvIP1[20]; @@ -453,12 +439,12 @@ return NULL; //----------------------------------------------------------------------------- uint16_t DEBUG_CAP::GetStartPosition() const { -return 0; +return 40; } //----------------------------------------------------------------------------- uint16_t DEBUG_CAP::GetStopPosition() const { -return 0; +return 40; } //----------------------------------------------------------------------------- RAW_PACKET MakeTCPPacket(const char * src, @@ -511,7 +497,6 @@ if (pkt_free(&pkt)) printfd(__FILE__, "pkt_free error!\n"); } rp.dataLen = -1; -strcpy(rp.iface, "eth0"); return rp; } //-----------------------------------------------------------------------------