开发者

How to get TTL of a UDP packet in Java?

开发者 https://www.devze.com 2023-01-27 10:53 出处:网络
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 di开发者_运维知识库splays its data - very simple.

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 di开发者_运维知识库splays 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. :-)


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.


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号