将 asio 套接字多播提升到特定以太网接口
我以为我在下面的例子中找到了答案,但并不完全是。
boost::asio::ip::udp::socket socket(io_service);
...
boost::asio::ip::address_v4 local_interface =
boost::asio::ip::address_v4::from_string("1.2.3.4");
boost::asio::ip::multicast::outbound_interface option(local_interface);
socket.set_option(option);
如何将 eth0
映射到适当的 outbound_interface 选项?
I thought I had found the answer in the following example, but not quite.
boost::asio::ip::udp::socket socket(io_service);
...
boost::asio::ip::address_v4 local_interface =
boost::asio::ip::address_v4::from_string("1.2.3.4");
boost::asio::ip::multicast::outbound_interface option(local_interface);
socket.set_option(option);
How do I map eth0
to the appropriate outbound_interface option?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下代码在 Windows 和 Mac OS X 上运行良好:
编辑:我在 Linux 上遇到了一些问题,但还没有研究它。我的猜测是套接字选项被忽略,有利于路由表。
The following code works fine on Windows and Mac OS X:
EDIT: I had some issues on Linux, but did not look into it yet. My guess is the socket option is ignored in favor of the routing table.
我认为您的示例和 eile 的示例不起作用的原因是您没有设置 SO_BINDTODEVICE 套接字选项。
请参阅此内容以了解为什么它不起作用:http://codingrelic。 geekhold.com/2009/10/code-snippet-sobindtodevice.html
请参阅此内容以了解如何使用 boost::asio: http://permalink.gmane.org/gmane.comp.lib.boost .asio.user/2724
I think the reason why your example and eile's example don't work is because you didn't set the SO_BINDTODEVICE socket option.
See this to know why it doesn't work: http://codingrelic.geekhold.com/2009/10/code-snippet-sobindtodevice.html
See this to know how to do it with boost::asio: http://permalink.gmane.org/gmane.comp.lib.boost.asio.user/2724
http://permalink.gmane.org/gmane.comp。 lib.boost.asio.user/2724 无效。
下面的代码似乎无效:
http://permalink.gmane.org/gmane.comp.lib.boost.asio.user/2724 is invalid.
The following code seems to be invalid: