为什么具有相同源IP地址的多播消息会被忽略 [英] Why multicast messages with same source ip address get ignored

查看:82
本文介绍了为什么具有相同源IP地址的多播消息会被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了利用多播消息的网络发现过程.它允许发现具有连接到同一网段的任何ip地址的特定设备.

I implemented a network discovery process which makes use of multicast messages. It allows to discover specific devices with any ip-address connected to the same segment.

客户端A发送多播消息,要求其他客户端.其他客户端以多播消息我在这里..."进行响应.基本上可以正常工作.

Client A sends a multicast messages, asking for other Clients. The other clients response with a multicast message "I'am here...". Basically this works fine.

但是有一种情况给我带来麻烦.

But there is one case which causes me troubles.

 Client A       Client B
192.168.2.5   192.168.2.5  
    |             |
     \__________ / 
         >>>
  UDP Multicast Message: 
  Source: 192.168.2.5 | Destination: 224.0.0.150

可能会发生巧合,发送多播消息的客户端A和客户端B都侦听相同的IP地址.在这种情况下,UDP数据包的源地址与目标客户端的ip地址相同.因此,客户端B上的应用程序不会收到任何多播消息.

The coincident could arise, that Client A which sends the multicast message and Client B both listen to the same ip-address. In this case the source address of the UDP packet is the same as the ip-address of the destination client. Thus the application on Client B does not receive any multicast message.

我猜想具有相同消息的多播消息被阻止并丢弃在ip堆栈中.是否有一种方法(套接字设置)来接收它.

I guess that the multicast message with the same messages gets blocked and dropped in the ip-stack. Is there a way (socket settings) to receive it anyway.

推荐答案

是的,您可以让主机读取自己的多播数据包(通常只是源IP地址上的过滤器),这由IP_MULTICAST_LOOP套接字控制选项.

Yes, you can have a host read its own multicast packets(which is often just a filter on the source IP address), this is controlled by the IP_MULTICAST_LOOP socket option.

int loop = 1;
setsockopt(socket, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop));

这篇关于为什么具有相同源IP地址的多播消息会被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