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:
parent
626ca8ad0e
commit
e5d2ccaa0f
@ -76,7 +76,7 @@ public:
|
|||||||
virtual bool appendToPacketList(long sec, long nsec, const uchar *packet,
|
virtual bool appendToPacketList(long sec, long nsec, const uchar *packet,
|
||||||
int length) = 0;
|
int length) = 0;
|
||||||
virtual void setPacketListLoopMode(bool loop,
|
virtual void setPacketListLoopMode(bool loop,
|
||||||
long secDelay, long nsecDelay) = 0;
|
quint64 secDelay, quint64 nsecDelay) = 0;
|
||||||
void updatePacketList();
|
void updatePacketList();
|
||||||
|
|
||||||
virtual void startTransmit() = 0;
|
virtual void startTransmit() = 0;
|
||||||
|
@ -160,23 +160,44 @@ PcapPort::PortMonitor::PortMonitor(const char *device, Direction direction,
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char errbuf[PCAP_ERRBUF_SIZE] = "";
|
char errbuf[PCAP_ERRBUF_SIZE] = "";
|
||||||
|
bool noLocalCapture;
|
||||||
|
|
||||||
direction_ = direction;
|
direction_ = direction;
|
||||||
isDirectional_ = true;
|
isDirectional_ = true;
|
||||||
isPromisc_ = true;
|
isPromisc_ = true;
|
||||||
|
noLocalCapture = true;
|
||||||
stats_ = stats;
|
stats_ = stats;
|
||||||
|
|
||||||
_retry:
|
_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_),
|
handle_ = pcap_open_live(device, 64 /* FIXME */, int(isPromisc_),
|
||||||
1000 /* ms */, errbuf);
|
1000 /* ms */, errbuf);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (handle_ == NULL)
|
if (handle_ == NULL)
|
||||||
{
|
{
|
||||||
if (isPromisc_ && QString(errbuf).contains("promiscuous"))
|
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;
|
isPromisc_ = false;
|
||||||
goto _retry;
|
goto _retry;
|
||||||
}
|
}
|
||||||
|
else if (noLocalCapture && QString(errbuf).contains("loopback"))
|
||||||
|
{
|
||||||
|
qDebug("Can't set no local capture mode %s", device);
|
||||||
|
noLocalCapture = false;
|
||||||
|
goto _retry;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
goto _open_error;
|
goto _open_error;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public:
|
|||||||
int length) {
|
int length) {
|
||||||
return transmitter_->appendToPacketList(sec, nsec, packet, 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);
|
transmitter_->setPacketListLoopMode(loop, secDelay, nsecDelay);
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ protected:
|
|||||||
long repeatDelaySec, long repeatDelayNsec);
|
long repeatDelaySec, long repeatDelayNsec);
|
||||||
bool appendToPacketList(long sec, long usec, const uchar *packet,
|
bool appendToPacketList(long sec, long usec, const uchar *packet,
|
||||||
int length);
|
int length);
|
||||||
void setPacketListLoopMode(bool loop, long secDelay, long nsecDelay) {
|
void setPacketListLoopMode(bool loop, quint64 secDelay, quint64 nsecDelay) {
|
||||||
returnToQIdx_ = loop ? 0 : -1;
|
returnToQIdx_ = loop ? 0 : -1;
|
||||||
loopDelay_ = secDelay*long(1e6) + nsecDelay/1000;
|
loopDelay_ = secDelay*long(1e6) + nsecDelay/1000;
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ protected:
|
|||||||
quint64 packetCount_;
|
quint64 packetCount_;
|
||||||
|
|
||||||
int returnToQIdx_;
|
int returnToQIdx_;
|
||||||
long loopDelay_;
|
quint64 loopDelay_;
|
||||||
|
|
||||||
bool usingInternalStats_;
|
bool usingInternalStats_;
|
||||||
AbstractPort::PortStats *stats_;
|
AbstractPort::PortStats *stats_;
|
||||||
|
Loading…
Reference in New Issue
Block a user