3

Following is the function I wrote to capture IPv6 multicast data coming on multicast address ff02::1 and port 9154.
This code works fine on Windows Vista and Windows 7. But I am unable to capture the same traffic for Windows 8 (none of the winsock functions returns error for Win8).

Using netstat I am able to verify that my application is using this port.
Can any one help?

void func()
{

    int multicastChannel = 0;
    char multicastIP[] = "FF02::1";
    char multicastPort[] = "9154";

    ADDRINFO*  multicastAddr  = NULL;
    ADDRINFO*  localAddr      = NULL;
    ADDRINFO   hints          = { 0 };

    struct ipv6_mreq multicastRequest6;

    hints.ai_family = PF_UNSPEC;
    hints.ai_flags  = AI_NUMERICHOST;

    if ( getaddrinfo(multicastIP, NULL, &hints, &multicastAddr) != 0 )
    {
        printf("getaddrinfo() failed");
        return;
    }

    hints.ai_family   = multicastAddr->ai_family;
    hints.ai_socktype = SOCK_DGRAM;
    hints.ai_flags    = AI_PASSIVE;

    if ( getaddrinfo(NULL, multicastPort, &hints, &localAddr) != 0 )
    {
        printf("getaddrinfo() failed");
        return;
    }

    multicastChannel = socket(localAddr->ai_family, localAddr->ai_socktype, 0);

    if ( bind(multicastChannel, localAddr->ai_addr, localAddr->ai_addrlen) != 0 )
    {
        printf("bind() failed");
        return;
    }

    memcpy(&multicastRequest6.ipv6mr_multiaddr,
           &((struct sockaddr_in6*)(multicastAddr->ai_addr))->sin6_addr,
           sizeof(multicastRequest6.ipv6mr_multiaddr));

    multicastRequest6.ipv6mr_interface = 0;

    if ( setsockopt(multicastChannel,
                    IPPROTO_IPV6,
                    IPV6_ADD_MEMBERSHIP,
                    (char*) &multicastRequest6,
                    sizeof(multicastRequest6)) != 0 )
    {
        ERROR_ReportError("setsockopt() failed");
    }

    freeaddrinfo(localAddr);
    freeaddrinfo(multicastAddr);

    ioctlsocket(multicastChannel, FIONBIO, &arg);

    sockaddr_in6 fromAddr;

    while(1)
    {
        read = recvfrom(multicastChannel,
                data,
                1500,
                0,
                (struct sockaddr*)&fromAddr,
                &sizeof(sockaddr_in6);

        if (read > 0) {
            function();
        }
    }
}
Shreyos Adikari
  • 12,348
  • 19
  • 73
  • 82
  • Print out all the returned values. It could be something as trivial as the default multicast route is incorrect: you are explicitly setting 0. – Steve-o Apr 06 '13 at 21:16
  • As multicasting on address FF02::1 is similar to broadcasting on IPv6 network, wireshark shows the traffic but my application is unable to capture it. – Shikhar Bhargava Apr 08 '13 at 11:45

0 Answers0