Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get TTL of a UDP packet in Java?

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

like image 888
mreichelt Avatar asked Oct 26 '22 01:10

mreichelt


1 Answers

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.

like image 164
unwind Avatar answered Nov 15 '22 06:11

unwind