JNetPcap on Android: problem with findAllDevs method!

I have successfully compiled jNetPcap as a shared library for Android. I made a simple application using this code: http://jnetpcap.com/examples/classic for testing the API.

The problem is that when I call the findAllDevs method and an exception is raised with this message: "Unable to read the list of devices, error issocket: Permission denied"

I can not understand the reason, since I made a call in the first part of my program to get root privileges for my application, and I am testing my application on the root phone. When I launch the application, a pop-up message is raised using this message: "SnifferApp received superuser permissions", and then an exception occurs.

Any ideas?

Here is a snippet of my code:

Process p = Runtime.getRuntime().exec("su");
/*try {
    Thread.sleep(10000);
} catch (InterruptedException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} // do nothing for 1000 miliseconds (1 second)
*/
try {
        System.loadLibrary(JNETPCAP_LIBRARY_NAME);
}
catch (UnsatisfiedLinkError e) {
    System.out.println("Native code library failed to load.\n" + e);
}

 /***************************************************************************
 * First get a list of devices on this system
 **************************************************************************/ 
 int r = Pcap.findAllDevs(alldevs, errbuf);
 r = Pcap.findAllDevs(alldevs, errbuf);
 if (r == Pcap.NOT_OK || alldevs.isEmpty()) { 
    tv.append("Can't read list of devices, error is" + errbuf 
    .toString());
    setContentView(tv);
    return; 
 }
+5
source share
1 answer

As far as I understand, you create a new process and get superuser permission, but your application does not have it.

Try adding this permission to the manifest file:

<uses-permission android:name="android.permission.INTERNET" /> 

I think findAllDevs is about to open network devices on the phone.

0

All Articles