2009-12-26 11:33:27 -06:00
|
|
|
#ifndef _SERVER_PCAP_PORT_H
|
|
|
|
#define _SERVER_PCAP_PORT_H
|
|
|
|
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QThread>
|
|
|
|
#include <pcap.h>
|
|
|
|
|
|
|
|
#include "abstractport.h"
|
2010-01-02 07:49:54 -06:00
|
|
|
#include "pcapextra.h"
|
2009-12-26 11:33:27 -06:00
|
|
|
|
|
|
|
class PcapPort : public AbstractPort
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PcapPort(int id, const char *device);
|
|
|
|
~PcapPort();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
|
|
|
virtual void clearPacketList() {
|
|
|
|
transmitter_->clearPacketList();
|
2010-01-10 00:21:39 -06:00
|
|
|
setPacketListLoopMode(false, 0);
|
2009-12-26 11:33:27 -06:00
|
|
|
}
|
|
|
|
virtual bool appendToPacketList(long sec, long usec, const uchar *packet,
|
|
|
|
int length) {
|
|
|
|
return transmitter_->appendToPacketList(sec, usec, packet, length);
|
|
|
|
}
|
2010-01-10 00:21:39 -06:00
|
|
|
virtual void setPacketListLoopMode(bool loop, long usecDelay) {
|
|
|
|
transmitter_->setPacketListLoopMode(loop, usecDelay);
|
2009-12-26 11:33:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void startTransmit() {
|
|
|
|
if (isDirty())
|
|
|
|
updatePacketList();
|
|
|
|
transmitter_->start();
|
|
|
|
}
|
|
|
|
virtual void stopTransmit() { transmitter_->stop(); }
|
|
|
|
virtual bool isTransmitOn() { return transmitter_->isRunning(); }
|
|
|
|
|
|
|
|
virtual void startCapture() { capturer_->start(); }
|
|
|
|
virtual void stopCapture() { capturer_->stop(); }
|
|
|
|
virtual bool isCaptureOn() { return capturer_->isRunning(); }
|
|
|
|
virtual QIODevice* captureData() { return capturer_->captureFile(); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
enum Direction
|
|
|
|
{
|
|
|
|
kDirectionRx,
|
|
|
|
kDirectionTx
|
|
|
|
};
|
|
|
|
|
|
|
|
class PortMonitor: public QThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PortMonitor(const char *device, Direction direction,
|
|
|
|
AbstractPort::PortStats *stats);
|
|
|
|
void run();
|
|
|
|
pcap_t* handle() { return handle_; }
|
|
|
|
Direction direction() { return direction_; }
|
|
|
|
bool isDirectional() { return isDirectional_; }
|
|
|
|
protected:
|
|
|
|
AbstractPort::PortStats *stats_;
|
|
|
|
private:
|
|
|
|
pcap_t *handle_;
|
|
|
|
Direction direction_;
|
|
|
|
bool isDirectional_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PortTransmitter: public QThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PortTransmitter(const char *device);
|
2010-01-08 09:18:55 -06:00
|
|
|
~PortTransmitter();
|
2009-12-26 11:33:27 -06:00
|
|
|
void clearPacketList();
|
|
|
|
bool appendToPacketList(long sec, long usec, const uchar *packet,
|
|
|
|
int length);
|
2010-01-10 00:21:39 -06:00
|
|
|
void setPacketListLoopMode(bool loop, long usecDelay) {
|
2009-12-26 11:33:27 -06:00
|
|
|
returnToQIdx_ = loop ? 0 : -1;
|
2010-01-10 00:21:39 -06:00
|
|
|
loopDelay_ = usecDelay;
|
2009-12-26 11:33:27 -06:00
|
|
|
}
|
|
|
|
void setHandle(pcap_t *handle);
|
|
|
|
void useExternalStats(AbstractPort::PortStats *stats);
|
|
|
|
void run();
|
|
|
|
void stop();
|
|
|
|
private:
|
2010-01-03 07:57:47 -06:00
|
|
|
void udelay(long usec);
|
2009-12-26 11:33:27 -06:00
|
|
|
int sendQueueTransmit(pcap_t *p, pcap_send_queue *queue, int sync);
|
|
|
|
|
2010-01-03 07:57:47 -06:00
|
|
|
quint64 ticksFreq_;
|
2009-12-26 11:33:27 -06:00
|
|
|
QList<pcap_send_queue*> sendQueueList_;
|
|
|
|
int returnToQIdx_;
|
2010-01-10 00:21:39 -06:00
|
|
|
long loopDelay_;
|
2009-12-26 11:33:27 -06:00
|
|
|
bool usingInternalStats_;
|
|
|
|
AbstractPort::PortStats *stats_;
|
|
|
|
bool usingInternalHandle_;
|
|
|
|
pcap_t *handle_;
|
|
|
|
bool stop_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PortCapturer: public QThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PortCapturer(const char *device);
|
|
|
|
~PortCapturer();
|
|
|
|
void run();
|
|
|
|
void stop();
|
|
|
|
QFile* captureFile();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString device_;
|
|
|
|
bool stop_;
|
|
|
|
QTemporaryFile capFile_;
|
|
|
|
pcap_t *handle_;
|
|
|
|
pcap_dumper_t *dumpHandle_;
|
|
|
|
};
|
|
|
|
|
|
|
|
PortMonitor *monitorRx_;
|
|
|
|
PortMonitor *monitorTx_;
|
|
|
|
private:
|
|
|
|
PortTransmitter *transmitter_;
|
|
|
|
PortCapturer *capturer_;
|
|
|
|
|
|
|
|
static pcap_if_t *deviceList_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|