Simple and quick reading of ToS

2 replies [Last post]
colinmadere
Offline
Joined: 05/12/2010

v1.2 (via Maven)

Looking at: http://jnetpcap.com/docs/javadoc/jnetpcap-javadoc/index.html

I'm a little confused about how I get the ToS from the header

when using the javadoc-mentioned Pcap.dispatch() method that takes a ByteBufferHandler (does not mention the other dispatch methods are thread-safe, so if another version would give me better return objects for this purpose that would be good to know).

The handler interface's returned PcapHeader doesn't seem to have an API for IP header values, though I see in one of the examples an annotation-based class that would provide such an API call (but this is a different header, that maybe I have to peer to the ByteBuffer returned), though don't see that class actually in the API. Wondering if I should be "peering" something to tease this value out... ?

All suggestions welcome.

Thanks.

Mark Bednarczyk
Mark Bednarczyk's picture
Offline
Joined: 03/22/2008
If you want decoded packets,

If you want decoded packets, you should use Pcap.dispatch/loop that takes JPacketHandler which will dispatch fully decoded packets to you. Then to get at individual parts of the ip header use Ip4 object which provides the neccessary accessors. I would also suggest using the loop call, not the dispatch, unless you have very specific reason to do so.


pcap.loop

(Pcap.LOOP_INFINITE, new JPacketHandler() { private Ip4 ip = new Ip4(); public void nextPacket(JPacket packet, Object o) { if (packet.hasHeader(ip)) { System.out.printf("tos=0x%X%n", ip.tos()); } } }, null); Hope that helps.

Sly Technologies, Inc.
R&D

colinmadere
Offline
Joined: 05/12/2010
Thanks!

Thanks!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.