Android NDK:尝试移植 JnetPcap

发布于 2024-11-06 05:43:53 字数 5387 浏览 6 评论 0原文

我发现了一个Android流量监控应用程序,Shark,它基于JnetPcap,有一个包含所有源文件和相应的 Android.mk 文件。

我将 jni 目录放入 Android-NDK 的示例文件中,并尝试使用 ndk-build -C 来构建它。编译过程中会出现一些错误。这是我获取的错误日志:

make: Entering directory `/home/thanasis/android-ndk-r5b/samples    /jnetpcap_pure/jni'
Compile thumb  : jnetpcap <= util_crc16.c
Compile thumb  : jnetpcap <= util_crc32.c
Compile++ thumb  : jnetpcap <= jnetpcap.cpp
Compile++ thumb  : jnetpcap <= packet_flow.cpp
Compile++ thumb  : jnetpcap <= packet_jheader.cpp
Compile++ thumb  : jnetpcap <= jnetpcap_pcap_header.cpp
Compile++ thumb  : jnetpcap <= nio_jbuffer.cpp
Compile++ thumb  : jnetpcap <= winpcap_stat_ex.cpp
Compile++ thumb  : jnetpcap <= winpcap_send_queue.cpp
Compile++ thumb  : jnetpcap <= winpcap_ext.cpp
Compile++ thumb  : jnetpcap <= jnetpcap_ids.cpp
Compile++ thumb  : jnetpcap <= jnetpcap_dumper.cpp
Compile++ thumb  : jnetpcap <= jnetpcap_utils.cpp
Compile++ thumb  : jnetpcap <= util_in_cksum.cpp
Compile++ thumb  : jnetpcap <= jnetpcap_beta.cpp
Compile++ thumb  : jnetpcap <= nio_jmemory.cpp
Compile++ thumb  : jnetpcap <= packet_jsmall_scanner.cpp
Compile++ thumb  : jnetpcap <= packet_protocol.cpp
Compile++ thumb  : jnetpcap <= nio_jnumber.cpp
Compile++ thumb  : jnetpcap <= packet_jheader_scanner.cpp
Compile++ thumb  : jnetpcap <= packet_jscan.cpp
Compile++ thumb  : jnetpcap <= util_checksum.cpp
Compile++ thumb  : jnetpcap <= packet_jpacket.cpp
Compile++ thumb  : jnetpcap <= winpcap_ids.cpp
Compile++ thumb  : jnetpcap <= util_debug.cpp
Compile++ thumb  : jnetpcap <= jnetpcap_bpf.cpp
Compile thumb  : pcap <= bpf_dump.c
Compile thumb  : pcap <= bpf_filter.c
Compile thumb  : pcap <= bpf_image.c
Compile thumb  : pcap <= etherent.c
Compile thumb  : pcap <= fad-gifc.c
Compile thumb  : pcap <= gencode.c
yacc  /home/thanasis/android-ndk-r5b/samples/jnetpcap_pure    /jni/libpcap/grammar.y
mv -f y.tab.c /home/thanasis/android-ndk-r5b/samples/jnetpcap_pure    /jni/libpcap/grammar.c
Compile thumb  : pcap <= grammar.c
Compile thumb  : pcap <= inet.c
Compile thumb  : pcap <= nametoaddr.c
Compile thumb  : pcap <= optimize.c
Compile thumb  : pcap <= pcap.c
Compile thumb  : pcap <= pcap-linux.c
Compile thumb  : pcap <= savefile.c
Compile thumb  : pcap <= scanner.c
Compile thumb  : pcap <= version.c
StaticLibrary  : libpcap.a
StaticLibrary  : libstdc++.a
SharedLibrary  : libjnetpcap.so
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/obj/local    /armeabi/libpcap.a(gencode.o): In function `pcap_compile':
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/jni/libpcap    /gencode.c:389: undefined reference to `pcap_parse'
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/obj/local    /armeabi/libpcap.a(grammar.o): In function `yyparse':
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure    /jni/y.tab.c:1941: undefined reference to `yylex'
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/obj/local    /armeabi/libpcap.a(scanner.o): In function `pcap_lex':
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure    /jni/scanner.l:342: undefined reference to `pcap_lval'
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/obj/local    /armeabi/libpcap.a(scanner.o): In function `pcap_lex':
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure    /jni/<stdout>:3554: undefined reference to `pcap_lval'
collect2: ld returned 1 exit status
make: *** [/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure    /obj/local/armeabi/libjnetpcap.so] Error 1
make: Leaving directory `/home/thanasis/android-ndk-r5b    /samples    /jnetpcap_pure/jni'

