6

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

mreichelt
  • 12,359
  • 6
  • 56
  • 70
  • possible duplicate of [Determine the remaining TTL of a multicast packet in Java](http://stackoverflow.com/questions/1723429/determine-the-remaining-ttl-of-a-multicast-packet-in-java) – Stephen C Nov 25 '10 at 14:19
  • (And the answer seems to be that it is not possible in pure Java to get the remaining TTL, and that TTL only strictly makes sense at the raw IP packet level.) – Stephen C Nov 25 '10 at 14:20

2 Answers2

3

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.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • Thanks - of course you are right. I totally forgot that this field is available on IP layer only. :-) So basically it is not possible until one captures the packets on a lower layer. – mreichelt Nov 25 '10 at 14:34
0

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

P Marecki
  • 1,108
  • 15
  • 19