在Java中确定多播数据包的剩余TTL
如果我有一个侦听多播数据的 Java 程序,我如何知道传入数据报的剩余 TTL 是多少?
我知道如何在发送多播套接字上设置 TTL,但我想知道到达数据包的剩余 TTL。
If I have a Java program that listens to multicast data, how can I tell what the remaining TTL of the incoming datagram is?
I know how to set the TTL on the sending multicast socket, but I want to know the remaining TTL of the arriving packet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用原始套接字接收 UDP 数据报,您可以检查 TTL(或 IP 或 UDP 标头中的其他任何内容)。不过,也有很多问题:
If you receive the UDP datagrams with a raw socket you can inspect the TTL (or anything else in the IP or UDP headers). There are lots of gotchas, though:
到达的数据包是什么?数据报或 UDP 数据包实际上可以被分割成多个 IP 数据包,如果路由不同,这些数据包将以不同的 TTL 到达。无论哪种情况(无论是否拆分),Java 都不提供对 IP 标头的访问。
What is the arriving packet? A datagram or UDP packet can actually have been split into several IP packets, which arrive with different TTLs if they are routed differently. In either case (split or not), Java doesn't provide access to the IP header.
我看了(我想你也这么做了),但找不到一个很好的 Java API 来执行此操作。
TTL 是 IPv4 数据报中的第 9 个完整字节。如果从传入数据报中输出 DatagramPacket 的第 9 个字节,会发生什么情况?这看起来像 TTL 值吗?或者,IP 数据报的标头在 DatagramPacket 中不可用,只有 IPv4 数据报的数据部分可用?
I looked (as I imagine you did as well), but could not find a nice Java API for doing this.
The TTL is the 9th whole byte in an IPv4 datagram. What happens if you output the 9th byte of the DatagramPacket from an incoming datagram? Does that look like the TTL value? Or, are the headers from the IP datagram not available in DatagramPacket, only the data portion of the IPv4 datagram?