PDA

View Full Version : UDP Multicast



Thomas_Lerman
29th July 2014, 20:51
Previously in Windows using Qt4, I was doing the following to join a source membership for UDP multicast:
int socketfd = m_RadarMulticastUdpSocket->socketDescriptor();

// set TTL (Time To Live)
unsigned int ttl = 30; // restricted to 38 hops
if (setsockopt(socketfd, IPPROTO_IP, IP_MULTICAST_TTL, (const char*)&ttl, sizeof(ttl)) < 0)
{
return (1);
}

ip_mreq_source mreq;
memset(&mreq, 0, sizeof(ip_mreq));
mreq.imr_multiaddr.s_addr = inet_addr("230.0.10.1");
mreq.imr_interface.s_addr = inet_addr(qPrintable(NicAddress));
mreq.imr_sourceaddr.s_addr = ipaddress;
if (setsockopt(socketfd, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP, (char*)&mreq, sizeof(mreq)) < 0)
{
return (1);
}When I try the same thing in Qt5, it does not work. I would guess the socket descriptor changed in some way. It is not returning -1 nor am I using any QNetworkProxy. Did anything with socketDescriptor() change?

So, I want to use QUdpSocket::joinMulticastGroup() and not be concerned with OS specific calls, but have not found a way to only join the multicast group that originates from a specified source. Did I miss something or is it really missing? I have a workaround (filtering after I get each packet) that is not the most efficient way of doing this.