PDA

View Full Version : Qt5 QUdpSocket and setsockopt



taraj
5th September 2017, 02:08
Hi

I have the following code to set up a QUdpSocket that i wish to apply a setsockopt to be able to IPPROTO_IP and IP_MULTICAST_IF. Code will not compile on the setsockopt call with the following error

error: expected primary-expression before 'char'
int result = setsockopt(udpSocket->socketDescriptor(), IPPROTO_IP, IP_MULTICAST_IF, char*(&multicastInterface), sizeof(struct in_addr));
^

Can I not do a setsockopt on the socketdescriptor of a QUdpSocket, or have I made another basic C mistake that I can't see? Or to do this do I just to create a C socket and not use QUdpSocket - or can I link them together somehow??

My reason for needing to try this is I have a problem similar to this post
https://serverfault.com/questions/814259/use-ip-route-add-to-add-multicast-routes-to-multiple-interfaces


Thanks!
Tara



udpSocket = new QUdpSocket(this);

struct servent *serv;
serv = getservbyname("data_in", "udp");

quint16 port = qFromBigEndian(uint16_t(serv->s_port));

if(udpSocket->bind(QHostAddress::AnyIPv4, port, QUdpSocket::ShareAddress) == true)
{
struct in_addr multicastInterface;
multicastInterface.s_addr =inet_addr("230.70.10.10");

int result = setsockopt(udpSocket->socketDescriptor(), IPPROTO_IP, IP_MULTICAST_IF, char*(&multicastInterface), sizeof(struct in_addr));
}