Fixed windows problem where tx packets are looped back as rx packets also. Also fixed an issue with transmit at slow rate (< 0.5pps)

Fixes issue 46
This commit is contained in:
Srivats P. 2011-10-20 07:13:33 +05:30
parent 626ca8ad0e
commit e5d2ccaa0f
3 changed files with 27 additions and 6 deletions

View File

@ -76,7 +76,7 @@ public:
virtual bool appendToPacketList(long sec, long nsec, const uchar *packet,
int length) = 0;
virtual void setPacketListLoopMode(bool loop,
long secDelay, long nsecDelay) = 0;
quint64 secDelay, quint64 nsecDelay) = 0;
void updatePacketList();
virtual void startTransmit() = 0;

View File

@ -160,23 +160,44 @@ PcapPort::PortMonitor::PortMonitor(const char *device, Direction direction,
{
int ret;
char errbuf[PCAP_ERRBUF_SIZE] = "";
bool noLocalCapture;
direction_ = direction;
isDirectional_ = true;
isPromisc_ = true;
noLocalCapture = true;
stats_ = stats;
_retry:
#ifdef Q_OS_WIN32
int flags = 0;
if (isPromisc_)
flags |= PCAP_OPENFLAG_PROMISCUOUS;
if (noLocalCapture)
flags |= PCAP_OPENFLAG_NOCAPTURE_LOCAL;
handle_ = pcap_open(device, 64 /* FIXME */, flags,
1000 /* ms */, NULL, errbuf);
#else
handle_ = pcap_open_live(device, 64 /* FIXME */, int(isPromisc_),
1000 /* ms */, errbuf);
1000 /* ms */, errbuf);
#endif
if (handle_ == NULL)
{
if (isPromisc_ && QString(errbuf).contains("promiscuous"))
{
qDebug("%s:can't set promiscuous mode, trying non-promisc", device);
qDebug("Can't set promiscuous mode, trying non-promisc %s", device);
isPromisc_ = false;
goto _retry;
}
else if (noLocalCapture && QString(errbuf).contains("loopback"))
{
qDebug("Can't set no local capture mode %s", device);
noLocalCapture = false;
goto _retry;
}
else
goto _open_error;
}

View File

@ -51,7 +51,7 @@ public:
int length) {
return transmitter_->appendToPacketList(sec, nsec, packet, length);
}
virtual void setPacketListLoopMode(bool loop, long secDelay, long nsecDelay)
virtual void setPacketListLoopMode(bool loop, quint64 secDelay, quint64 nsecDelay)
{
transmitter_->setPacketListLoopMode(loop, secDelay, nsecDelay);
}
@ -105,7 +105,7 @@ protected:
long repeatDelaySec, long repeatDelayNsec);
bool appendToPacketList(long sec, long usec, const uchar *packet,
int length);
void setPacketListLoopMode(bool loop, long secDelay, long nsecDelay) {
void setPacketListLoopMode(bool loop, quint64 secDelay, quint64 nsecDelay) {
returnToQIdx_ = loop ? 0 : -1;
loopDelay_ = secDelay*long(1e6) + nsecDelay/1000;
}
@ -174,7 +174,7 @@ protected:
quint64 packetCount_;
int returnToQIdx_;
long loopDelay_;
quint64 loopDelay_;
bool usingInternalStats_;
AbstractPort::PortStats *stats_;