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. [SOLVED] QUdpSocket->Bind() on linux requires super user rights
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QUdpSocket->Bind() on linux requires super user rights

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.0k 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.
  • C Offline
    C Offline
    code_fodder
    wrote on 5 Jun 2013, 12:41 last edited by
    #1

    Hi All,

    Using Qt SDK5.0.2. I am struggling a bit here with the QUdpSocket->bind() function on linux (in my case Ubuntu 12.10 and/or 10.10, I think version does not matter).

    My project calls QUdpSocket->bind(ip_address, port);
    I have built the project for windows and created a deployment (includnig all the dlls etc...). Then I run it on linux under wine and the binding fails. If I switch to root using "su" and run it again the binding works.

    I then thought it was an issue of wine so I installed Qt SDK 5.0.2 on ubuntu 12.10. When I run the project via the Qt Creator its fine. But when I run the binary output from the command line (i.e. enter the command "./myapp") it fails to bind. If I run as super user (i.e. enter the command "sudo ./myapp") then it works.

    The documentation says that the bind type "DontShareAddress" may need admin rights on certain platforms, so I tried using "QAbstractSocket::ShareAddress". But this did not fix the problem.

    Has anyone else come across this? I have not found much in the way of information on this topic so far.
    Any ideas to solve this? - I don't think my final solution is a good one if it has to be run as the root user.

    Thanks very much :)

    1 Reply Last reply
    0
    • B Offline
      B Offline
      butterface
      wrote on 5 Jun 2013, 13:02 last edited by
      #2

      Which port do you use?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        code_fodder
        wrote on 5 Jun 2013, 13:22 last edited by
        #3

        I am using a range of ports.

        5000

        27017, 27018

        42400, 42401

        44284

        Is there an issue with any of these ports? Is there a range that I need to try to avoid and then I wont need admin rights?

        Thanks! :)

        1 Reply Last reply
        0
        • B Offline
          B Offline
          butterface
          wrote on 5 Jun 2013, 14:14 last edited by
          #4

          These ports seem to be okay. Can you figure out which of these ports causes the problem? Can you also provide a little bit more of code so maybe one can see the problem.

          You cannot use Ports 1-1023 without root privileges and actually should not use these ports.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            code_fodder
            wrote on 5 Jun 2013, 15:21 last edited by
            #5

            ah ok,

            Well, I made a tiny test project just to test this one line of code (the "bind" itself):

            I have tried various address and port combos, for example:
            IP 127.0.0.1, port 10 .... wait, port 10!!?? :o
            @
            // Attempt to bind
            if (_udpSocket->bind(_rxIp.address, _rxIp.port, QAbstractSocket::ShareAddress))
            {
            qDebug() << _connectionName << "Bind success:" << _rxIp.address << _rxIp.port << endl;
            }
            else
            {
            qDebug() << _connectionName << "Bind failed:" << _rxIp.address << _rxIp.port << endl;
            }
            @

            Then I changed that "test" code to port 5000 and I no longer had the problem!, I swear that when I first tried this I was having issues with port 5000, but maybe I had myself all confused!

            So, to recap... I have to STOP using these special special ports 1-1023 as my test ports :o

            Thanks very much butterface, I think you saved my going round and round in circles! :D

            1 Reply Last reply
            0

            1/5

            5 Jun 2013, 12:41

            • Login

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