c++inputstreamlibpcapjnetpcap

JNetPcap open pcap from InputStream


Is there a way to open an offline Pcap from an InputStream and not from a local file?

In the documentation it say that you can use pcap_fopen_offline() to open Pcap from an open stream but I don't know how to use it.


Solution

  • pcap_fopen_offline(3) is a C API of which JNetPCap works as a wrapper (you should have noticed this fact because naming convention is so different from Java API!) You don't have a direct access to it unless you code in C without JNetPCap (maybe you can access it with JNI/JNA, but that's no different from coding in C)

    Moreover, when a document about C API talks about "stream", it's almost always a "file stream" in C's terminology. It doesn't necessarily mean a data stream from a file in a filesystem, but you basically need to be fluent with C to use it anything other than STDIN/OUT or files in a filesystem. I quickly went through Javadoc of JNetPCap, but I don't think it can do the work of translating a general InputStream into C's file stream for you.