在具有多个接口的服务器上接收多播(linux)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5483779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
receiving multicast on a server with multiple interfaces (linux)
提问by Gaetano Mendola
To receive a multicast on my not default NIC (dvb) I do the following:
要在我的非默认 NIC (dvb) 上接收多播,我执行以下操作:
- 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
- 打开一个套接字(AF_INET,SOCK_DGRAM)
- 在 dvb 接口上用 IP_ADD_MEMBERSHIP 加入多播地址
- 绑定多播地址(请注意,一个常见的错误是绑定“0.0.0.0”然后在该套接字上接收甚至您不感兴趣的多播)和端口
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.
此时接收需要的组播数据包的唯一方法是在路由表中添加一条规则,通过dvb到达发送者所在的网络(另一个网络),就好像dvb需要回复组播发送者一样;假设一种源发送方多播模式。有谁知道发生了什么?这个问题对我来说很烦人,因为原则上我不知道发件人的 IP。
采纳答案by caf
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.
您似乎受到rp_filter
反向路径过滤的影响。如果数据包到达没有源地址路由的接口,这将丢弃数据包。
You can disable it on a per-interface basis with the sysctl /proc/sys/net/ipv4/conf/<if>/rp_filter
.
您可以使用 sysctl 在每个接口的基础上禁用它/proc/sys/net/ipv4/conf/<if>/rp_filter
。
回答by user207421
bind the multicast address
绑定多播地址
That is definitely wrong. You must bind to an actual IP address of a real adapter, or 0.0.0.0.
那绝对是错误的。您必须绑定到真实适配器的实际 IP 地址或 0.0.0.0。
note that a common error is to bind "0.0.0.0"
注意一个常见的错误是绑定“0.0.0.0”
That's not an error. THat is correct procedure unless you only want to listen to one IP address.
那不是错误。这是正确的程序,除非您只想收听一个 IP 地址。
and then receive on that socket even multicast you are not interested in
然后在该套接字上接收甚至是您不感兴趣的多播
I don't know what this means.
我不知道这是什么意思。
in principle I don't know the ip of sender
原则上我不知道发件人的IP
The IP address of the sender of any UDP datagram is available via the sockets API.
任何 UDP 数据报的发送方的 IP 地址都可以通过套接字 API 获得。