Skip to content

Commit 5437988

Browse files
Merge pull request #2 from seladb/master
Build libpcap for multiple targets and API versions
2 parents 4881d3d + 43947d3 commit 5437988

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
tcpdumpbuild*/**
2+
libpcap_all_targets/**
23
venv/**

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@ Default android API: 23
3434
3535
4. Compiled binaries will be located in the corresponding `tcpdumpbuild` directory.
3636
37+
38+
## Compile libpcap for multiple targets and API versions
39+
40+
You can use the `build_libpcap_all.sh` script to run the scripts mentioned above for multiple targets and Android API versions.
41+
This can be useful if you need to buid libpcap for multiple targets / API versions.
42+
43+
1. Run the script `build_libpcap_all.sh` and set `NDK` to the location of the android sdk directory.
44+
45+
2. You can also specify the following parameters:
46+
47+
- `OUTPUT_DIR` for the output directory. The default is `libpcap_all_targets`.
48+
- `TARGETS` one or more targets from this list: `arm arm64 x86 x86_64`. The default is all of them.
49+
- `API_MIN` min API version. The default is 21.
50+
- `API_MAX` max API version. The default is 30.
51+
52+
3. Examples:
53+
```
54+
$ NDK=/home/ubuntu/workspace/android-ndk-rxxx/ ./build_libpcap_all.sh
55+
$ NDK=/home/ubuntu/workspace/android-ndk-rxxx/ OUTPUT_DIR=my_dir ./build_libpcap_all.sh
56+
$ NDK=/home/ubuntu/workspace/android-ndk-rxxx/ TARGETS="x86 x86_64" ./build_libpcap_all.sh
57+
$ NDK=/home/ubuntu/workspace/android-ndk-rxxx/ API_MIN=21 API_MAX=30 /build_libpcap_all.sh
58+
```
59+
3760
## How to use tcpdump?
3861
3962
- https://www.tcpdump.org/manpages/tcpdump.1.html

build_arm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
tcpdump_ver=4.9.2
44
libpcap_ver=1.9.0
55
android_api_def=23
6-
toolchain_arch=armv7a
6+
toolchain_arch=arm
77
toolchain_dir=toolchain_armv7a
88

99
#-------------------------------------------------------#

build_libpcap_all.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
output_dir=libpcap_all_targets
4+
android_targets="arm arm64 x86 x86_64"
5+
android_api_min=21
6+
android_api_max=30
7+
8+
if [ ${OUTPUT_DIR} ]
9+
then
10+
output_dir=${OUTPUT_DIR}
11+
fi
12+
13+
if [ ${TARGETS} ]
14+
then
15+
android_targets=${TARGETS}
16+
fi
17+
18+
if [ ${API_MIN} ]
19+
then
20+
android_api_min=${API_MIN}
21+
fi
22+
23+
if [ ${API_MAX} ]
24+
then
25+
android_api_max=${API_MAX}
26+
fi
27+
28+
echo "________________________________________"
29+
echo ""
30+
echo "Output dir : ${output_dir}"
31+
echo "Targets : ${android_targets}"
32+
echo "Android API: ${android_api_min}..${android_api_max}"
33+
echo "________________________________________"
34+
35+
read -p "Press enter to start or ctrl+c to abort"
36+
37+
rm -rf ${output_dir}
38+
39+
for android_target in ${android_targets}
40+
do
41+
for android_api in $(eval echo {${android_api_min}..${android_api_max}})
42+
do
43+
rm -rf tcpdumpbuild-${android_target}/
44+
ANDROID_API=${android_api} ./build_${android_target}.sh || continue
45+
dest_dir=${output_dir}/${android_target}/${android_api}
46+
mkdir -p ${dest_dir}
47+
cp tcpdumpbuild-${android_target}/libpcap-1.9.0/libpcap.a ${dest_dir}
48+
echo "**** DONE ${dest_dir} ****"
49+
done
50+
done

0 commit comments

Comments
 (0)