Question

I'm unable to receive the multicast packets sent by the server. I could see the packets being received via tcpdump. Can anyone please let me know what am I doing wrong here.Thanks.

struct ipv6_mreq mreq;
struct sockaddr_in6 servaddr;

sock = socket(AF_INET6,SOCK_DGRAM,0);

servaddr.sin6_family = AF_INET6;
servaddr.sin6_port = htons(61624);
servaddr.sin6_addr = in6addr_any;

inet_pton(AF_INET6,"ff38:40:2001::1",&mreq.ipv6mr_multiaddr);

mreq.ipv6mr_interface = 0;
setsockopt(sock,IPPROTO_IPV6,IPV6_JOIN_GROUP, &mreq,sizeof(mreq));
bind(sock,(struct sockaddr *)&servaddr,sizeof(servaddr));
/* using poll to receive data */
Was it helpful?

Solution

Zero is invalid supposed to be "hey kernel, select one for me" interface index. This does not work for you, most probably because your routing table does not have explicit entries that match given multicast group, and default route goes over different interface.

Use if_nametoindex(3) to resolve interface name and store it into ipv6mr_interface member of struct ipv6_mreq.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top