简体   繁体   中英

ipv6 multicast reception

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 */

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM