Home > Back-end >  Qt and problems arising from the winpcap
Qt and problems arising from the winpcap

Time:10-26

Qt/c + + : winpcap to filter packets, I have two ideas:
1. Call pcap_loop, but the third parameter of pcap_loop (i.e., a function pointer), cannot be set as ordinary member function of a class, but if the static member functions, and inevitably need to put the other data members are also set to static members, destroyed the encapsulation
2. A new thread invokes the pcap_next_ex, but at the time of subclassing QThread, need to pass multiple parameters, is passed in the QThread, or in which the function, I wonder if you have any good Suggestions, thanks in advance!

Another question is: must call pcap_setmode and pcap_loop call together? In a piece of code, I dropped my pcap_setmode comments, print out the IP is normal (in pcap_next_ex implementation), but when I call, after pcap_setmode programs allow IP is 0.0, 0, 0
What reason is this?

U_long netmask.
Netmask=((struct sockaddr_in *) (addr - & gt; Netmask)) - & gt; Sin_addr. S_addr;

Struct bpf_program fcode;
//if (pcap_compile (m_curSes, & amp; Fcode, m_strFilter. C_str (), 1, netmask) & lt; 0)
If (pcap_compile (m_curSes, & amp; Fcode, "IP", 1, netmask) & lt; 0)
{
return false;
}

If (pcap_setfilter (m_curSes, & amp; Fcode)==1)
{
return false;
}

If (pcap_setmode (m_curSes MODE_STAT) & lt; 0)
{
return false;
}

The capture ();
  • Related