5

I've sucessfully compiled jNetPcap as a shared library for Android. I have made a simple application using this code: http://jnetpcap.com/examples/classic to test the API.

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

I cannot understand the reason, since I have made a call in the first part of my program so as to get root permissions for my application and I test my application to a rooted phone. When I run the application, a pop up is raised with this message:"SnifferApp has been granted Superuser permissions" and then the exception occurs.

Any ideas?

Here is a piece 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; 
 }
Thanasis Petsas
  • 4,378
  • 5
  • 31
  • 57
  • Hi, I've the same problem with my application. I was able to install jnetpcap but when running the 'findAllDevs' function I receive an Empty List, no errors in errbuf... I was wondering if you have solved the problem? I am already running the applicaiton as root: $sudo -i -> root#eclipse -> start the AVD in eclipse – wasp256 Apr 04 '13 at 19:36
  • I didn't solved it at all. Finally, I used native code to run my experiments.. If I find something I'll let you know. – Thanasis Petsas Apr 05 '13 at 11:03
  • Thanasis Petsas I have the same problem. I have complied JnetPcap library successfully with Android NDK, but when I run this classic example from the official JnetPcap website the alldevs.size() returns 0. Did you solve it??? – Panagiotis Jan 08 '16 at 10:53
  • Dear Ezazel, It has been a long time since I worked on it. As far as I remember I hadn't found an explanation or solution about this.. – Thanasis Petsas Jan 12 '16 at 15:13

1 Answers1

0

As far as I understand, you're creating a new process and getting superuser permission, but your app doesn't have them.

Try adding this permission in your manifest file:

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

as I guess findAllDevs is going to open the network devices on the phone.

Trasplazio Garzuglio
  • 3,535
  • 2
  • 25
  • 25
  • Yes, by doing this the the value of Pcap.NOT_OK is false :), but the code reaches again the if block due to the fact that the alldevs.isEmpty() is true.. And now the errbuf contains nothing.. I tried to add more permissions in the manifest file: – Thanasis Petsas May 12 '11 at 13:02
  • It's because your app is not running as root. Maybe what you can do is create two apps. Your normal application that uses pcap and a "launcher" that fires up your normal app as root. Something like "su -c ". can be a script that uses __am start ...__ to launch your application. It's just an idea, good luck. – Trasplazio Garzuglio May 12 '11 at 15:53
  • yes I tried to do this! I typed for first time: $su #am start -a android.intent.action.MAIN -n com.sniffer.jni/com.sniffer.jni.SnifferApp but the application run as before with app priveleges (ps shows:app_79 9844 55 128016 17812 ffffffff afe0dab4 S com.sniffer.jni). Then I tried this: # su -c am start -a android.intent.action.MAIN -n com.sniffer.jni/com.sniffer.jni.SnifferApp and I got this: Permission denied :( – Thanasis Petsas May 13 '11 at 11:41
  • I think - do not have to run the process with the root privileges. Android - is Linux (modified). After starting the application, you can try to add the application's UID to a specific group, which provides the necessary permissions (using root shell). I do not have a chance to try it. – Aleksandr Nov 07 '12 at 11:06
  • 1
    Is it really necessary to be root just to get a list of network devices? Isn't this what the Android permissions are for? – Yahma Mar 16 '13 at 17:05