Java中如何获取UDP数据包的TTL?
我正在使用 Java 应用程序将 UDP 数据包发送到 Android 设备。我有另一个 Java 应用程序,它接收这些 UDP 数据包并显示其数据 - 非常简单。
现在我正在研究一些路由算法 - 因此最好知道 UDP 数据包自发送以来经过了多少跳。我的想法是读出数据包的 TTL(生存时间)值并显示它。你知道纯 Java 是否可以实现这一点吗?类 DatagramPacket
根本没有给出任何提示。
我想这是不可能的,因为这些信息可能已经在较低层被删除,但我只是想确定一下。 :-)
I am using a Java application to send UDP packets to an Android device. There I have another Java application that receives these UDP packets and displays its data - very simple.
Now I am working on some routing algorithms - therefore it would be nice to know how many hops a UDP packet did since it was send. My idea is to just read out the TTL (time-to-live) value of the packet and display it. Do you know if this is possible with pure Java? The class DatagramPacket
doesn't give any hints at all.
I guess that this is not possible because this information might already have been removed at a lower layer, but I just want to be sure. :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如您所知,TTL 字段 是底层 IP 协议的一项功能(当使用),而不是 UDP。因此,它在 DatagramPacket API 中不可见是有道理的。不过,我认为你是对的;通常不可能通过数据报级 API 访问 IP 数据包。您可能需要研究数据包捕获。
The TTL field is, as you know, a feature of the underlying IP protocol (when used), not of UDP. So it makes sense for it not to be visible in the DatagramPacket API. However, I think you're right; it's not normally possible to get access to the IP packets through datagram-level API:s. You probably need to look into packet capture.
出于您的目的,如果我正确理解,就足以操纵发送者的 TTL;例如,将发送套接字的 TTL 设置为 1,2,3,4,5,并为每个发送一条内容为“1”、“2”、“3”、“4”或“5”等的消息。有些可能是接收器上丢失...
For your purpose, if I get it correctly, it would be sufficient to manipulate the TTL of the sender; e.g. set TTL of the sending socket to 1,2,3,4,5 and for each send one message with content "1","2","3","4" or "5" etc. Some will likely be missing on the receiver...