Add port speed and MTU properties

This commit only retreives these properties for Windows. Linux and
BSD/MacOS are pending
This commit is contained in:
Srivats P 2021-11-06 21:27:55 +05:30
parent 14993073fe
commit 925edb8507
7 changed files with 21 additions and 1 deletions

View File

@ -212,6 +212,9 @@ message Port {
optional TransmitMode transmit_mode = 7 [default = kSequentialTransmit]; optional TransmitMode transmit_mode = 7 [default = kSequentialTransmit];
optional string user_name = 8; optional string user_name = 8;
optional bool is_tracking_stream_stats = 9; optional bool is_tracking_stream_stats = 9;
optional double speed = 10; // in Mbps
optional uint32 mtu = 11;
} }
message PortConfigList { message PortConfigList {

View File

@ -64,6 +64,11 @@ AbstractPort::~AbstractPort()
void AbstractPort::init() void AbstractPort::init()
{ {
if (interfaceInfo_) {
data_.set_speed(interfaceInfo_->speed);
data_.set_mtu(interfaceInfo_->mtu);
}
if (deviceManager_) if (deviceManager_)
deviceManager_->createHostDevices(); deviceManager_->createHostDevices();
} }

View File

@ -214,6 +214,7 @@ void BsdPort::populateInterfaceInfo()
} }
interfaceInfo_ = new InterfaceInfo; interfaceInfo_ = new InterfaceInfo;
// FIXME: speed, mtu
interfaceInfo_->mac = mac; interfaceInfo_->mac = mac;
// //

View File

@ -39,6 +39,9 @@ struct InterfaceInfo
quint64 mac; quint64 mac;
QList<Ip4Config> ip4; QList<Ip4Config> ip4;
QList<Ip6Config> ip6; QList<Ip6Config> ip6;
double speed{0}; // in Mbps
quint32 mtu{0};
}; };
#endif #endif

View File

@ -247,6 +247,7 @@ void LinuxPort::populateInterfaceInfo()
rtnl_link_put(link); rtnl_link_put(link);
interfaceInfo_ = new InterfaceInfo; interfaceInfo_ = new InterfaceInfo;
// FIXME: speed, mtu
interfaceInfo_->mac = mac; interfaceInfo_->mac = mac;
// //

View File

@ -74,7 +74,7 @@ PortManager::PortManager()
{ {
AbstractPort *port; AbstractPort *port;
qDebug("%d. %s", i, device->name); qDebug("==========\n%d. %s", i, device->name);
if (device->description) if (device->description)
qDebug(" (%s)\n", device->description); qDebug(" (%s)\n", device->description);
@ -122,6 +122,8 @@ PortManager::PortManager()
qPrintable(QHostAddress(ip.address.toArray()).toString()), qPrintable(QHostAddress(ip.address.toArray()).toString()),
ip.prefixLength, ip.prefixLength,
qPrintable(QHostAddress(ip.gateway.toArray()).toString())); qPrintable(QHostAddress(ip.gateway.toArray()).toString()));
qDebug("Speed: %g Mbps", intfInfo->speed);
qDebug("Mtu: %u", intfInfo->mtu);
} }
if (!port->setRateAccuracy(txRateAccuracy)) if (!port->setRateAccuracy(txRateAccuracy))

View File

@ -261,6 +261,11 @@ void WinPcapPort::populateInterfaceInfo()
} }
interfaceInfo_ = new InterfaceInfo; interfaceInfo_ = new InterfaceInfo;
interfaceInfo_->speed = adapter->TransmitLinkSpeed != quint64(-1) ?
adapter->TransmitLinkSpeed/ulong(1e6) : 0;
interfaceInfo_->mtu = adapter->Mtu;
if (adapter->PhysicalAddressLength == 6) { if (adapter->PhysicalAddressLength == 6) {
interfaceInfo_->mac = qFromBigEndian<quint64>( interfaceInfo_->mac = qFromBigEndian<quint64>(
adapter->PhysicalAddress) >> 16; adapter->PhysicalAddress) >> 16;