0

I am trying to make a packet sniffing Application and I had build it as a system Application for nexus 4.

r = pcap_findalldevs (&alldevs, errbuf);
printf("R==========%d",r);   

__android_log_write(ANDROID_LOG_ERROR, "Tag",errbuf );

error is E/Tag ( 4751): Can't open netlink socket 13:Permission denied

I cant capture any interface on my device. I have also given permissions to my application

Manifest.xml

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.NET_ADMIN"/>
<uses-permission android:name="android.permission.NET_RAW"/>
<uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES"/>
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
<permission-group android:name="android.permission-group.SYSTEM_TOOLS"></permission-group>
Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45

1 Answers1

0

Why are you logging an error? To quote the pcap_findalldevs() man page:

RETURN VALUE
   pcap_findalldevs() returns 0 on success and -1 on failure.   If  -1  is
   returned,  errbuf  is  filled  in  with  an  appropriate error message.
   errbuf is assumed to be able to hold at least PCAP_ERRBUF_SIZE chars.

If r is 0, no error occurred, and there is NO guarantee that errbuf contains anything meaningful. Do

if (pcap_findalldevs (&alldevs, errbuf) == -1)
    __android_log_write(ANDROID_LOG_ERROR, "Tag",errbuf );

instead.

  • could you please suggest any solution to avoid this error? Thanks in advanse – nauman siddiqui May 13 '15 at 10:34
  • What error? Unless `pcap_findalldevs()` returns -1, there is no error. Did you change your code to do what I said it should do - i.e., *check the return value of `pcap_findalldevs()` and print an error message only when it returns -1*, and then run it, and did it then print an error? –  May 13 '15 at 17:52