compile libpcap on android with ndk

1,868 views
Skip to first unread message

Nivas Maguluri

unread,
Jun 17, 2010, 5:49:16 PM6/17/10
to android-ndk
i created android-ndk project called NativeAdd. Added libcap open
source folder under android-ndk root directory. When I compile the
libpcap code with ndk, I came up with errors.

Android.mk file under jni directory:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := NativeAdd

LOCAL_SRC_FILES := NativeAdd.c

LOCAL_C_INCLUDES := $(NDK_ROOT)/external/libpcap

LOCAL_STATIC_LIBRARIES := libpcap

LOCAL_LDLIBS := -ldl -llog

include $(BUILD_SHARED_LIBRARY)

include $(NDK_ROOT)/external/libpcap/Android.mk

The libpcap code is from android.git.kernel.org Git.

/home/subba/AndroidSDKWorkSpace/NativeAdd/bin/ndk/local/armeabi/
libpcap.a(gencode.o): In function `pcap_compile':
/home/subba/AndroidSDK/android-ndk-r4/external/libpcap/gencode.c:389:
undefined reference to `pcap_parse'
/home/subba/AndroidSDKWorkSpace/NativeAdd/bin/ndk/local/armeabi/
libpcap.a(scanner.o): In function `yylex':
/home/subba/AndroidSDK/android-ndk-r4/external/libpcap/scanner.l:335:
undefined reference to `pcap_lval'
/home/subba/AndroidSDKWorkSpace/NativeAdd/bin/ndk/local/armeabi/
libpcap.a(scanner.o): In function `yy_get_next_buffer':
/home/subba/AndroidSDKWorkSpace/NativeAdd/<stdout>:3726: undefined
reference to `pcap_lval'
collect2: ld returned 1 exit status
make: *** [/home/subba/AndroidSDKWorkSpace/NativeAdd/bin/ndk/local/
armeabi/libNativeAdd.so] Error 1
subba@subba-laptop:~/AndroidSDKWorkSpace/NativeAdd$


Environment details :
Android-ndk-r4
make 3.8.1
ubuntu 8.10

`pcap_parse' function exists in grammr.c. Still it complains about
undefined reference. Is there some source or library I need to add to
compile?








Onur Cinar

unread,
Jun 17, 2010, 6:42:07 PM6/17/10
to android-ndk

Hi Nivas,

You will need to either remove the following line from the grammer.c

#define YYBISON 1

Or, you will also need to include the bison library from:

http://android.git.kernel.org/?p=platform/external/bison.git;a=summary

Regards,

-onur



On Jun 17, 2:49 pm, Nivas Maguluri <core.test.accou...@gmail.com>
wrote:
---
www.zdo.com

albert jordan

unread,
Jun 17, 2010, 7:39:29 PM6/17/10
to andro...@googlegroups.com
Thanks onur for quick response.

grammar.c file is automatically generated by grammar.y. I commented YYBISON in the following places

grammar.y and grammar.c:

//#ifndef YYBISON
int yyparse(void);

int
pcap_parse()
{
    return (yyparse());
}
//#endif

And then to get it compile fully i have to comment following code in scanner.c and scannerl.

//#define yylval pcap_lval

Now i am able to compile libpcap with my ndk application and able to print libpcap version name on activtiy. However commenting those lines may effect functionalities ?Any idea.


 


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Onur Cinar

unread,
Jun 17, 2010, 8:26:25 PM6/17/10
to android-ndk

Hi Albert,

Good news! Well, functionality wise, looks like the grammer.c also
provides an implementation for the yyparse function. But I would still
try to include the bison library as well just to be safe.

http://android.git.kernel.org/?p=platform/external/bison.git;a=summary

Best regards,

-onur

On Jun 17, 4:39 pm, albert jordan <core.test.accou...@gmail.com>
wrote:
> Thanks onur for quick response.
>
> grammar.c file is automatically generated by grammar.y. I commented YYBISON
> in the following places
>
> grammar.y and grammar.c:
>
> //#ifndef YYBISON
> int yyparse(void);
>
> int
> pcap_parse()
> {
>     return (yyparse());}
>
> //#endif
>
> And then to get it compile fully i have to comment following code in
> scanner.c and scannerl.
>
> //#define yylval pcap_lval
>
> Now i am able to compile libpcap with my ndk application and able to print
> libpcap version name on activtiy. However commenting those lines may effect
> functionalities ?Any idea.
>
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-ndk?hl=en.
>
>

---
www.zdo.com

albert jordan

unread,
Jun 17, 2010, 8:56:19 PM6/17/10
to andro...@googlegroups.com
Onur,

I am trying to compile bison with my ndk application, it gives the following error. I have added bison open source code from git to the ndk root directory in external folder.

Here is Anroid.mk file:-


LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := NativeAdd

LOCAL_SRC_FILES := NativeAdd.c

LOCAL_C_INCLUDES := $(NDK_ROOT)/external/bison

LOCAL_STATIC_LIBRARIES := bison


LOCAL_C_INCLUDES := $(NDK_ROOT)/external/libpcap

LOCAL_STATIC_LIBRARIES := libpcap

LOCAL_LDLIBS := -ldl -llog

include $(BUILD_SHARED_LIBRARY)

include $(NDK_ROOT)/external/bison/Android.mk

include $(NDK_ROOT)/external/libpcap/Android.mk


Error:-

subba@subba-laptop:~/AndroidSDKWorkSpace/NativeAdd$ /home/subba/AndroidSDK/android-ndk-r4/ndk-build -B V=1
/home/subba/AndroidSDK/android-ndk-r4/external/bison/Android.mk:82: /home/subba/AndroidSDK/android-ndk-r4/build/core/build-host-executable.mk: No such file or directory
make: *** No rule to make target `/home/subba/AndroidSDK/android-ndk-r4/build/core/build-host-executable.mk'.  Stop.
subba@subba-laptop:~/AndroidSDKWorkSpace/NativeAdd$

