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. QNetworkInterface get subnet mask
Qt 6.11 is out! See what's new in the release blog

QNetworkInterface get subnet mask

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 7.7k Views 1 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.
  • mrdebugM Offline
    mrdebugM Offline
    mrdebug
    wrote on last edited by
    #1

    Hi. Is there a way to get the subnet mask?

    Need programmers to hire?
    www.labcsp.com
    www.denisgottardello.it
    GMT+1
    Skype: mrdebug

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      "Get a list of the network interfaces":http://qt-project.org/doc/qt-5/qnetworkinterface.html#allInterfaces
      For each interface "get a list of the address entries":http://qt-project.org/doc/qt-5/qnetworkinterface.html#addressEntries
      For each entry "get netmask":http://qt-project.org/doc/qt-5/qnetworkaddressentry.html#netmask

      1 Reply Last reply
      0
      • mrdebugM Offline
        mrdebugM Offline
        mrdebug
        wrote on last edited by
        #3

        Is there a way to get the valid ip from a list?
        For example I have this list:

        10.0.0.1 255.255.255.0
        192.168.0.1 255.255.255.0
        192.168.1.1 255.255.255.0

        from the remote server. My pc is
        192.168.0.111 255.255.255.0

        Is there a way to select the right ip? (in this case the second, 192.168.0.1)

        Need programmers to hire?
        www.labcsp.com
        www.denisgottardello.it
        GMT+1
        Skype: mrdebug

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          if you know ip address and mask you can calculate first ip address in a network.
          For example
          @
          192.168.0.111 = 0xC0A8006F
          255.255.255.0 = 0xFFFFFF00
          0xC0A8006F & 0xFFFFFF00 = 0xC0A80000
          0xC0A80000 = 192.168.0.0
          @
          So first address of the network 192.168.0.0 is 192.168.0.1

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreyc
            wrote on last edited by
            #5

            Another option is to calculate network addresses for all 3 entries in the list and for pc.
            Select the entry from the list that has the same network with pc.

            1 Reply Last reply
            0
            • mrdebugM Offline
              mrdebugM Offline
              mrdebug
              wrote on last edited by
              #6

              Solved using your suggestion.
              I hoped to find an already made function.

              Need programmers to hire?
              www.labcsp.com
              www.denisgottardello.it
              GMT+1
              Skype: mrdebug

              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