tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Simple multicast question



Ivo Vachkov wrote:
I use something like this usually ...

Thanks, close to what I use (except for REUSEADDR). But adding REUSEADDR and thus disabling the delivery optimization didn't help either. That needs more investigation
on my part.

My fragment now is (setting the bind address to INADDR_ANY on multicast addresses).

    fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (fd == -1)
       {
         errx(EXIT_FAILURE, "socket(2) failed");
       }
printf("Binding to %s\n", argv[1]); if (IN_CLASSD(ntohl(((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr)))
       {
         printf("MCAST ADD MEMBERSHIP: ");
memset(&mreq, 0, sizeof(mreq)); mreq.imr_multiaddr = ((struct sockaddr_in *)ai->ai_addr)->sin_addr;
         mreq.imr_interface.s_addr = htonl(INADDR_ANY);
((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr = htonl(INADDR_ANY);
         if (setsockopt(fd,
                        IPPROTO_IP,
                        IP_ADD_MEMBERSHIP,
                        (char *)&mreq,
                        sizeof(mreq)))
           {
             printf("FAIL %s (%d)\n", strerror(errno), errno);
           }
         else
           {
             printf("SUCCESS\n");
           }
       }

     if (bind(fd, ai->ai_addr, ai->ai_addrlen) == -1) ....


With that I see broadcast packets that are also flying around, but not multicast packets yet.

Thanks,
 Frank


Home | Main Index | Thread Index | Old Index