Use base class link state in case of Win intf stats
After this change adapter_ and linkStateOid_ members are no longer required in case of Windows Interface stats, so don't initialize them. Also remove all references to them in ifstats mode - the change in has/setExclusiveControl also fixes the non-working bindconfig - the problem was the portname being derived in those functions was not correct causing bindconfig to fail - bindconfig itself probably never had a problem.
This commit is contained in:
parent
e5375247a9
commit
f27003b8f5
@ -109,7 +109,8 @@ void PcapPort::updateNotes()
|
||||
{
|
||||
QString notes;
|
||||
|
||||
if ((!monitorRx_->isPromiscuous()) || (!monitorTx_->isPromiscuous()))
|
||||
if ((monitorRx_ && monitorTx_)
|
||||
&& (!monitorRx_->isPromiscuous() || !monitorTx_->isPromiscuous()))
|
||||
notes.append("<li>Non Promiscuous Mode</li>");
|
||||
|
||||
if (!monitorRx_->isDirectional() && !hasExclusiveControl())
|
||||
|
@ -76,13 +76,15 @@ WinPcapPort::WinPcapPort(int id, const char *device, const char *description)
|
||||
data_.set_description(description);
|
||||
|
||||
// XXX: luid_ is already populated by populateInterfaceInfo() call above
|
||||
adapter_ = PacketOpenAdapter((CHAR*)device);
|
||||
if (!adapter_)
|
||||
qFatal("Unable to open adapter %s", device);
|
||||
linkStateOid_ = (PPACKET_OID_DATA) malloc(sizeof(PACKET_OID_DATA) +
|
||||
sizeof(NDIS_LINK_STATE));
|
||||
if (!linkStateOid_)
|
||||
qFatal("failed to alloc oidData");
|
||||
if (internalPortStats_) {
|
||||
adapter_ = PacketOpenAdapter((CHAR*)device);
|
||||
if (!adapter_)
|
||||
qFatal("Unable to open adapter %s", device);
|
||||
linkStateOid_ = (PPACKET_OID_DATA) malloc(sizeof(PACKET_OID_DATA) +
|
||||
sizeof(NDIS_LINK_STATE));
|
||||
if (!linkStateOid_)
|
||||
qFatal("failed to alloc oidData");
|
||||
}
|
||||
|
||||
data_.set_is_exclusive_control(hasExclusiveControl());
|
||||
minPacketSetSize_ = 256;
|
||||
@ -125,6 +127,12 @@ void WinPcapPort::init()
|
||||
|
||||
OstProto::LinkState WinPcapPort::linkState()
|
||||
{
|
||||
if (!internalPortStats_)
|
||||
return AbstractPort::linkState();
|
||||
|
||||
assert(adapter_);
|
||||
assert(linkStateOid_);
|
||||
|
||||
memset(linkStateOid_, 0, sizeof(PACKET_OID_DATA) + sizeof(NDIS_LINK_STATE));
|
||||
|
||||
linkStateOid_->Oid = OID_GEN_LINK_STATE;
|
||||
@ -162,7 +170,7 @@ OstProto::LinkState WinPcapPort::linkState()
|
||||
|
||||
bool WinPcapPort::hasExclusiveControl()
|
||||
{
|
||||
QString portName(adapter_->Name + strlen("\\Device\\NPF_"));
|
||||
QString portName(name() + strlen("\\Device\\NPF_"));
|
||||
QString bindConfigFilePath(QCoreApplication::applicationDirPath()
|
||||
+ "/bindconfig.exe");
|
||||
int exitCode;
|
||||
@ -185,7 +193,7 @@ bool WinPcapPort::hasExclusiveControl()
|
||||
|
||||
bool WinPcapPort::setExclusiveControl(bool exclusive)
|
||||
{
|
||||
QString portName(adapter_->Name + strlen("\\Device\\NPF_"));
|
||||
QString portName(name() + strlen("\\Device\\NPF_"));
|
||||
QString bindConfigFilePath(QCoreApplication::applicationDirPath()
|
||||
+ "/bindconfig.exe");
|
||||
QString status;
|
||||
|
@ -88,9 +88,9 @@ private:
|
||||
bool setPromisc();
|
||||
bool clearPromisc();
|
||||
|
||||
LPADAPTER adapter_;
|
||||
LPADAPTER adapter_{nullptr};
|
||||
NET_LUID luid_;
|
||||
PPACKET_OID_DATA linkStateOid_ ;
|
||||
PPACKET_OID_DATA linkStateOid_{nullptr};
|
||||
|
||||
static PIP_ADAPTER_ADDRESSES adapterList_;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user