Hi,
I want to send message to ipv6 multicast group, use the code as below.
It works on my macbook and ios simulators, but failed on the iphone or ipad device and print the log "sendto: Can't assign requested address".
Could anybody help ?
void sendIPV6Multicast(void)
{
struct sockaddr_in6 sin = {0};
char smsg[] = {"abcdef"};
int wifiInterface;
int fd;
long ret;
fd = socket(AF_INET6, SOCK_DGRAM, 0);
if (fd < 0)
perror("socket");
wifiInterface = if_nametoindex("en0");
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &wifiInterface, sizeof(wifiInterface)) < 0)
perror("setsockopt");
inet_pton(AF_INET6, "FF12::99", &sin.sin6_addr);
sin.sin6_family = AF_INET6;
sin.sin6_scope_id = wifiInterface;
sin.sin6_port = htons(6000);
ret = sendto(fd, smsg, strlen(smsg), 0, (struct sockaddr*)&sin, sizeof(sin));
if (ret < 0)
perror("sendto");
}