#include "pcaprethread.h" PcapReThread::PcapReThread(pcap_t *pcap) : pcap(pcap) { qRegisterMetaType("Resp"); connect(this, &QThread::finished, this, &QThread::deleteLater); connect(this, &PcapReThread::onMsg, this, [](Resp resp, const QByteArray data) { resp.callback(data); }); } void PcapReThread::run() { pcap_pkthdr *header; const u_char *data; int res; while((res = pcap_next_ex(pcap, &header, &data)) >= 0) { if(status==2) return; if(status==1 || res == 0) continue; //超时 if(data[0]!=0x55 || data[1]!=0x55 ) continue; int id = data[2]<<8 | data[3]; { std::lock_guard lock(mtx); for(int i=0; icaplen-4)); break; } } } emit onError(pcap_geterr(pcap)); }