qudpsocket multicast root privileges

451 Views Asked by At

I've written a simple udp multicast server using QUdpSocket but the writedatagram function only works if I run the app with root privileges. Is this normal? It's a pain. Plus iperf (for example) seems to work without root privileges. What am I doing wrong?

Platform is Ubuntu 12.04 3.2.0-56-generic x86_64 My codes is very simple...

#define MULTICAST_ADDR "192.168.1.255"
#define MULTICAST_PORT 45454
udpSocket = new QUdpSocket();
udpSocket->setSocketOption(QAbstractSocket::MulticastTtlOption,1);
udpSocket->setSocketOption(QAbstractSocket::MulticastLoopbackOption,0);
    x = udpSocket->writeDatagram(ba->data()+sent,
                                toSend,
                                QHostAddress(MULTICAST_ADDR),
                                MULTICAST_PORT);

This code is based on QTs own example code which makes no mention of root privileges.

If I simply change the IP address to a non-broadcast/multicast address (e.g. 192.168.1.18) I don't need root privileges.

1

There are 1 best solutions below

0
On

Not exactly an answer..but almost. I know that UDP is a bit brutal compared to TCP and that throttling must be managed by the app so that bandwidth and resources are handled nicely. I found that pausing after each of my writeDatagram calls fixed the problem. Something somewhere getting clogged? But why does running with root privileges circumvent this problem? Perhaps the system runs faster with root privileges so I am able to call writeDatagram flat-out without suffering the consequences of my bad coding?

Note also that I no longer call writeDatagram in a vicious loop but instead call each subsequent writeDatagram in response to the bytesWritten signal. I don't think this comes in to play with my error, but it looks more like proper coding.