dseshadri20 / oscpack

Automatically exported from code.google.com/p/oscpack
Other
0 stars 0 forks source link

Implement support for multicast address #17

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Try to bind UdpListeningReceiveSocket to a multicast address and send 
messages to the multicast group. It won't work.

Suggested fix: change the Bind method in UdpSocket.cpp to:

    void Bind( const IpEndpointName& localEndpoint )
    {
        struct sockaddr_in bindSockAddr;
        SockaddrFromIpEndpointName( bindSockAddr, localEndpoint );

        if (localEndpoint.IsMulticastAddress()) {
            group.imr_interface.s_addr = htonl(INADDR_ANY);
            group.imr_multiaddr.s_addr = bindSockAddr.sin_addr.s_addr;
            if (setsockopt(socket_, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&group, sizeof(group)) < 0) {
                throw std::runtime_error("error adding multicast group\n");
                close(socket_);
                exit(1);
            }
        }

        if (bind(socket_, (struct sockaddr *)&bindSockAddr, sizeof(bindSockAddr)) < 0) {
            throw std::runtime_error("unable to bind udp socket\n");
        }

        isBound_ = true;
    }

Original issue reported on code.google.com by mattijsk...@gmail.com on 30 May 2014 at 4:39