在具有多个接口的服务器上接收多播(linux)
要在我的非默认 NIC (dvb) 上接收多播,我执行以下操作:
- 打开套接字(AF_INET、SOCK_DGRAM)
- 使用 dvb 接口上的 IP_ADD_MEMBERSHIP 加入多播地址
- 绑定多播地址(请注意,常见错误是绑定“0.0” .0.0”,然后在该套接字上接收甚至您不感兴趣的多播),
此时接收所需多播数据包的端口的唯一方法是在路由表中添加一条规则以到达发送者所在的网络(另一个网络)通过 DVB,就好像 DVB 需要回复多播发送者一样;假设一种源发送方多播模式。有人知道发生了什么事吗?这个问题对我来说很烦人,因为原则上我不知道发件人的IP。
To receive a multicast on my not default NIC (dvb) I do the following:
- open a socket (AF_INET, SOCK_DGRAM)
- join the multicast address with IP_ADD_MEMBERSHIP on the dvb interface
- bind the multicast address (note that a common error is to bind "0.0.0.0" and then receive on that socket even multicast you are not interested in) and the port
at this point the only way to receive the needed multicast packets is to add in the routing table a rule to reach the network where the sender is (another network) trough the dvb, as if the dvb needs to reply to the multicast sender; let say a sort of source sender multicast mode. Anyone knows what is going on? The problem is annoying to me because in principle I don't know the ip of sender.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎被
rp_filter
反向路径过滤所困扰。如果数据包到达没有源地址路由的接口,则会丢弃数据包。您可以使用 sysctl
/proc/sys/net/ipv4/conf//rp_filter
在每个接口上禁用它。You appear to be being stung by
rp_filter
reverse-path filtering. This drops packets if they arrive on an interface that doesn't have a route for the source address.You can disable it on a per-interface basis with the sysctl
/proc/sys/net/ipv4/conf/<if>/rp_filter
.这绝对是错误的。您必须绑定到真实适配器的实际 IP 地址,或 0.0.0.0。
这不是一个错误。这是正确的过程,除非您只想监听一个 IP 地址。
不知道这是什么意思。
任何UDP数据报的发送者的IP地址都可以通过套接字API获得。
That is definitely wrong. You must bind to an actual IP address of a real adapter, or 0.0.0.0.
That's not an error. THat is correct procedure unless you only want to listen to one IP address.
I don't know what this means.
The IP address of the sender of any UDP datagram is available via the sockets API.