#include <vector>
-#include "common.h"
+#include "stg/common.h"
+#include "stg/raw_ip_packet.h"
+#include "stg/traffcounter.h"
+#include "stg/plugin_creator.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())
- {
- }
-
- ~CAP_NF_CREATOR()
- {
- delete nf;
- }
-
- NF_CAP * GetCapturer() { return nf; }
-private:
- NF_CAP * nf;
-} cnc;
+PLUGIN_CREATOR<NF_CAP> cnc;
PLUGIN * GetPlugin()
{
-return cnc.GetCapturer();
+return cnc.GetPlugin();
}
NF_CAP::NF_CAP()
cap->stoppedUDP = false;
while (cap->runningUDP)
{
- if (!cap->WaitPackets(cap->sockUDP))
+ if (!WaitPackets(cap->sockUDP))
{
continue;
}
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;
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;
-}