Skip to content

Instantly share code, notes, and snippets.

@Sharp0802
Last active April 18, 2024 09:42
Show Gist options
  • Save Sharp0802/6a776e93ebd324d139b9e41ef8a6753f to your computer and use it in GitHub Desktop.
Save Sharp0802/6a776e93ebd324d139b9e41ef8a6753f to your computer and use it in GitHub Desktop.

Clone libpcap repository and Create build directory.

$ cd path/to/libpcap/source
$ mkdir build
$ cd build

Then, Write Android.cmake, CMake toolchain file for Android.

See also: Cross-compiling for Android

$ cat Android.cmake
set(CMAKE_ANDROID_NDK       "/path/to/ndk")

set(CMAKE_SYSTEM_NAME       "Android")
set(CMAKE_SYSTEM_VERSION    24)
set(CMAKE_ANDROID_ARCH_ABI  "armeabi-v7a")
set(CMAKE_ANDROID_STL_TYPE  "c++_static")
set(CMAKE_ANDROID_TOOLCHAIN "clang")

Prepare to compile without unnecessary interfaces.

$ cmake                                      \
  -DDISABLE_DBUS=True                        \
  -DDISABLE_RDMA=True                        \
  -DDISABLE_DAG=True                         \
  -DDISABLE_SEPTEL=True                      \
  -DDISABLE_SNF=True                         \
  -DDISABLE_AIRPCAP=True                     \
  -DDISABLE_TC=True                          \
  -DCMAKE_GENERATOR=Ninja                    \
  -DCMAKE_C_FLAGS="-O3"                      \
  -DCMAKE_BUILD_TYPE=Release                 \
  -DCMAKE_TOOLCHAIN_FILE=../../Android.cmake \
  ..

Let's compile!

$ ninja
@Sharp0802
Copy link
Author

If you enabled DPDK support, DPDK version v21.10 or below is required to build.

See: the-tcpdump-group/libpcap#1159

@Sharp0802
Copy link
Author

Android API version should be equal or greater than 24, so system can use fseeko.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment