3

Context

Current status

For performance analysis, my company is interested in nanosecond resolution. So far, we have been using hardware timestamps and the support of nanoseconds was quickly hacked into the C libpcap library.

It seems that the support for nanoseconds has now been added to the library (see other Stack Overflow answer here), and the last version on the git repository makes the following method available:

pcap_open_offline_with_tstamp_precision(pathname, PCAP_TSTAMP_PRECISION_NANO, errbuf);

Future

The thing is, C has proven itself to be hardly maintainable, difficultly scalable and since we use the capture for analysis only, we feel like we could benefit from using Java instead. Being able to use a proper IDE, Maven, build web-services, etc. seems more important than speed of execution when it comes to performance analysis.

I first hoped to be able to use jNetPcap but I can't find out how to support nanosecond resolution with that Java binding of libpcap.


Question

jNetPcap

Does anyone know an easy way to read Pcap files with nanosecond precision, using jNetPcap?

Update: I just found mention of a TimestampResolution enum in jNetPcap's Javadoc. I will try to use that and update my answer later.

Note: I have also asked about nanosecond resolution directly on jNetPcap's support forum, and will update my question if I get any answer on that side...

Other solutions

Does anyone know about another way to profit from Java's ecosystem while still being able to read PCap files with nanosecond precision?


Thanks! :)

Community
  • 1
  • 1
snooze92
  • 3,959
  • 2
  • 24
  • 36
  • I haven't read the whole post, but is `System.nanoTime()` what you are searching? – hgoebl Nov 14 '13 at 07:45
  • Not at all, hehe! [`System.nanoTime()`](http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/System.html#nanoTime()) will give the value of the most precise available timer. It only allows for performance analysis within a given Java program. Read the rest of the post: in my case, I have hardware timestamp in a PCAP file, and I want to calculate latencies **a posteriori** – snooze92 Nov 14 '13 at 08:00
  • 1
    Sorry for not reading the whole post. If LGPL is not a problem for you, you could just fork the jNetPcap project and add nanosecond precision. It's just a wrapper if I understood correctly. – hgoebl Nov 14 '13 at 08:10

1 Answers1

1

I know this question is old, but just in case someone else has this need- if using jNetPcap is not a must, pcap4j seems to support it.

To open a cap:

PcapHandle h = Pcaps.openOffline(fname, PcapHandle.TimestampPrecision.NANO);

To read packet and timestamp:

Packet nextPacket = h.getNextPacket();
Timestamp timestamp = h.getTimestamp();

Hope that helps!

Yiftach
  • 198
  • 1
  • 1
  • 12