Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for multicast address #17

Open
GoogleCodeExporter opened this issue Aug 25, 2015 · 0 comments
Open

Implement support for multicast address #17

GoogleCodeExporter opened this issue Aug 25, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 30 May 2014 at 4:39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant