Skip to content

Integration of jnetPcap into Packet Analyzer

prasadtalasila edited this page Feb 2, 2016 · 1 revision

About jnetPcap

jNetPcap is an open-source java library. It contains:

  • A Java wrapper for nearly all libpcap library native calls
  • Decodes captured packets in real-time
  • Provides a large library of network protocols (core protocols)
  • Users can easily add their own protocol definitions using java SDK
  • jNetPcap uses a mixture of native and java implementation for optimum packet decoding performance

For more detailed information follow these javadocs.

Installing jnetPcap into Local Maven Repo

Installing jnetPcap for this project is somewhat a non-trivial task. Since jnetPcap is not available in central maven repository, it cannot be installed by just adding a dependancy in pom.xml file.
One can go to this url to download corresponding package for jnetPcap. Version 1.3.0 is the stable version and all 1.4 variants are under active development at the time of writing of this document.

Once you have downloaded the corresponding tar file, extract the contents to any directory of your choice. The extracted contents must have a jnetpcap.jar file. This jar file is the one that has to be installed in your local maven repository.

To install jnetpcap jar file in local maven repository use the following command -

mvn install:install-file

Following arguments should also be given for installing the file -

  • Path to file: -Dfile="/path/to/file.jar"
  • GroupId: -DgroupId="jnetpcap"
  • artifactId: -DartifactId="jnetpcap"
  • version: -Dversion="1.3.0"
  • packaging: -Dpackaging="jar"

You can follow more detailed documentation about installing third party JARs in local maven repository here.

After maven has installed the jar file, update your pom.xml file as with dependency on jnetpcap with corresponding groupId, artifactId and version.

Making jnetPcap work with Tomcat

Many would think that the job is done at the end of the installing process but it is not so. If you try to build and deploy the operation on Tomcat, it will run as long as any code the application is using does not use jnetPcap library code. But once any part of application uses it you'll get a 500 response from server saying -

java.lang.UnsatisfiedLinkError: no jnetpcap in java.library.path

To resolve this error -

  • Go to directory where jnetPcap tarball was extracted.
  • There will be a file named libjnetpcap.so. Copy this file to /usr/lib (you will probably need sudo access)
  • Go to $TOMCAT_HOME/bin. Define a file(if not there already) named setenv.sh. Enter the following command -
    export JAVA_OPTS="-Djava.library.path=/usr/lib"
  • Save this file and redeploy application on Tomcat. Now it should run without any exceptions.
Clone this wiki locally
You can’t perform that action at this time.