]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp
Hide or add proper copy ctor and assignement operator, initialize
[stg.git] / projects / stargazer / plugins / capture / cap_nf / cap_nf.cpp
index 3d6c55b5b7139b2ac037db4f25a65266a1dfaa01..9ed507561ddb75e575d3215e0143cc01c921b514 100644 (file)
@@ -54,8 +54,9 @@ return cnc.GetPlugin();
 
 NF_CAP::NF_CAP()
     : traffCnt(NULL),
 
 NF_CAP::NF_CAP()
     : traffCnt(NULL),
-      tidTCP(0),
-      tidUDP(0),
+      settings(),
+      tidTCP(),
+      tidUDP(),
       runningTCP(false),
       runningUDP(false),
       stoppedTCP(true),
       runningTCP(false),
       runningUDP(false),
       stoppedTCP(true),
@@ -63,7 +64,8 @@ NF_CAP::NF_CAP()
       portT(0),
       portU(0),
       sockTCP(-1),
       portT(0),
       portU(0),
       sockTCP(-1),
-      sockUDP(-1)
+      sockUDP(-1),
+      errorStr()
 {
 }
 
 {
 }
 
@@ -248,7 +250,7 @@ socklen_t slen;
 cap->stoppedUDP = false;
 while (cap->runningUDP)
     {
 cap->stoppedUDP = false;
 while (cap->runningUDP)
     {
-    if (!cap->WaitPackets(cap->sockUDP))
+    if (!WaitPackets(cap->sockUDP))
         {
         continue;
         }
         {
         continue;
         }
@@ -291,7 +293,7 @@ socklen_t slen;
 cap->stoppedTCP = false;
 while (cap->runningTCP)
     {
 cap->stoppedTCP = false;
 while (cap->runningTCP)
     {
-    if (!cap->WaitPackets(cap->sockTCP))
+    if (!WaitPackets(cap->sockTCP))
         {
         continue;
         }
         {
         continue;
         }
@@ -312,7 +314,7 @@ while (cap->runningTCP)
         continue;
         }
 
         continue;
         }
 
-    if (!cap->WaitPackets(sd))
+    if (!WaitPackets(sd))
         {
         close(sd);
         continue;
         {
         close(sd);
         continue;
@@ -373,43 +375,15 @@ for (int i = 0; i < packets; ++i)
     {
     NF_DATA * data = reinterpret_cast<NF_DATA *>(buf + 24 + i * 48);
 
     {
     NF_DATA * data = reinterpret_cast<NF_DATA *>(buf + 24 + i * 48);
 
-    ip.header.ipHeader.ip_v = 4;
-    ip.header.ipHeader.ip_hl = 5;
-    ip.header.ipHeader.ip_p = data->proto;
+    ip.rawPacket.header.ipHeader.ip_v = 4;
+    ip.rawPacket.header.ipHeader.ip_hl = 5;
+    ip.rawPacket.header.ipHeader.ip_p = data->proto;
     ip.dataLen = ntohl(data->octets);
     ip.dataLen = ntohl(data->octets);
-    ip.header.ipHeader.ip_src.s_addr = data->srcAddr;
-    ip.header.ipHeader.ip_dst.s_addr = data->dstAddr;
-    ip.header.sPort = data->srcPort;
-    ip.header.dPort = data->dstPort;
+    ip.rawPacket.header.ipHeader.ip_src.s_addr = data->srcAddr;
+    ip.rawPacket.header.ipHeader.ip_dst.s_addr = data->dstAddr;
+    ip.rawPacket.header.sPort = data->srcPort;
+    ip.rawPacket.header.dPort = data->dstPort;
 
     traffCnt->Process(ip);
     }
 }
 
     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;
-}