The JNI Solution
You need to wrap the calls and the logic you need out of libpcap in C or C++ and expose the underlying functions through JNI
(Java Native Interface) so your application can call native code in Java.
The documentation on JNI
is pretty complete on internet, a lot of tutorials exists on this subject such as this one.
If you want to easily wrap native code in JNI you can use Swig
which allow you to automatically generate JNI code based on your C/C++ native headers.
The obtained JNI code should be compiled using the Android NDK as a dynamic library (.so). This library is to be placed in your application package under libs/
. You can then invoke System.loadLibrary(path_to_you_dynamic_library)
to load all the symbols contained in the library and use them in Java.
Using a third-party library
If you're afraid of getting headaches while figuring out how to use JNI, you can look at this library which does the hard work for you, and provides an API to manipulate raw sockets in Java.
http://www.savarese.com/software/rocksaw/