Unsolved Hardware address on Mac Os X
-
Hi,
the following code works well on windows and linux and I get an hardware address but on mac os X (Qt5.6.0) I get an empty string :
foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces()) { // Return only the first non-loopback MAC Address if (!(netInterface.flags() & QNetworkInterface::IsLoopBack)) return netInterface.hardwareAddress(); } return QString();
is there any other solution on mac os ?
-
Hi
You should insert some qDebug to see what is going on.
If you get empty string, it meansQNetworkInterface::allInterfaces() is empty list
Or !(netInterface.flags() & QNetworkInterface::IsLoopBack)
is never true
So does it detect any interfaces ?
-
@mrjj,Hi, I have called qDebug <<"mac address :"<<netInterface.hardwareAddress(); in the loop foreach and I get 4 empty hardware Addresses.so QNetworkInterface::allInterfaces() is not empty but each hardwareAddress() is empty
-
@stephane78
Hi
It might be related to the actual hardware.Do you have this macintosh on lan or only wifi?
Is it possible by other means to list the hw adr?
Some interfaces do not have. ( at least on windows. Im not on mac OS
so not sure if same applies)Maybe try to list the various data from QNetworkConfiguration?
-
@mrjj , Hi the wifi is not active and the mac is on lan with ethernet active (it is a macbook pro).
-
@stephane78
Ok. should have a MAC for the lan. At least on linux/windows.So lets wait and see if an actual macintosh users know if its a bug or
simply works differently for this platform :) -
@mrjj, Hi I have found that :https://lists.freebsd.org/pipermail/freebsd-hackers/2004-June/007415.html from that :http://stackoverflow.com/questions/10593736/mac-address-from-interface-on-os-x-c, so I can perhaps try this low level thing on mac os to get the mac address.I come here back again to tell you if it works....
-
@mrjj,Hi to add to the above things,I have two interfaces "lo0" and "gif0" if I use qDebug and netInterface.name();.So now I will try the code that I mentioned above to get the mac address.
-
@stephane78
Just to be 100% sure, you did go and look in "hardware" on the mac that it does in fact have an address?lo0 = loopback
gif0 = Software Network Interface
stf0 = 6to4 tunnel interface
en0 = Ethernet 0
fw0 = Firewire
en1 = Ethernet 1
vmnet8 = Virtual Interface
vmnet1 = Virtual Interface
http://superuser.com/questions/267660/can-someone-please-explain-ifconfig-output-in-mac-os-xI do wonder why you dont have a en0 ?
Happy coding :) i wish you luck.
-
@mrjj, Hi, ifconfig detects en0 but Qt doesn't detect it....so thanks I will try the code for freebsd above, with interfaces en0, en1 and en2.
-
@stephane78
Oh, you should say Qt version and mac OS version btw. It might be bug or regression. -
@mrjj it is mac os 10.10.4 and Qt5.6.0
-
@mrjj, yes it might be bug.But I have done a function QString interfacetoMac(char * ) based on the freebsd code that returns the mac adress and I call interfacetoMac on "en0" (if the result is empty on "en1","en2") and I had the Mac address (hardware address) on the mac.So my problem is solved.it seems that Qt don't see en0 on the mac....
-
Hi,
Can you re-test that on a more recent version of Qt ? With my current build of 5.7 it's working correctly.
Try 5.6.1-1 at least or the 5.6.2 latest test package.