- Queued RPC calls would cause crashes due to invalid pointers to request/response and/or controller; this has been fixed - PbRpcController now takes ownership of request and response messages and will delete them when it itself is being deleted - This design mandates that request and response messages for each RPC call have to be allocated on the heap. - The convention for the Closure 'done' call now is to allocate and pass a pointer to the controller object to it which will delete it after use; this requires that controller itself be also allocated on the heap (NOTE: this is just a convention - not mandatory) - All existing RPC calls (in portgroup.cpp) have been changed to follow the above convention - Reordering of queued RPC calls has been fixed - PortManager is now destroyed at exit; because of this fix the per port temporary capture files are auto-removed at exit - WinPcapPort destructor no longer deletes the monitor threads because the parent class PcapPort already does it - Capture does not automatically (and incorrectly) stop after one packet if started immediately after a View Capture operation - User is prompted to stop transmit on a port first if he tries to apply configuration changes on a port in 'transmit' state
131 lines
3.5 KiB
C++
131 lines
3.5 KiB
C++
#ifndef _SERVER_PCAP_PORT_H
|
|
#define _SERVER_PCAP_PORT_H
|
|
|
|
#include <QTemporaryFile>
|
|
#include <QThread>
|
|
#include <pcap.h>
|
|
|
|
#include "abstractport.h"
|
|
#include "pcapextra.h"
|
|
|
|
class PcapPort : public AbstractPort
|
|
{
|
|
public:
|
|
PcapPort(int id, const char *device);
|
|
~PcapPort();
|
|
|
|
void init();
|
|
|
|
virtual bool hasExclusiveControl() { return false; }
|
|
virtual bool setExclusiveControl(bool exclusive) { return false; }
|
|
|
|
virtual void clearPacketList() {
|
|
transmitter_->clearPacketList();
|
|
setPacketListLoopMode(false, 0);
|
|
}
|
|
virtual bool appendToPacketList(long sec, long usec, const uchar *packet,
|
|
int length) {
|
|
return transmitter_->appendToPacketList(sec, usec, packet, length);
|
|
}
|
|
virtual void setPacketListLoopMode(bool loop, long usecDelay) {
|
|
transmitter_->setPacketListLoopMode(loop, usecDelay);
|
|
}
|
|
|
|
virtual void startTransmit() {
|
|
Q_ASSERT(!isDirty());
|
|
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);
|
|
~PortTransmitter();
|
|
void clearPacketList();
|
|
bool appendToPacketList(long sec, long usec, const uchar *packet,
|
|
int length);
|
|
void setPacketListLoopMode(bool loop, long usecDelay) {
|
|
returnToQIdx_ = loop ? 0 : -1;
|
|
loopDelay_ = usecDelay;
|
|
}
|
|
void setHandle(pcap_t *handle);
|
|
void useExternalStats(AbstractPort::PortStats *stats);
|
|
void run();
|
|
void stop();
|
|
private:
|
|
void udelay(long usec);
|
|
int sendQueueTransmit(pcap_t *p, pcap_send_queue *queue, int sync);
|
|
|
|
quint64 ticksFreq_;
|
|
QList<pcap_send_queue*> sendQueueList_;
|
|
int returnToQIdx_;
|
|
long loopDelay_;
|
|
bool usingInternalStats_;
|
|
AbstractPort::PortStats *stats_;
|
|
bool usingInternalHandle_;
|
|
pcap_t *handle_;
|
|
volatile bool stop_;
|
|
};
|
|
|
|
class PortCapturer: public QThread
|
|
{
|
|
public:
|
|
PortCapturer(const char *device);
|
|
~PortCapturer();
|
|
void run();
|
|
void stop();
|
|
QFile* captureFile();
|
|
|
|
private:
|
|
QString device_;
|
|
volatile bool stop_;
|
|
QTemporaryFile capFile_;
|
|
pcap_t *handle_;
|
|
pcap_dumper_t *dumpHandle_;
|
|
};
|
|
|
|
PortMonitor *monitorRx_;
|
|
PortMonitor *monitorTx_;
|
|
|
|
void updateNotes();
|
|
|
|
private:
|
|
PortTransmitter *transmitter_;
|
|
PortCapturer *capturer_;
|
|
|
|
static pcap_if_t *deviceList_;
|
|
};
|
|
|
|
#endif
|