2 #include <netinet/in.h>
3 #include <linux/netfilter.h>
6 #include "raw_ip_packet.h"
17 printf("constructor IPQ_CAP_CREATOR\n");
22 printf("destructor IPQ_CAP_CREATOR\n");
27 BASE_PLUGIN * GetCapturer()
32 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
39 BASE_PLUGIN * GetPlugin()
41 return icc.GetCapturer();
43 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
46 const string IPQ_CAP::GetVersion() const
48 return "ipq_cap v.1.1";
50 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
57 void IPQ_CAP::SetTraffcounter(TRAFFCOUNTER * tc)
61 //-----------------------------------------------------------------------------
62 const string & IPQ_CAP::GetStrError() const
66 //-----------------------------------------------------------------------------
71 printfd(__FILE__, "IPQ_CAP::Start()\n");
74 errorStr = "Cannot open socket!";
78 if (pthread_create(&thread, NULL, Run, this) == 0)
82 errorStr = "Cannot create thread.";
85 //-----------------------------------------------------------------------------
92 //5 seconds to thread stops itself
93 for (int i = 0; i < 25; i++)
99 //after 5 seconds waiting thread still running. now killing it
102 if (pthread_kill(thread, SIGINT))
104 errorStr = "Cannot kill thread.";
110 //-----------------------------------------------------------------------------
111 bool IPQ_CAP::IsRunning()
115 //-----------------------------------------------------------------------------
116 void * IPQ_CAP::Run(void * d)
118 RAW_PACKET raw_packet;
122 IPQ_CAP * dc = (IPQ_CAP *)d;
123 dc->isRunning = true;
124 memset(&raw_packet, 0, sizeof(raw_packet));
125 raw_packet.dataLen = -1;
128 status=dc->IPQCapRead(&raw_packet, 68);
129 if(status==-1||status==-2)
131 dc->traffCnt->Process(raw_packet);
133 dc->isRunning = false;
136 //-----------------------------------------------------------------------------
137 uint16_t IPQ_CAP::GetStartPosition() const
141 //-----------------------------------------------------------------------------
142 uint16_t IPQ_CAP::GetStopPosition() const
146 //-----------------------------------------------------------------------------
147 int IPQ_CAP::IPQCapOpen()
151 ipq_h = ipq_create_handle(0, PF_INET);
154 ipq_destroy_handle(ipq_h);
155 errorStr = "Cannot create ipq handle!";
158 status = ipq_set_mode(ipq_h, IPQ_COPY_PACKET, PAYLOAD_LEN);
161 ipq_destroy_handle(ipq_h);
162 errorStr = "Cannot set IPQ_COPY_PACKET mode!";
167 //-----------------------------------------------------------------------------
168 int IPQ_CAP::IPQCapClose()
170 ipq_destroy_handle(ipq_h);
173 //-----------------------------------------------------------------------------
174 int IPQ_CAP::IPQCapRead(void * buffer, int blen)
177 static ipq_packet_msg_t *m;
179 memset(buf, 0, BUFSIZE);
180 status = ipq_read(ipq_h, buf, BUFSIZE, 0);
183 if (ipq_message_type(buf) != IPQM_PACKET)
185 m = ipq_get_packet(buf);
186 memcpy(buffer, m->payload, blen);
187 ipq_set_verdict(ipq_h, m->packet_id, NF_ACCEPT, 0, NULL);
190 //-----------------------------------------------------------------------------