Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Hardware address on Mac Os X
Qt 6.11 is out! See what's new in the release blog

Hardware address on Mac Os X

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 5.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stephane78
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      You should insert some qDebug to see what is going on.
      If you get empty string, it means

      QNetworkInterface::allInterfaces() is empty list

      Or !(netInterface.flags() & QNetworkInterface::IsLoopBack)

      is never true

      So does it detect any interfaces ?

      1 Reply Last reply
      2
      • S Offline
        S Offline
        stephane78
        wrote on last edited by stephane78
        #3

        @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

        mrjjM 1 Reply Last reply
        0
        • S stephane78

          @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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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?

          1 Reply Last reply
          1
          • S Offline
            S Offline
            stephane78
            wrote on last edited by
            #5

            @mrjj , Hi the wifi is not active and the mac is on lan with ethernet active (it is a macbook pro).

            mrjjM 1 Reply Last reply
            0
            • S stephane78

              @mrjj , Hi the wifi is not active and the mac is on lan with ethernet active (it is a macbook pro).

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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 :)

              1 Reply Last reply
              0
              • S Offline
                S Offline
                stephane78
                wrote on last edited by
                #7

                @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....

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  stephane78
                  wrote on last edited by
                  #8

                  @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.

                  mrjjM 1 Reply Last reply
                  0
                  • S stephane78

                    @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.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @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-x

                    I do wonder why you dont have a en0 ?

                    Happy coding :) i wish you luck.

                    S 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      @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-x

                      I do wonder why you dont have a en0 ?

                      Happy coding :) i wish you luck.

                      S Offline
                      S Offline
                      stephane78
                      wrote on last edited by
                      #10

                      @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.

                      mrjjM 1 Reply Last reply
                      0
                      • S stephane78

                        @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.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @stephane78
                        Oh, you should say Qt version and mac OS version btw. It might be bug or regression.

                        S 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @stephane78
                          Oh, you should say Qt version and mac OS version btw. It might be bug or regression.

                          S Offline
                          S Offline
                          stephane78
                          wrote on last edited by
                          #12

                          @mrjj it is mac os 10.10.4 and Qt5.6.0

                          S 1 Reply Last reply
                          1
                          • S stephane78

                            @mrjj it is mac os 10.10.4 and Qt5.6.0

                            S Offline
                            S Offline
                            stephane78
                            wrote on last edited by
                            #13

                            @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....

                            1 Reply Last reply
                            1
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              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.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              1

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved