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. UDP Socket - writeDatagram uses IPv6 and not IPv4
QtWS25 Last Chance

UDP Socket - writeDatagram uses IPv6 and not IPv4

Scheduled Pinned Locked Moved Solved General and Desktop
networkingsocketsipv6ipv4
8 Posts 4 Posters 2.7k 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.
  • M Offline
    M Offline
    mikkel1156
    wrote on 22 Jan 2018, 16:07 last edited by
    #1

    I'm having this problem that when I write a datagram like writeDatagram(data, QHostAddress("127.0.0.1"), 600), for some reason it's using IPv6. I checked this when I got a datagram, and it does indeed say IPv6 (QAbstractSocket::NetworkLayerProtocol(IPv6Protocol)). The sending address somehow becomes ::ffff:127.0.0.1

    This is a problem since the data sent I'm specify who it was from, so it does not add up since it's compating a IPv6 address to a IPv4 one. A fix would be stripping the IPv6 part off from the address when comparing, but that doesn't like a real solution, just a "hack".

    I've found that I can specify the protocol used with connectToHost, but I have some other strange problem using that, it doesn't even connect for me. My solution/workaround for that was sending the data directly with writeDatagram as seen above.

    Any ideas?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Pablo J. Rogina
      wrote on 22 Jan 2018, 16:18 last edited by
      #2

      @mikkel1156 said in UDP Socket - writeDatagram uses IPv6 and not IPv4:

      I've found that I can specify the protocol used with connectToHost, but I have some other strange problem using that, it doesn't even connect for me

      Are you sure the underlying OS where you run this application is indeed implementing IPv4?

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mikkel1156
        wrote on 22 Jan 2018, 16:23 last edited by
        #3

        @Pablo-J.-Rogina said in UDP Socket - writeDatagram uses IPv6 and not IPv4:

        @mikkel1156 said in UDP Socket - writeDatagram uses IPv6 and not IPv4:

        I've found that I can specify the protocol used with connectToHost, but I have some other strange problem using that, it doesn't even connect for me

        Are you sure the underlying OS where you run this application is indeed implementing IPv4?

        I don't know. I'm developing this on Windows. If there is a way to set the implementation to IPv4, then that will probably fix it. I don't know of such though.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Pablo J. Rogina
          wrote on 22 Jan 2018, 16:29 last edited by
          #4

          @mikkel1156 open "Network and Sharing Center", on the left "Change adapter settings", locate the adapter (i.e. Local Area Connection), right click Properties. A dialog opens showing items used by the connection. You should see "Internet Protocol Version 6" and hopefully "Internet Protocol Version 4"

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          3
          • M Offline
            M Offline
            mikkel1156
            wrote on 22 Jan 2018, 16:49 last edited by
            #5

            I guess this is a good enough solution. Thanks for the help.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              poncho524
              wrote on 3 Jan 2019, 14:37 last edited by
              #6

              I saw this thread when I Googled for a solution to the same "problem". The proposed solution here is not good.

              A better method is to bind your socket to an IPv4 address...

              QUdpSocket socket;
              socket.bind(QHostAddress("0.0.0.0"), 0);
              

              this will bind to INADDR_ANY (IPv4) at some ephemeral port (if you don't care about local port).

              A 1 Reply Last reply 3 Jan 2019, 14:51
              1
              • P poncho524
                3 Jan 2019, 14:37

                I saw this thread when I Googled for a solution to the same "problem". The proposed solution here is not good.

                A better method is to bind your socket to an IPv4 address...

                QUdpSocket socket;
                socket.bind(QHostAddress("0.0.0.0"), 0);
                

                this will bind to INADDR_ANY (IPv4) at some ephemeral port (if you don't care about local port).

                A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 3 Jan 2019, 14:51 last edited by
                #7

                @poncho524 said in UDP Socket - writeDatagram uses IPv6 and not IPv4:

                QHostAddress("0.0.0.0")

                Then why not use QHostAddress::AnyIPv4 ? Looks more clear to me...

                Qt has to stay free or it will die.

                P 1 Reply Last reply 3 Jan 2019, 14:58
                3
                • A aha_1980
                  3 Jan 2019, 14:51

                  @poncho524 said in UDP Socket - writeDatagram uses IPv6 and not IPv4:

                  QHostAddress("0.0.0.0")

                  Then why not use QHostAddress::AnyIPv4 ? Looks more clear to me...

                  P Offline
                  P Offline
                  poncho524
                  wrote on 3 Jan 2019, 14:58 last edited by
                  #8

                  @aha_1980 said in UDP Socket - writeDatagram uses IPv6 and not IPv4:

                  Then why not use QHostAddress::AnyIPv4 ? Looks more clear to me...

                  Learn something new everyday :)

                  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