It's trying look build-host-executable.mk file ndk directory. Some reason ndk build directory  this file is not there. Am i doing anything wrong here? do i need to rename build-executable to build-host-executable?



To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

albert jordan

unread,
Jun 18, 2010, 3:10:34 PM6/18/10
to andro...@googlegroups.com
Added a function to get active Network interface from the libpcap. Some reason it shows socket: permission denied even in emulator. For emulator do we need any permission to getactivenetwork interface?

Sample code :-

JNIEXPORT jstring JNICALL Java_org_apache_NativeAdd_getActiveNetworkInterface
  (JNIEnv *env, jclass c)
{
          char *dev; /* name of the device to use */
          char errbuf[PCAP_ERRBUF_SIZE];
          dev = pcap_lookupdev(errbuf);
          if(dev == NULL)
          {
               LOGE("pcap_lookupdev active interface %s\n",errbuf);
          }
          return (*env)->NewStringUTF(env, pcap_lookupdev(errbuf));
}

E/libpcap ( 2626): pcap_lookupdev active interface socket: Permission denied

Is it possible to getnetworkinterface and capture network traffic using libpcap? Please suugest ..

David Turner

unread,
Jun 18, 2010, 4:24:16 PM6/18/10
to andro...@googlegroups.com
I don't think it is possible to capture network traffic without admin privileges, which normal applications do not have. Come on, this is a serious security risk.

albert jordan

unread,
Jun 18, 2010, 5:25:17 PM6/18/10
to andro...@googlegroups.com
David,
      I have two questions regarding sample project to conculde my work.

(i)  Even having root permission on device or emuator normal ndk application can't get the permission?

(ii)  my device is developement device if i add ndk appp to system/app folder does ndk appliciation get the permission?

Appreciate your help.

David Turner

unread,
Jun 18, 2010, 5:30:02 PM6/18/10
to andro...@googlegroups.com
On Fri, Jun 18, 2010 at 2:25 PM, albert jordan <core.test...@gmail.com> wrote:
David,
      I have two questions regarding sample project to conculde my work.

(i)  Even having root permission on device or emuator normal ndk application can't get the permission?

yes, an application runs under its own userid, which does not have root permissions.
 
(ii)  my device is developement device if i add ndk appp to system/app folder does ndk appliciation get the permission?

nope, this is totally unrelated.
Reply all
Reply to author
Forward
0 new messages