Wrong hardware MAC
-
Hi
Using the following code snippet:
foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces()) { if (!(netInterface.flags() & QNetworkInterface::IsLoopBack)) sMAC = netInterface.hardwareAddress(); } qDebug() << sMAC;
does return a wrong MAC.
This is what ifconfig returns and is correct:
eth0 Link encap:Ethernet HWaddr 74:2D:0A:02:FF:08
and this is what QT returns, shifted and filled with wrong data:
"01:00:74:2D:0A:02"
I'm using Qt 4.6.3 on eLinux.
any ideas?
Thanks -
Hi
Using the following code snippet:
foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces()) { if (!(netInterface.flags() & QNetworkInterface::IsLoopBack)) sMAC = netInterface.hardwareAddress(); } qDebug() << sMAC;
does return a wrong MAC.
This is what ifconfig returns and is correct:
eth0 Link encap:Ethernet HWaddr 74:2D:0A:02:FF:08
and this is what QT returns, shifted and filled with wrong data:
"01:00:74:2D:0A:02"
I'm using Qt 4.6.3 on eLinux.
any ideas?
Thanks@McLion
your code only would output the correct values if there is only 1 interface available.
But currently it only outputs the the MAC of the last interface.
So move the qDebug() line inside the loop and recheck the values. -
@McLion
your code only would output the correct values if there is only 1 interface available.
But currently it only outputs the the MAC of the last interface.
So move the qDebug() line inside the loop and recheck the values.@raven-worx
Already did that and did output all interfaces before selecting the non-loop only, and since there is only 1 if in this embedded HW, this is fine.
Nevertheless ,the MAC returned is not correct. -
@McLion
your code only would output the correct values if there is only 1 interface available.
But currently it only outputs the the MAC of the last interface.
So move the qDebug() line inside the loop and recheck the values.@raven-worx
What is the easiest way to get a string back from a linux command run with system() for instance?
Reading back the rsult of
cat /sys/class/net/eth0/address
would be an easy substitution.
I used QFutureWatcher to get single value returns from commands run with system(). Can it return a string, or is there an easier solution? -
@raven-worx
What is the easiest way to get a string back from a linux command run with system() for instance?
Reading back the rsult of
cat /sys/class/net/eth0/address
would be an easy substitution.
I used QFutureWatcher to get single value returns from commands run with system(). Can it return a string, or is there an easier solution?@McLion
the question is why Qt thinks it is a loopback interface - maybe a Qt bug though.
Did you find the adapter you looking for in the available interfaces returned by Qt?
What is the interface which is returned instead actually?Why do you use QFuture for calling a system command?
Using QProcess instead and reading it's stdout data should be sufficient. -
@McLion
the question is why Qt thinks it is a loopback interface - maybe a Qt bug though.
Did you find the adapter you looking for in the available interfaces returned by Qt?
What is the interface which is returned instead actually?Why do you use QFuture for calling a system command?
Using QProcess instead and reading it's stdout data should be sufficient.@raven-worx
ThanksIt definitely seems to be a Qt bug:
All interfaces found by the Qt function above:
"04:03:00:00:00:00"
"01:00:74:2D:0A:02"
Correct interface:
"74:2d:0a:02:ff:08"I use the system() for some short things like a drive check that I run in a separate thread with a Future and a FutureWatcher - works as supposed.
I'll try your suggested way with QProcess ... I'l be back.
-
@McLion
the question is why Qt thinks it is a loopback interface - maybe a Qt bug though.
Did you find the adapter you looking for in the available interfaces returned by Qt?
What is the interface which is returned instead actually?Why do you use QFuture for calling a system command?
Using QProcess instead and reading it's stdout data should be sufficient.@raven-worx
Following works a treat:QProcess process; process.start("cat /sys/class/net/eth0/address"); process.waitForFinished(); QString sMAC(process.readAllStandardOutput());
Thanks a lot.
McL -
Hi!
This bug was fixed in Qt 4.7.4, see: QTBUG-19165 -
Hi!
This bug was fixed in Qt 4.7.4, see: QTBUG-19165