Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android use pcap library

I have a general question according an android app, I need to use some pcap functionality in my android app. Because java does not give the possibility in raw packet injections and low layer programming (as far as I know, pls correct me if I'm wrong) so I was looking for an alternative. So far I found the following:

  • ANDROID NDK
  • JNETPCAP

Any suggestions which one I should use or does anyone have other suggestions?

like image 297
wasp256 Avatar asked Feb 17 '23 02:02

wasp256


1 Answers

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/

like image 178
Halim Qarroum Avatar answered Feb 27 '23 15:02

Halim Qarroum