3 #include <netinet/in.h>
4 #include <linux/netfilter.h>
7 #include "raw_ip_packet.h"
29 IPQ_CAP * GetCapturer()
34 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
41 BASE_PLUGIN * GetPlugin()
43 return icc.GetCapturer();
45 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
48 const string IPQ_CAP::GetVersion() const
50 return "ipq_cap v.1.2";
52 //-----------------------------------------------------------------------------
60 memset(buf, 0, BUFSIZE);
62 //-----------------------------------------------------------------------------
63 void IPQ_CAP::SetTraffcounter(TRAFFCOUNTER * tc)
67 //-----------------------------------------------------------------------------
68 const string & IPQ_CAP::GetStrError() const
72 //-----------------------------------------------------------------------------
79 errorStr = "Cannot open socket!";
80 printfd(__FILE__, "Cannot open socket\n");
84 if (pthread_create(&thread, NULL, Run, this) == 0)
88 errorStr = "Cannot create thread.";
89 printfd(__FILE__, "Cannot create thread\n");
92 //-----------------------------------------------------------------------------
98 //5 seconds to thread stops itself
99 for (int i = 0; i < 25; i++)
105 //after 5 seconds waiting thread still running. now killing it
108 if (pthread_kill(thread, SIGINT))
110 errorStr = "Cannot kill thread.";
113 for (int i = 0; i < 25 && isRunning; ++i)
119 printfd(__FILE__, "Thread not stopped\n");
123 pthread_join(thread, NULL);
129 //-----------------------------------------------------------------------------
130 bool IPQ_CAP::IsRunning()
134 //-----------------------------------------------------------------------------
135 void * IPQ_CAP::Run(void * d)
137 RAW_PACKET raw_packet;
140 IPQ_CAP * dc = (IPQ_CAP *)d;
141 dc->isRunning = true;
142 memset(&raw_packet, 0, sizeof(raw_packet));
143 raw_packet.dataLen = -1;
146 status = dc->IPQCapRead(&raw_packet, 68);
152 dc->traffCnt->Process(raw_packet);
154 dc->isRunning = false;
157 //-----------------------------------------------------------------------------
158 uint16_t IPQ_CAP::GetStartPosition() const
162 //-----------------------------------------------------------------------------
163 uint16_t IPQ_CAP::GetStopPosition() const
167 //-----------------------------------------------------------------------------
168 int IPQ_CAP::IPQCapOpen()
172 ipq_h = ipq_create_handle(0, PF_INET);
175 ipq_destroy_handle(ipq_h);
176 errorStr = "Cannot create ipq handle!";
179 status = ipq_set_mode(ipq_h, IPQ_COPY_PACKET, PAYLOAD_LEN);
182 ipq_destroy_handle(ipq_h);
183 errorStr = "Cannot set IPQ_COPY_PACKET mode!";
188 //-----------------------------------------------------------------------------
189 int IPQ_CAP::IPQCapClose()
191 ipq_destroy_handle(ipq_h);
194 //-----------------------------------------------------------------------------
195 int IPQ_CAP::IPQCapRead(void * buffer, int blen)
198 static ipq_packet_msg_t *m;
200 memset(buf, 0, BUFSIZE);
201 status = ipq_read(ipq_h, buf, BUFSIZE, 1);
208 if (ipq_message_type(buf) != IPQM_PACKET)
210 m = ipq_get_packet(buf);
211 memcpy(buffer, m->payload, blen);
212 ipq_set_verdict(ipq_h, m->packet_id, NF_ACCEPT, 0, NULL);
215 //-----------------------------------------------------------------------------