#include <cerrno>
#include <cstring>
-#include "common.h"
-#include "cap_nf.h"
-#include "raw_ip_packet.h"
-
-#include "../../../traffcounter.h"
-
-class CAP_NF_CREATOR
-{
-public:
- CAP_NF_CREATOR()
- : nf(new NF_CAP())
- {
- };
+#include <vector>
- ~CAP_NF_CREATOR()
- {
- delete nf;
- };
+#include "stg/common.h"
+#include "stg/raw_ip_packet.h"
+#include "stg/traffcounter.h"
+#include "stg/plugin_creator.h"
+#include "cap_nf.h"
- NF_CAP * GetCapturer() { return nf; };
-private:
- NF_CAP * nf;
-} cnc;
+PLUGIN_CREATOR<NF_CAP> cnc;
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
-return cnc.GetCapturer();
+return cnc.GetPlugin();
}
NF_CAP::NF_CAP()
int NF_CAP::ParseSettings()
{
-vector<PARAM_VALUE>::iterator it;
+std::vector<PARAM_VALUE>::iterator it;
for (it = settings.moduleParams.begin(); it != settings.moduleParams.end(); ++it)
{
if (it->param == "TCPPort")
cap->stoppedUDP = false;
while (cap->runningUDP)
{
- if (!cap->WaitPackets(cap->sockUDP))
+ if (!WaitPackets(cap->sockUDP))
{
continue;
}
continue;
}
-
- // Wrong logic!
- // Need to check actual data length and wait all data to receive
if (res < 24)
{
if (errno != EINTR)
cap->stoppedTCP = false;
while (cap->runningTCP)
{
- if (!cap->WaitPackets(cap->sockTCP))
+ if (!WaitPackets(cap->sockTCP))
{
continue;
}
continue;
}
- if (!cap->WaitPackets(sd))
+ if (!WaitPackets(sd))
{
close(sd);
continue;
{
NF_DATA * data = reinterpret_cast<NF_DATA *>(buf + 24 + i * 48);
- /*ip.pckt[0] = 4 << 4;
- ip.pckt[0] |= 5;
- ip.pckt[9] = data->proto;
- ip.dataLen = ntohl(data->octets);
- *(uint32_t *)(ip.pckt + 12) = data->srcAddr;
- *(uint32_t *)(ip.pckt + 16) = data->dstAddr;
- *(uint16_t *)(ip.pckt + 20) = data->srcPort;
- *(uint16_t *)(ip.pckt + 22) = data->dstPort;*/
ip.header.ipHeader.ip_v = 4;
ip.header.ipHeader.ip_hl = 5;
ip.header.ipHeader.ip_p = data->proto;
traffCnt->Process(ip);
}
}
-
-bool NF_CAP::WaitPackets(int sd) const
-{
-fd_set rfds;
-FD_ZERO(&rfds);
-FD_SET(sd, &rfds);
-
-struct timeval tv;
-tv.tv_sec = 0;
-tv.tv_usec = 500000;
-
-int res = select(sd + 1, &rfds, NULL, NULL, &tv);
-if (res == -1) // Error
- {
- if (errno != EINTR)
- {
- printfd(__FILE__, "Error on select: '%s'\n", strerror(errno));
- }
- return false;
- }
-
-if (res == 0) // Timeout
- {
- return false;
- }
-
-return true;
-}