Re: [asio-users] Boost.Asio Multicast on a host with multiple interfaces - filtering/knowing on inc
Brought to you by:
chris_kohlhoff
From: Ramon C. <ram...@ct...> - 2008-09-03 12:46:54
|
Re, Answering my own question, this seems to work and is slightly more portable than IP_PKTINFO. I am not sure that SO_BINDTODEVICE is available in all targeted systems in order to suggest the option to be included in a new release :) Apologies for the inconvenience this may have caused. Let me thank Christoff for the excellent library that Boost.Asio is. Ramon. aio::ip::address if_address = aio::ip::address::from_string (if_address_str); aio::ip::address multicast_address = aio::ip::address::from_string ("224.0.0.1"); // bind address aio::ip::address listen_address = multicast_address; aio::ip::udp::endpoint listen_endpoint(listen_address, port_); // open the socket socket_.open (listen_endpoint.protocol()); // SO_BINDTODEVICE if ((::setsockopt (socket_.native(), SOL_SOCKET, SO_BINDTODEVICE, ifp_->name().c_str(), ifp_->name().size() + 1) == -1)) { throw std::runtime_error("setsockopt() SO_BINDTODEVICE"); } // bind socket_.set_option (aio::ip::udp::socket::reuse_address(true)); socket_.bind (listen_endpoint); // disable loopback socket_.set_option(aio::ip::multicast::enable_loopback(false)); // set oif - the socket will use this interface as outgoing interface socket_.set_option(aio::ip::multicast::outbound_interface(if_address.to_v4() )); // set mcast group - join group - socket_.set_option(aio::ip::multicast::join_group(multicast_address.to_v4(), if_address.to_v4())); |