class SnifferThread
: public QThread{
Q_OBJECT;
signals:
void signalPacketReceived(uint8* pData, uint32 pDataLength, uint32 pOrd);
slots:
void sniffOnePacket();
//...
private:
};
void SnifferThread::run()
{
pcapfp_ = pcap_open_live(itf.c_str(), PCAP_MAX_NB_BYTE, 1, -1, errorBuffer);
connect(&m_timer,SIGNAL(timeout()),this,SLOT(sniffOnePacket()));
m_timer.start(20);
exec();
disconnect(&m_timer,SIGNAL(timeout()),this,SLOT(sniffOnePacket()));
}
void SnifferThread::sniffOnePacket()
{
pcap_pkthdr pktHeader;
if(canSniff_)
{
isSniffing_ = true;
const uint8* data = pcap_next(pcapfp_, &pktHeader);
if ( data != 0 )
{
// ...
emit signalPacketReceived(buffer, bufSize, ++frameNumber_);
}
}
}
class SnifferThread : public QThread
{
Q_OBJECT;
signals:
void signalPacketReceived(uint8* pData, uint32 pDataLength, uint32 pOrd);
slots:
void sniffOnePacket();
//...
private:
QTimer m_timer;
};
void SnifferThread::run()
{
pcapfp_ = pcap_open_live(itf.c_str(), PCAP_MAX_NB_BYTE, 1, -1, errorBuffer);
connect(&m_timer,SIGNAL(timeout()),this,SLOT(sniffOnePacket()));
m_timer.start(20);
exec();
disconnect(&m_timer,SIGNAL(timeout()),this,SLOT(sniffOnePacket()));
}
void SnifferThread::sniffOnePacket()
{
pcap_pkthdr pktHeader;
if(canSniff_)
{
isSniffing_ = true;
const uint8* data = pcap_next(pcapfp_, &pktHeader);
if ( data != 0 )
{
// ...
emit signalPacketReceived(buffer, bufSize, ++frameNumber_);
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks