Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Wrong hardware MAC

Wrong hardware MAC

Scheduled Pinned Locked Moved Solved Mobile and Embedded
networkhardware maclinux
9 Posts 3 Posters 2.4k Views
  • 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.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by
    #1

    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

    raven-worxR 1 Reply Last reply
    0
    • McLionM McLion

      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

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      McLionM 2 Replies Last reply
      0
      • raven-worxR raven-worx

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

        McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • raven-worxR raven-worx

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

          McLionM Offline
          McLionM Offline
          McLion
          wrote on last edited by
          #4

          @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-worxR 1 Reply Last reply
          0
          • McLionM McLion

            @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-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

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

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            McLionM 2 Replies Last reply
            1
            • raven-worxR raven-worx

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

              McLionM Offline
              McLionM Offline
              McLion
              wrote on last edited by
              #6

              @raven-worx
              Thanks

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

              1 Reply Last reply
              0
              • raven-worxR raven-worx

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

                McLionM Offline
                McLionM Offline
                McLion
                wrote on last edited by
                #7

                @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

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  Hi!
                  This bug was fixed in Qt 4.7.4, see: QTBUG-19165

                  McLionM 1 Reply Last reply
                  2
                  • ? A Former User

                    Hi!
                    This bug was fixed in Qt 4.7.4, see: QTBUG-19165

                    McLionM Offline
                    McLionM Offline
                    McLion
                    wrote on last edited by
                    #9

                    @Wieland
                    Thanks for confirming.

                    1 Reply Last reply
                    0

                    • Login

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