Compile libpcap using Android NDK

BorrajaX picture BorrajaX · Mar 25, 2014 · Viewed 8.9k times · Source

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.

Answer

BorrajaX picture BorrajaX · Apr 5, 2014

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.