设置多播加入的 UDP 数据报源

发布于 2025-01-06 15:23:21 字数 707 浏览 3 评论 0原文

我有一台 Windows XP 计算机,它有一个带有 2 个 IP 地址的网络适配器(基本上同一物理网络上有 2 个子网):

IP 地址 1:1.51.1.2 掩码 255.255.0.0

IP 地址 2:1.162.1.2 掩码 255.255.255.0

默认网关:1.51.1.1

我用java编写的应用程序需要使用IP多播与其他应用程序通信比如说IP 224.0.5.1。但是,这并不像我将第二个 IP 地址添加到网络适配器那样有效。我用旧的 Wireshark 进行了一些挖掘,得出的结论是 IGMP 加入请求是问题所在。如果有效,则数据报上的源 IP 为 1.51.1.2;如果无效,则数据报上的源 IP 为 1.162.1.2。如果源与它本身配置的不在同一子网上,作为路由器的网关似乎会忽略加入。你可能会说这有点好(尽管 IGMP 规范在这里有点沉默),但在我迄今为止看到的许多套接字 API 中,我看不到任何实际影响数据报源 IP 的方法。一切似乎都发生在网络接口上,与实际使用的子网无关。

同样奇怪的是,数据报上的源 IP 实际上被选择为最高的 IP 编号,我认为这是可预测的,但并不完全直观。所以这是我的问题:

  • Java 或任何本机 Windows 库是否有任何方法可以在 IGMP 请求的 UDP 数据报上设置源 IP?
  • 事实上,网关会忽略连接,因为它无法识别源,这是正确的行为吗(我将采用事实上的行为,因为规范在这一点上很模糊)?

I have a windows XP machine having a single network adapter with 2 IP addresses (basically there are 2 subnets on the same physical network):

IP Address 1: 1.51.1.2 mask 255.255.0.0

IP address 2: 1.162.1.2 mask 255.255.255.0

Default Gateway: 1.51.1.1

My application which is written in java needs to communicate with other applications using IP multicast on say IP 224.0.5.1. However, this does not work as sound as I add the second IP address to the network adapter. I have done some digging with good old Wireshark and come to the conclusion that the IGMP join request is the problem. The source IP on the datagram is 1.51.1.2 in the case where it works and 1.162.1.2 when it does not. The gateway which is a router seem to ignore the join if the source is not on the same subnet as it itself is configured to be on. You could say that is somewhat fine (although the IGMP spec is a bit silent here), but I cannot see any way to actually influence the source IP of the datagram in any of the many socket APIs I have looked at so far. Everything seems to occur on the network interface with no regards to the actual subnet used.

Also strangely it seems that the source IP on the datagram is actually chosen to be the highest IP number which I guess is predictable but not exactly intuitive. So here are my questions:

  • Is there any way in Java or any of the native windows libraries to set the source IP on the UDP datagram of the IGMP request?
  • Is the fact that the gateway ignores the join because it does not recognise the source the correct behavior (I am going with de facto behavior as the spec is vague on this point)?

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

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

发布评论

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

评论(1

睡美人的小仙女 2025-01-13 15:23:21

关于一种实际影响数据报源IP的方法

SocketOptions.setOption(IP_MULTICAST_IF, InetAddress);

或者

MulticastSocket.setInterface(InetAddress)

About a way to actually influence the source IP of the datagram:

SocketOptions.setOption(IP_MULTICAST_IF, InetAddress);

OR

MulticastSocket.setInterface(InetAddress)

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