响应超出范围的多播

发布于 2024-12-12 07:58:19 字数 1401 浏览 2 评论 0原文

如何响应从不同 IP 范围发送的多播 udp 消息?
我有一个场景,在小型设备上实现了一个简单的 SLP 服务器 (http://www.openslp.org/doc/rfc/rfc2608.txt),并在 PC 上实现了一个简单的 SLP 客户端。

该设备有一个 ip。例如。 10.0.0.50
然而,PC 有多个 ip。例如。 10.0.0.70、192.168.1.70、172.19.1.70
PC 还有多个网络适配器,每个适配器都有多个 ip。 (别介意。)
我从 PC 向 slp 多播组发送 udp 消息:

System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0));
client.Send(m_tx_buffer, encoded, SLPMULTICASTGROUP, SLPPORT);


.net UdpClient 将选择一个随机 IP 附加到 udp 消息。
设备将接收 udp 消息并向给定的发送者 IP 发送回单播消息。像这样:

int mysock;
struct sockaddr_in myaddr, cliaddr;
char msgbuf[MAXLEN];
socklen_t clilen;
int msglen;
mysock = socket(PF_INET,SOCK_DGRAM,0);
myaddr.sin_family = AF_INET;
myaddr.sin_port = htons( S_PORT );
myaddr.sin_addr = htonl( INADDR_ANY );
bind(mysock, &myaddr, sizeof(myaddr));
while (1) {
   len=sizeof(cliaddr);
   msglen=recvfrom(mysock,msgbuf,MAXLEN,0,cliaddr,&clilen);
   sendto(mysock,msgbuf,msglen,0,cliaddr,clilen);
}


问题是.net是否选择例如。 ip 192.168.1.70。设备将对此做出响应。而且PC端好像也上不了。 (PC 和设备共享 10.0.0.x 范围。)
应该能通过吧? (我已使用 Wireshark 验证该消息未到达 PC。并且我已使用 jtag 验证该设备发送了消息。)

为了解决这个问题,我可以让 PC 枚举所有 ip 并发送几条 udp 消息。但这的性能有些差,并且有淹没不良设备的风险。 (设备会收到所有消息并做出相应响应。PC 不会收到响应。)

我的设备(顺便说一句,它是一个小型 RTOS)是否存在传输缺陷?
或者有什么方法可以解决这个问题,而不淹没我的小设备?

How to respond to a multicast udp message sent from a different ip range?
I have a scenario in which I've implemented a simple SLP server (http://www.openslp.org/doc/rfc/rfc2608.txt) on a small device and a simple SLP client on a PC.

The device has an ip. Eg. 10.0.0.50
The PC however has several ips. Eg. 10.0.0.70, 192.168.1.70, 172.19.1.70
The PC also have several network adapters, that each have several ips. (Never mind that.)

From the PC I send out an udp message to the slp multicast group:

System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0));
client.Send(m_tx_buffer, encoded, SLPMULTICASTGROUP, SLPPORT);

The .net UdpClient will select a random ip to attach to the udp message.
The device will recieve the udp message and send back a unicast message to the given sender ip. Like so:

int mysock;
struct sockaddr_in myaddr, cliaddr;
char msgbuf[MAXLEN];
socklen_t clilen;
int msglen;
mysock = socket(PF_INET,SOCK_DGRAM,0);
myaddr.sin_family = AF_INET;
myaddr.sin_port = htons( S_PORT );
myaddr.sin_addr = htonl( INADDR_ANY );
bind(mysock, &myaddr, sizeof(myaddr));
while (1) {
   len=sizeof(cliaddr);
   msglen=recvfrom(mysock,msgbuf,MAXLEN,0,cliaddr,&clilen);
   sendto(mysock,msgbuf,msglen,0,cliaddr,clilen);
}

Problem is if the .net chooses eg. ip 192.168.1.70. The device will respond to this. And it doesn't seem to get through to the PC. (The PC and the device share the 10.0.0.x range.)

Is it supposed to get through? (I've verified with Wireshark that the message doesn't arrive on the PC. And I've verified with my jtag that the device sends out a message.)

To solve this I could make the PC enumerate all ips and send out several udp messages. But this has somewhat bad performance and it risks flooding the poor devices. (The device will recieve all the messages and respond accordingly. It's the PC that doesn't recieve the responses.)

Is it my device (it's a small RTOS btw.) that has a flawed transmisson?

Or is there some way to solve this problem, without flooding my small devices?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

私野 2024-12-19 07:58:19

如果您希望设备能够发送到不在直接连接子网上的 IP 地址,则必须为其提供这些 IP 地址的路由。

您可以简单地为其指定一条通过 PC 的默认路由(即网关为 10.0.0.70 的默认路由)。

If you want your device to be able to send to IP addresses that aren't on the directly attached subnet, you'll have to give it routes for those IP addresses.

You might be able to simply give it a default route through the PC (ie. a default route with a gateway of 10.0.0.70).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文