pcap4j icon indicating copy to clipboard operation
pcap4j copied to clipboard

Add support for Android

Open kaitoy opened this issue 12 years ago • 20 comments

kaitoy avatar Apr 14 '13 04:04 kaitoy

GOGOGO

kyangc avatar Aug 19 '15 03:08 kyangc

Oh. I've forgotten this....

kaitoy avatar Aug 27 '15 04:08 kaitoy

How is the issue going?

chenenyu avatar Oct 26 '16 10:10 chenenyu

I'm working on v2 and just waiting for someone's contribution for Android support for now....

kaitoy avatar Oct 26 '16 17:10 kaitoy

Hey, how is the development going? Is there an ETA?

rdinkel avatar Nov 29 '16 07:11 rdinkel

I'm planning to complete v2 development in March 2017. Then I will have time for Android support. It would take a month, I think.

kaitoy avatar Nov 30 '16 05:11 kaitoy

I successfully added your library in Android project. I just need to write a Pcap file with ipv4 packets got from VPN . How can I do it?

krupalshah avatar Mar 07 '17 16:03 krupalshah

Sorry but I'm not yet familiar with Android. It seems DNS66 project is using Pcap4J on Android, so could you consult its author?

kaitoy avatar Mar 13 '17 15:03 kaitoy

Can i use this on Android to send ARP packet?

ghost avatar Apr 22 '17 07:04 ghost

I have no idea for now.

kaitoy avatar Apr 22 '17 08:04 kaitoy

Ok Thanks

ghost avatar Apr 22 '17 08:04 ghost

Trying this library on android, I got:

FATAL EXCEPTION: main Process: com.play.around, PID: 29329 java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-arm/libjnidispatch.so) not found in resource path (.) at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:866) at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:826) at com.sun.jna.Native.(Native.java:140) at com.sun.jna.Pointer.(Pointer.java:41) at com.sun.jna.ptr.PointerByReference.(PointerByReference.java:28) at com.sun.jna.ptr.PointerByReference.(PointerByReference.java:24) at org.pcap4j.core.Pcaps.findAllDevs(Pcaps.java:48) at org.pcap4j.util.NifSelector.selectNetworkInterface(NifSelector.java:38) at com.play.around.MainActivity.sendArpRequest(MainActivity.java:73) at com.play.around.MainActivity$1.onClick(MainActivity.java:51) at android.view.View.performClick(View.java:5204) at android.view.View$PerformClick.run(View.java:21153) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

elile avatar May 05 '17 16:05 elile

How is the issue going?

tinyoculus avatar Jul 06 '17 10:07 tinyoculus

No progress actually... I need to find someone who can help me.

kaitoy avatar Jul 08 '17 01:07 kaitoy

I am not sure why this is happening. I got to the point where all the ".so" library would load properly but after that I get this error:

FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Error looking up function 'pcap_dump': undefined symbol: pcap_dump
    at com.sun.jna.Function.<init>(Function.java:212)
    at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:541)
    at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:518)
    at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:468)
    at com.sun.jna.Function.getFunction(Function.java:82)
    at org.pcap4j.core.NativeMappings.<clinit>(NativeMappings.java:47)
    at org.pcap4j.core.NativeMappings.pcap_findalldevs(Native Method)
    at org.pcap4j.core.Pcaps.findAllDevs(Pcaps.java:51)
    ...........

However for this I had to custom compile libpcap(1.8.1) from here and include it in the project.

Is it that using libpcap 1.1.1 will fix this issue? or is this a entirely different problem?

I also tried to look at the DNS66 project. Didn't find anything special to make pcap4j work. :(

writzx avatar Mar 15 '18 06:03 writzx

UPDATE: I got around the error that I was getting a while ago, and it was because of wrong config for building libpcap. I used the 1.3.0 version from here.

After compiling successfully, I found another problem. pcap4j can't find any interface in the device. Pcaps.findAllDevs() returns 0 length list. NifSelector().selectNetworkInterface() returns null. Most probably this is because of root access blocking the scan and root in android is only available via shell.

writzx avatar Mar 17 '18 06:03 writzx

I think so, too. libpcap needs root privileges.

kaitoy avatar Mar 19 '18 10:03 kaitoy

However, I noticed that tcpdump successfully and correctly runs and dumps all the packet information. The reason is most likely it can get root permission as its a native executable. That makes the only way to sniff on Android is using a native executable with a shell wrapper around it.

writzx avatar Mar 19 '18 11:03 writzx

the main problem from what I can see is that you can't really have the app itself run in a root context (you can only open a root shell and run native programs from there). I was able to get it to work by re implementing the NativeMappings so instead of loading libpcap into the java process, I created a proxy native program that loads the library (and we can run it with root permissions from a shell) and using some dumb ipc (basically just using stdio) it will talk with the java program that will do all the calls.

I have not tested it with sending packets but I can get all the interfaces (even tho I am getting alot of not supported address families) and I can receive packets so it looks promising.

for the code of the native program and for the code of the java side

Itay2805 avatar Oct 19 '19 01:10 Itay2805

Sir,How is it going?I want to get some Information in LAN. I find it is available for Windows and Linux,But it is not useful when I play on the Android. Do you have any suggestions?

romantictree avatar May 21 '20 03:05 romantictree