这是 Android.mk 文件:

/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/jni/Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := jnetpcap

LOCAL_SRC_FILES :=\
jnetpcap.cpp\
packet_flow.cpp\
packet_jheader.cpp\
jnetpcap_pcap_header.cpp\
nio_jbuffer.cpp\
winpcap_stat_ex.cpp\
winpcap_send_queue.cpp\
winpcap_ext.cpp\
jnetpcap_ids.cpp\
jnetpcap_dumper.cpp\
jnetpcap_utils.cpp\
util_in_cksum.cpp\
jnetpcap_beta.cpp\
nio_jmemory.cpp\
packet_jsmall_scanner.cpp\
packet_protocol.cpp\
nio_jnumber.cpp\
packet_jheader_scanner.cpp\
packet_jscan.cpp\
util_checksum.cpp\
packet_jpacket.cpp\
winpcap_ids.cpp\
util_debug.cpp\
util_crc16.c\
util_crc32.c\
jnetpcap_bpf.cpp

LOCAL_C_INCLUDES :=\
$(NDK_ROOT)/platforms/android-8/arch-arm/usr/include\
$(LOCAL_PATH)/libpcap

LOCAL_CFLAGS := -DLIBPCAP_VERSION=0x097

LOCAL_STATIC_LIBRARIES := libpcap

include $(BUILD_SHARED_LIBRARY)

include $(LOCAL_PATH)/libpcap/Android.mk

/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/jni/libpcap/Android.mk:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:=\
bpf_dump.c\
bpf/net/bpf_filter.c\
bpf_image.c\
etherent.c\
fad-gifc.c\
gencode.c\
grammar.c\
inet.c\
nametoaddr.c\
optimize.c\
pcap.c\
pcap-linux.c\
savefile.c\
scanner.c\
version.c

LOCAL_CFLAGS:=-O2 -g
LOCAL_CFLAGS+=-DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -Dlinux -D__GLIBC__ -D_GNU_SOURCE

LOCAL_MODULE:= libpcap

include $(BUILD_STATIC_LIBRARY)

我该如何修复这个问题?

I found a traffic monitoring application for Android, Shark, which is based on JnetPcap and has a file with all the source files and the appropriate Android.mk files.

I put the jni directory in the samples file of the Android-NDK and I tried to build it using ndk-build -C. During the compilation some errors occur. Here is the error log I take:

