禁用 UDP 广播的自接收
我想知道有什么方法可以禁用来自节点 A 的 UDP 广播数据包,使其不被节点 A 本身接收。
对于广播,我只是使用 INADDR_BROADCAST
并在 接收端我正在使用 AI_PASSIVE | AI_NUMERICHOST。
I wish to know is there any way I can disable the UDP broadcast packet from the node A to not received by node A itself.
For braodcast I am simply using INADDR_BROADCAST
and on the
receiver side I am using AI_PASSIVE | AI_NUMERICHOST
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,这是广播的基本属性 - 子网上的每个主机(包括发送者)都必须在网络堆栈中一直处理数据包。您的选项是:
IP_MULTICAST_LOOP
套接字选项。bind(2)< /code>
发送机器上的目标端口。这可行,但有点笨拙,因为它对应用程序设计和/或部署施加了限制。
No, this is fundamental property of broadcasting - every host on the subnet, including the sender, will have to process the packet all the way up the network stack. You options are:
IP_MULTICAST_LOOP
socket option.bind(2)
the destination port on the sending machine. This works but is sort of kludgy since it puts restrictions on application design and/or deployment.绑定到接口,而不仅仅是地址。
这样,未到达指定接口(而是源自该接口)的数据将不会被接收。
Bind to interface, not just address.
This way data that didn't arrive at the interface specified (but originated from it instead) will not be received.
以下是我使用 Python 套接字库进行实验的结果。 UDP广播器是否接收自己发送的消息取决于您将广播套接字绑定到什么地址。为了更清楚起见,广播公司的 IP 地址是 192.168.2.1。
接收广播的 UDP 消息。
PS 在 Python 2.7.9、操作系统 Raspbian 8(针对 Raspberry Pi 的 Debian 改编)、Linux 内核 4.4.38 上进行测试
Here are results of my experiments with Python's socket library. Whether UDP broadcaster receives messages sent by itself is dependent on what address will you bind broadcasting socket to. For greater clarity, broadcaster's IP address was 192.168.2.1.
Receiver received broadcasted UDP messages in all these cases.
P.S. Tested on Python 2.7.9, OS Raspbian 8 (adaptation of Debian for Raspberry Pi), Linux kernel 4.4.38