can jnetpcap use jna instead of jni?

At first, thanks for your contribution.

just as a question: will jnetpcap become better if uses jna instead of jni?
if using jna, you will not need to compile native wrapper (such as jnetpcap.dll) for various platform, we can link libpcap.so (or wpcap.dll) with java class directly, only one jar library is enough. it will also support the max number of platforms, for example MacOS, BSD, etc. jna can do these for you.

just an idea: why not split jnetpcap to more functional jars? like what many java frameworks do.
For example, such as jnetpcap.jar for pure wrapper, jnetanalyzer.jar for analyzing various packet protocol, jnetdump.jar for dumping or reading packets, other jars for other functions. splitting them to different project functionally make better to use them. sometimes, somebody maybe only want to get an analyzer but dumper, And sometimes oppositely.

OutOfMemory Exception with PcapPacketHandler

I want to create some own Packets from a .pcap File and do some Simualtion stuff. After that i want to recreate the .pcap File to compare both. I use jnetpcap-1.4.r1390 on Windows 7. So i try this version:
public static void main(String[] args) throws ClassNotFoundException{
jnet jn = new jnet();
for(int i = 0;i<PL.packets.size();i++){
In handlingPackets i want to loop the packets and put them all after createPacket in a ArrayList called packets in a external Interface:
public void handlingPackets(int n){
    pcap.loop(n,  new PcapPacketHandler<StringBuilder>(){
    public void nextPacket(PcapPacket packet, StringBuilder user) {
}, errbuf);
public void createPacket(PcapPacket buffer){
// PAKETE in die AL packen!
PL.packets.add(new Packet(this.id,this.flow_id,this.time, this.length,this.destAdd,this.protocol,this.destPort,buffer,header));
At the end i try to write the captured Packets in a new File:
public void writeFile(JCaptureHeader header, JBuffer buffer){   
With "small" Files (packets less than 60k this works great! But if the Files getting bigger then i get a OOM error :
Exception in thread "main" java.lang.OutOfMemoryError
at org.jnetpcap.Pcap.loop(Native Method)
at org.jnetpcap.Pcap.loop(Unknown Source)
at jnet.handlingPackets(jnet.java:80)
at jnet.main(jnet.java:201)
i do some DisposableGC after putting a packet in the arrayList and i also checked the packetNumber where the programm stops.

Calculate time difference between the capture of two packets


I have a question about time difference calculation between two packets captured using jnetpcap. My goal is to calculate the throughput in real time of a video stream between a sender and a receiver. I have a server which is sending the video frames and is capturing using jnetpcap all outgoing packets and saves their timestamps. I have a client which is receiving the video frames, displaying them, and also captures all incoming packets and saves their timestamps. I would like to calculate the difference between the receiving time and the sending time of each video packet as accurately as possible, which will give me the actual time each packet spent "on the wire" and then use this value, and the size of the packet to calculate the throughput.

I already have the application working, my clocks on the server and the receiver are synchronized before starting the stream and I'm correctly capturing 90% of the packets, but the calculated throughput is not close enough to the actual value. The packet size is fixed and I know it, I have my own protocol to keep track of the frame numbers so I'm pretty sure I'm using the correct Received-Sent packet pairs to calculate the difference, the standard deviation of the captured packets is not high so the calculated throughput values are fairly close to each other but not close to the actual value so the only problem I can see right know is that the calculation of the time difference between the capture times is not accurate enough...

For the calculation I'm doing the following:
long sendTimeInMillis = pcapPacketOut.getCaptureHeader().timestampInMillis();
long receiveTimeInMillis = pcapPacketIn.getCaptureHeader().timestampInMillis();

long timeOnTheWireMillis = receiveTimeInMillis - sendTimeInMillis;
long timeOnTheWireSeconds = timeOnTheWireMillis * 1000;

double throughput = (double) timeOnTheWireSeconds / packetSizeInBits;

So after the long intro, here are my questions:)

Problem with ClassicPcapExample

Hi, I'm testing the example http://jnetpcap.com/examples/classic, but when I run it I get

Network devices found:
#0: \Device\NPF_{6673F9A1-7413-4C19-8D8E-6288B653124A} [Microsoft]
#1: \Device\NPF_{EC165E47-7983-45DC-B201-36594D8A9BC9} [Broadcom NetLink (TM) Gigabit Ethernet Driver]
#2: \Device\NPF_{04D551A6-DE8B-4D1A-8A45-27F9B962CA3C} [Microsoft]

Choosing 'Broadcom NetLink (TM) Gigabit Ethernet Driver' on your behalf:

And nothing more. Why? all other examples give me the same empty answare.


[SOLVED] UnsatisfiedLinkError from executable .jar in Eclipse

First of all I'd like to thank the team (or person) behind this great library. I've learned to use it in no time at all.

I've created a little packet sniffer using eclipse and I wanted to create an executable .jar. I've followed each and every one of the steps in the eclipse setup tutorial http://jnetpcap.com/eclipse and then exported the .jar using the option "Package required libraries into generated JAR". The problem is that whenever I run it, I get this error message:

C:\Documents and Settings\Administrador\Escritorio\masterTest>java -jar Capturad
or2.jar "LAN0:" 3 10000
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
Caused by: java.lang.UnsatisfiedLinkError: com.slytechs.library.NativeLibrary.dl
        at com.slytechs.library.NativeLibrary.dlopen(Native Method)
        at com.slytechs.library.NativeLibrary.<init>(Unknown Source)
        at com.slytechs.library.JNILibrary.<init>(Unknown Source)
        at com.slytechs.library.JNILibrary.loadLibrary(Unknown Source)
        at com.slytechs.library.JNILibrary.register(Unknown Source)
        at com.slytechs.library.JNILibrary.register(Unknown Source)
        at com.slytechs.library.JNILibrary.register(Unknown Source)
        at org.jnetpcap.Pcap.<clinit>(Unknown Source)
        at jnetpcap.main.Capturador.obtenerListaDeInterfaces(Capturador.java:485
        at jnetpcap.main.Capturador.primerPaso(Capturador.java:88)
        at jnetpcap.main.Launcher.main(Launcher.java:18)
        ... 5 more

Syndicate content