[SOLVED] QUdpSocket->Bind() on linux requires super user rights
-
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 :)
-
Which port do you use?
-
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! :)
-
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.
-
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