Compile libpcap using Android NDK

泪湿孤枕 提交于 2019-11-30 18:48:22

问题


I've been doing a lot of attempts to get libpcap compiled for Android, and I don't see any pattern or any progress worth writing down.

I have a very simple sniffer (that works fine in a MIPS linux) that uses libpcap, so I thought to myself oh, ok... no biggie... I'll just compile libpcap for Android (in the end, Android is just a Linux)... and here's where the problems started. I have no idea on how to compile libpcap using ndk-build and the Android.mk and all that infrastructure.

I have the Android NDK in a directory. That NDK has the toolchains built (I have a lot of directories under ~/Documents/Projects/Android_NDK/toolchains/ ) but none of the toolchains has libpcap available.

I've tried with two different libpcap version or... branches:

The Android one, which is the one I'd like to use, https://android.googlesource.com/platform/external/libpcap/

and the regular one: http://www.tcpdump.org/release/libpcap-1.5.3.tar.gz

All tries I've done have been very unsuccessful. I've seen the question Android NDK: Link using a pre-compiled static library which is similar, but I'm still getting various errors.

I have downloaded those pcap libraries to their own directories. Maybe is that the problem? Do I need to put the Android libpcap in some directory within the NDK root directory and re-create the toolchains?

I'm using NDK-r9 on a MacOSX 10.9.2 64bit.


回答1:


Finally!!

After getting annoyed by the non existing headers in and stuff like that, I found this question, that pointed to a SVN repo (http://sourceforge.net/p/prueba-android/code/HEAD/tree/trunk/jni/) with a libpcap that compiled!

If someone else wants additional details on how my Android.mk and directory structure looks like, please add a comment and I'll extend this answer.




回答2:


Please read an excellent article at http://blog.umitproject.org/2011/05/libpcap-for-android.html. There are instructions that will help you link to libpcap, but the most important takeaway is that you cannot use libpcap on non-rooted Android. So maybe it's not worth your effort.

On a rooted device, you can simply install a free sniffer like Shark for Root.




回答3:


If anyone else is having problems compiling libpcap for Android using the NDK, there is version 1.5.2 here with a built Android.mk file in it: https://android.googlesource.com/platform/external/libpcap.git and instructions for compiling this using the NDK are here: http://ducbh.blogspot.co.uk/2013/12/cross-compile-libpcap-for-android.html . I can confirm this works using the current NDK (r10b)...although you may have to add AndroidManifest.xml (blank) and and Application.mk that points to your Android.mk file.

I don't think it would be that difficult to modify the .mk file for the current libpcap version (1.6.2)



来源:https://stackoverflow.com/questions/22646344/compile-libpcap-using-android-ndk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!