#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(resps.isEmpty()) continue; { std::lock_guard lock(mtx); if(status==0 && res && data[0]==0x55 && data[1]==0x55) { int id = data[2]<<8 | data[3]; for(int i=0; icaplen)); break; } } auto now = std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count(); for(int i=0; i 0) { auto resp = resps.takeAt(i); resp.timeout = -5; emit onMsg(resp, QByteArray()); } } } emit onError(pcap_geterr(pcap)); }