February 2017

Jnetpcap not working from commandline but works in eclipse

Hi There
I was hoping someone might be able to point me in the right direction as to why im getting this error when running my application using java from the command line after compiling the java file with javac (which works with no errors). I have copied the dll (jnetpcap.dll) is in C:\Windows\System32 directory and set the ClassPath in windows:

C:\>echo %CLASSPATH%
C:\jnetpcap\jnetpcap.jar

The code works just fine when i run it in eclipse it capures IP addresses no problem. But when i try compiling the .java file from the command line using "javac PackageCapture" i dont get an error but i get 2 class files for some reason (see below):

C:\Users\Anthony.mcgoverna-lt\workspace_neon\packet_ver01\src\packet_sniffer>dir

Directory of C:\Users\Anthony.mcgoverna-lt\workspace_neon\packet_ver01\src\packet_sniffer

22-Feb-17 11:25 AM

.
22-Feb-17 11:25 AM ..
22-Feb-17 11:24 AM 6,456 PackageCapture.java
16-Feb-17 06:34 PM 1,566 sniff_ver1.java
2 File(Drunk 8,022 bytes
2 Dir(Drunk 336,621,965,312 bytes free

Then i compile the .java file (no errors)

C:\Users\Anthony.mcgoverna-lt\workspace_neon\packet_ver01\src\packet_sniffer>javac PackageCapture.java

Then i get 2 class files for some weird reason

C:\Users\Anthony.mcgoverna-lt\workspace_neon\packet_ver01\src\packet_sniffer>dir

Directory of C:\Users\Anthony.mcgoverna-lt\workspace_neon\packet_ver01\src\packet_sniffer

22-Feb-17 11:26 AM

.
22-Feb-17 11:26 AM ..
22-Feb-17 11:26 AM 2,027 PackageCapture$1.class
22-Feb-17 11:26 AM 2,517 PackageCapture.class
22-Feb-17 11:24 AM 6,456 PackageCapture.java
16-Feb-17 06:34 PM 1,566 sniff_ver1.java
4 File(Drunk 12,566 bytes
2 Dir(Drunk 336,621,957,120 bytes free

reading from offline file slow

Hi there,
I am using this code

...
pcap.loop(numFrames, new JPacketHandler() {
public void nextPacket(JPacket packet, StringBuilder errbuf) {

// final Tcp tcp = new Tcp();
// final Udp udp = new Udp();
// final Ip4 ip = new Ip4();

if (hasHeaders(packet)) {
frameData.add(new Frame("timestamp", "source ip", "destination ip", "protocol", packet.getTotalSize(), "payload" ));
}

}

}, errbuf);

...

to load packets from an offline file, but it takes around 7 minutes to load files with 100mb (around 730k packages). Is there any way to up the performance or am I stuck with it? Sorry I'm a beginner.

Also what would be the smartest way to get the data mentioned in the code from the packet?

Using jnetpcap 1.4r1425 on 64 bit W7
Thank you very much!

Solution to "glibc detected java: malloc(): memory corruption" Error

Hi, User aboyapati issued a crash bug last year (http://jnetpcap.com/node/1431). I experienced same issue on linux and I flew a day solving it. Without valgrind, it would have been impossible. I attached a patch file, but this site requires you to login to view the patch file.