jNetPcap v2 - Implementation

No replies
Mark Bednarczyk
Joined: 03/22/2008

As to implementation of jNetPcap v2 API and library here are my thoughts. This is all up for discussion, so please comment.

Of course, as they say, "the devil is in the details", it is very true.

Technologies to utilize

Here are some technologies that I believe we could benefit from. These are chosen to be have least amount of development and runtime depencies.

Gradle for builds

Gradle is the latest and most configurable build system, supplanting 'maven'.

Simple and designed for multi-modular builds. Available as extensions and great support for all of the major IDEs including eclipse.

CCNI for JNI implementation

Sly Techs has a new compiler developed for JNI. This is called CCNI and provides super easy integration of native and java code.

Over the years JNA has also been suggested as it is widely supported on various platforms. However, I personally do not like JNA because code overhead, too generic and too many encapsulations even of simple things as well as it has runtime requirements.

CCNI is easier to follow as it follows the same style as jsni from Google/GWT toolkit but for C and C++ languages. It is easy to integrate into builds. The CCNI compiler is pure java and thus able to run on any platforms as long as it can generate the target code (OS specific). There are no runtime prerequisites, it still generates a static or shared library with all of the user code included.

Here is a quick "HelloWorld" example of code written using CCNI:

public class HelloWorld {

	public native static String createString()
		jstring strObj = (*env)->NewStringUTF(env, "Hello World!");
		return strObj;

	public static void main(String[] args) {
		String str = HelloWorld.createString();

And a slightly more complex example which sums up the integers within a range and sets a class field from JNI. The @CType annotation instructs the CCNI compiler to generate a stub functions in C to get and set the java field's value, as it demonstrated on line #16.

package org.cni.examples;

import org.cni.annotation.CType;

public class SumIntegers {

	private @CType long	calculated;

	public native void calculateSum(int max)
		jlong sum = 0;
		for (int i = 0; i < max; i ++) {
			sum += i;
		SumIntegers_set_calculated(env, self_arg, sum);

	public static void main(String[] args) {
		int max = (args.length == 1 ? Integer.parseInt(args[0]) : 1000000);

		SumIntegers worker = new SumIntegers();



Operating systems to support

We have to hit the major ones out the gate. Its that simple!

  1. Windows
  2. Linux
  3. FreeBSD
  4. Mac/OSX
  5. Solaris
  6. HP/UX
  7. AIX

Other possibilities are Android and IOS.

Build script maintainers and builds

We could really use help from some volunteers in this area. Sly Techs will provide access to servers and build systems, but we need to maintain the build scripts professionally and implement various continues integration tools such as Jenkins.


We could use the help of all of the community on testing and feedback.

Sly Technologies, Inc.