make: Entering directory `/home/thanasis/android-ndk-r5b/samples    /jnetpcap_pure/jni'
Compile thumb  : jnetpcap <= util_crc16.c
Compile thumb  : jnetpcap <= util_crc32.c
Compile++ thumb  : jnetpcap <= jnetpcap.cpp
Compile++ thumb  : jnetpcap <= packet_flow.cpp
Compile++ thumb  : jnetpcap <= packet_jheader.cpp
Compile++ thumb  : jnetpcap <= jnetpcap_pcap_header.cpp
Compile++ thumb  : jnetpcap <= nio_jbuffer.cpp
Compile++ thumb  : jnetpcap <= winpcap_stat_ex.cpp
Compile++ thumb  : jnetpcap <= winpcap_send_queue.cpp
Compile++ thumb  : jnetpcap <= winpcap_ext.cpp
Compile++ thumb  : jnetpcap <= jnetpcap_ids.cpp
Compile++ thumb  : jnetpcap <= jnetpcap_dumper.cpp
Compile++ thumb  : jnetpcap <= jnetpcap_utils.cpp
Compile++ thumb  : jnetpcap <= util_in_cksum.cpp
Compile++ thumb  : jnetpcap <= jnetpcap_beta.cpp
Compile++ thumb  : jnetpcap <= nio_jmemory.cpp
Compile++ thumb  : jnetpcap <= packet_jsmall_scanner.cpp
Compile++ thumb  : jnetpcap <= packet_protocol.cpp
Compile++ thumb  : jnetpcap <= nio_jnumber.cpp
Compile++ thumb  : jnetpcap <= packet_jheader_scanner.cpp
Compile++ thumb  : jnetpcap <= packet_jscan.cpp
Compile++ thumb  : jnetpcap <= util_checksum.cpp
Compile++ thumb  : jnetpcap <= packet_jpacket.cpp
Compile++ thumb  : jnetpcap <= winpcap_ids.cpp
Compile++ thumb  : jnetpcap <= util_debug.cpp
Compile++ thumb  : jnetpcap <= jnetpcap_bpf.cpp
Compile thumb  : pcap <= bpf_dump.c
Compile thumb  : pcap <= bpf_filter.c
Compile thumb  : pcap <= bpf_image.c
Compile thumb  : pcap <= etherent.c
Compile thumb  : pcap <= fad-gifc.c
Compile thumb  : pcap <= gencode.c
yacc  /home/thanasis/android-ndk-r5b/samples/jnetpcap_pure    /jni/libpcap/grammar.y
mv -f y.tab.c /home/thanasis/android-ndk-r5b/samples/jnetpcap_pure    /jni/libpcap/grammar.c
Compile thumb  : pcap <= grammar.c
Compile thumb  : pcap <= inet.c
Compile thumb  : pcap <= nametoaddr.c
Compile thumb  : pcap <= optimize.c
Compile thumb  : pcap <= pcap.c
Compile thumb  : pcap <= pcap-linux.c
Compile thumb  : pcap <= savefile.c
Compile thumb  : pcap <= scanner.c
Compile thumb  : pcap <= version.c
StaticLibrary  : libpcap.a
StaticLibrary  : libstdc++.a
SharedLibrary  : libjnetpcap.so
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/obj/local    /armeabi/libpcap.a(gencode.o): In function `pcap_compile':
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/jni/libpcap    /gencode.c:389: undefined reference to `pcap_parse'
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/obj/local    /armeabi/libpcap.a(grammar.o): In function `yyparse':
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure    /jni/y.tab.c:1941: undefined reference to `yylex'
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/obj/local    /armeabi/libpcap.a(scanner.o): In function `pcap_lex':
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure    /jni/scanner.l:342: undefined reference to `pcap_lval'
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/obj/local    /armeabi/libpcap.a(scanner.o): In function `pcap_lex':
/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure    /jni/<stdout>:3554: undefined reference to `pcap_lval'
collect2: ld returned 1 exit status
make: *** [/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure    /obj/local/armeabi/libjnetpcap.so] Error 1
make: Leaving directory `/home/thanasis/android-ndk-r5b    /samples    /jnetpcap_pure/jni'

Here are the Android.mk files:

/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/jni/Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := jnetpcap

LOCAL_SRC_FILES :=\
jnetpcap.cpp\
packet_flow.cpp\
packet_jheader.cpp\
jnetpcap_pcap_header.cpp\
nio_jbuffer.cpp\
winpcap_stat_ex.cpp\
winpcap_send_queue.cpp\
winpcap_ext.cpp\
jnetpcap_ids.cpp\
jnetpcap_dumper.cpp\
jnetpcap_utils.cpp\
util_in_cksum.cpp\
jnetpcap_beta.cpp\
nio_jmemory.cpp\
packet_jsmall_scanner.cpp\
packet_protocol.cpp\
nio_jnumber.cpp\
packet_jheader_scanner.cpp\
packet_jscan.cpp\
util_checksum.cpp\
packet_jpacket.cpp\
winpcap_ids.cpp\
util_debug.cpp\
util_crc16.c\
util_crc32.c\
jnetpcap_bpf.cpp

LOCAL_C_INCLUDES :=\
$(NDK_ROOT)/platforms/android-8/arch-arm/usr/include\
$(LOCAL_PATH)/libpcap

LOCAL_CFLAGS := -DLIBPCAP_VERSION=0x097

LOCAL_STATIC_LIBRARIES := libpcap

include $(BUILD_SHARED_LIBRARY)

include $(LOCAL_PATH)/libpcap/Android.mk

/home/thanasis/android-ndk-r5b/samples/jnetpcap_pure/jni/libpcap/Android.mk:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:=\
bpf_dump.c\
bpf/net/bpf_filter.c\
bpf_image.c\
etherent.c\
fad-gifc.c\
gencode.c\
grammar.c\
inet.c\
nametoaddr.c\
optimize.c\
pcap.c\
pcap-linux.c\
savefile.c\
scanner.c\
version.c

LOCAL_CFLAGS:=-O2 -g
LOCAL_CFLAGS+=-DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -Dlinux -D__GLIBC__ -D_GNU_SOURCE

LOCAL_MODULE:= libpcap

include $(BUILD_STATIC_LIBRARY)

How can I fix this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文