I have downloaded the libpcap in external folder from android source code using the Git and
repo. I used the toolcains of ndk (android-ndk-r5b) to compile the library following these
steps:
./configure --prefix=path-to-android-src/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin
make clean
make
make install
and then a file libpcap.a is produced.
I have make a simple sniffer using libpcap (sniffer.c). When I try to compile it, these errors occur:
agcc sniffer.c libpcap.a
sniffer.c:9:18: error: pcap.h: No such file or directory
sniffer.c:19: warning: 'struct pcap_pkthdr' declared inside parameter list
sniffer.c:19: warning: its scope is only this definition or declaration, which is probably not what you want
sniffer.c: In function 'processPacket':
sniffer.c:23: warning: incompatible implicit declaration of built-in function 'printf'
sniffer.c:24: error: dereferencing pointer to incomplete type
sniffer.c:26: error: dereferencing pointer to incomplete type
sniffer.c:33: error: dereferencing pointer to incomplete type
sniffer.c: In function 'main':
sniffer.c:45: error: 'pcap_t' undeclared (first use in this function)
sniffer.c:45: error: (Each undeclared identifier is reported only once
sniffer.c:45: error: for each function it appears in.)
sniffer.c:45: error: 'descr' undeclared (first use in this function)
sniffer.c:46: error: 'PCAP_ERRBUF_SIZE' undeclared (first use in this function)
sniffer.c:62: warning: incompatible implicit declaration of built-in function 'printf'
sniffer.c:66: warning: incompatible implicit declaration of built-in function 'fprintf'
sniffer.c:66: error: 'stderr' undeclared (first use in this function)
sniffer.c:72: warning: incompatible implicit declaration of built-in function 'fprintf'
when I try to produce the object code in advance:
agcc -c sniffer.o sniffer.c
the same errors occured.
Can someone explain me how to solve this problem?
here is the alias of agcc I use in bashrc file:
./configure --prefix=/home/petsas/projects/mobile-attacks/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/
Also, I have attached a file with the outputs of the commands above: configure, make and make install.
(I put the errors in code style because there were errors of alignment)
Thank you in advance!
-- update --
I used the options -I and -L to specify the include and library files, and these errors are gone now..
Here is my new error log:
agcc --static -I /home/petsas/projects/mobile-attacks/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/include -L /home/petsas/projects/mobile-attacks/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/lib -o sniffer sniffer.c libpcap.a
/home/petsas/projects/mobile-attacks/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: libpcap.a(pcap-linux.o): Relocations in generic ELF (EM: 3)
/home/petsas/projects/mobile-attacks/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: libpcap.a(pcap-linux.o): Relocations in generic ELF (EM: 3)
/home/petsas/projects/mobile-attacks/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: libpcap.a(pcap-linux.o): Relocations in generic ELF (EM: 3)
libpcap.a: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
any ideas?
Heading
I couldn't find the solution following the way I describe above, but I made it through
writing a Android.mdk file and by using the ndk-build of android NDK.
I put the libpcap direcotry into the android-ndk-r5b/samples, I modified a bit the Android.mdk
and the structure of the direcotry, so as to look like the other ones inside the samples dir and
I used the ndk-build command inside the android-ndk-r5b direcory:
ndk-build -C samples/android-ndk-r5b
All worked fine! I was able to produce a libpicap.so file, and put it in the phone using the
commands:
in android (phone):
$ su
# mount -o,rw remount /dev/block/mtdblock4 /system/lib
in my Desktop:
$ adb push libpcap.so /system/lib/
I made a simple sniffer, I compiled and linked with the libpcap.so and works perfectly in
my HTC Hero! ;)
Related
description
We have a C/C++ project wallet-core that is using third party library libsecp256k1, and we install libsecp256k1 into /usr/local/lib and /usr/local/include, all works well in wallet-core Unit Test, till we add it to android, which call wallet-core.
call links:
android project -> wallet-core -> trezor_crypto -> libsecp256k1
When we run tools/android-test, got error in link period:
xxxx -L/usr/local/lib trezor-crypto/libTrezorCrypto.a libprotobuf.a -llog /usr/local/lib/libsecp256k1.a -latomic -lm && :
/Users/bibodeng/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: /usr/local/lib/libsecp256k1.a: no archive symbol table (run ranlib)
../../../../../../trezor-crypto/src/ecdsa.c:1211: error: undefined reference to 'secp256k1_context_create'
../../../../../../trezor-crypto/src/ecdsa.c:1213: error: undefined reference to 'secp256k1_schnorr_sign'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Configuring for JNI
two function is undefined and there is no symbols, tell me ranlib. ranlib result:
$ranlib libsecp256k1.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: libsecp256k1.a(/0) size too large (archive member extends past the end of the file)
I run nm -g libsecp256k1.a also said it's truncated or malformed archive.
Please help me to solve this problem, we have stuck several days. Thanks a lot.
guess reason
I read many answer and guess it's reason:
linker will run ranlib before link, but it fail cause there is no
symbol ranlib failed because libsecp256k1.a
archive file is too big or maybe not in good format
libsecp256k1.a file is not
generated well or ranlib has problems.
codes & config
libsecp256k1: https://github.com/Bitcoin-ABC/secp256k1
./autogen.sh
mkdir build
cd build
../configure --enable-module-schnorr
make
make check
sudo make install
wallet-core: https://github.com/IFWallet/wallet-core/tree/free_cash
git clone git#github.com:IFWallet/wallet-core.git
git checkout free_cash
cd wallet-core
./bootstrap.sh
./tools/android-test
download the codes from github and checkout free_cash branch, run upper cmd will get the same error.
relate answers
I already try this answer, but not work.
ndk-no-archive-symbol-table
I'm trying to cross-compile ncurses using android-ndk but compilation error shows halfway the process.
Command:
CC=~/my-toolchain/bin/arm-linux-androideabi-gcc ./configure --host=arm-linux-androideabi --prefix=/Android
Output:
** Configuration summary for NCURSES 6.0 20150808:
extended funcs: yes
xterm terminfo: xterm-new
bin directory: /Android/bin
lib directory: /Android/lib
include directory: /Android/include/ncurses
man directory: /Android/share/man
terminfo directory: /Android/share/terminfo
** Include-directory is not in a standard location
Command
make
Output
../objects/tic.o:tic.c:function usage: error: undefined reference to 'stderr'
../objects/tic.o:tic.c:function put_translate: error: undefined reference to 'stdout'
../objects/tic.o:tic.c:function copy_input: error: undefined reference to 'stderr'
../objects/tic.o:tic.c:function open_input: error: undefined reference to 'stdin'
../objects/tic.o:tic.c:function open_input: error: undefined reference to 'stderr'
../objects/tic.o:tic.c:function show_databases: error: undefined reference to 'stdout'
../objects/tic.o:tic.c:function show_databases: error: undefined reference to 'stderr'
../objects/dump_entry.o:dump_entry.c:function show_entry: error: undefined reference to 'stdout'
../objects/dump_entry.o:dump_entry.c:function compare_entry: error: undefined reference to 'stdout'
../lib/libncurses.a(lib_twait.o):lib_twait.c:function _nc_timed_wait: error: undefined reference to '__FD_SET_chk'
../lib/libncurses.a(lib_twait.o):lib_twait.c:function _nc_timed_wait: error: undefined reference to '__FD_SET_chk'
../lib/libncurses.a(lib_twait.o):lib_twait.c:function _nc_timed_wait: error: undefined reference to '__FD_ISSET_chk'
../lib/libncurses.a(lib_twait.o):lib_twait.c:function _nc_timed_wait: error: undefined reference to '__FD_ISSET_chk'
collect2: error: ld returned 1 exit status
Makefile:242: recipe for target 'tic' failed
make[1]: *** [tic] Error 1
make[1]: Leaving directory '/home/jrm/softether/src/curses/ncurses-6.0/progs'
Makefile:113: recipe for target 'all' failed
make: *** [all] Error 2
I don't have any idea about the error. I tried using google but i can't seem to find similar problems like mine.
The usual reason for this error is that you've compiled against android-23 or higher but are linking against something earlier. Another variation of that issue is when you have multiple libraries built against different API levels.
It looks like you are using a standalone toolchain? If that's correct, then I'd suspect your issue is either a prebuilt library that's part of libcurses (FWIR there aren't any of those, so unlikely) or that there's something funky going on in their build scripts that causes one of the two issues I mentioned. Tons of projects add their own Android specific hacks to their build scripts that always end up being the cause of these sorts of issues, so that wouldn't surprise me at all.
Should look at both the compilation command for tic.c and the link command for whatever library/executable is failing to link there. Make sure both are using the same API levels (look for things like $NDK/platforms/android-$API_LEVEL, -D__ANDROID_API__=$API_LEVEL, and -target arm-linux-androideabi$API_LEVEL).
btw, not ncurses 6, but I do have an example showing how to use standalone toolchains that had to build ncurses 5.9: https://github.com/DanAlbert/lua-ndk/blob/master/build_lua_with_libreadline.sh#L75. Might be worth taking a look to see if that helps at all.
i am new in android ndk and i m making connection of java and c/c++ code and at last moment when i use ndk-build command then i got this error.
please help me to clear this problem.
I am working on ubuntu 12.04. and i got same error on both linux and windows and on windows i use using cygwin.
Error-
/home/saicomputer/android-ndk-r8e/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml
Compile thumb : myjni <= native.c
jni/native.c: In function 'Java_com_example_demo_MainActivity_hello':
jni/native.c:4:3: error: parameter name omitted
jni/native.c:4:3: error: parameter name omitted
jni/native.c:5:10: error: 'env' undeclared (first use in this function)
jni/native.c:5:10: note: each undeclared identifier is reported only once for each function it appears in
jni/native.c: In function 'Java_com_example_demo_MainActivity_add':
jni/native.c:9:3: error: parameter name omitted
jni/native.c:9:3: error: parameter name omitted
jni/native.c:9:3: error: parameter name omitted
jni/native.c:9:3: error: parameter name omitted
jni/native.c:10:9: error: 'value1' undeclared (first use in this function)
jni/native.c:10:18: error: 'value2' undeclared (first use in this function)
make: *** [obj/local/armeabi/objs/myjni/native.o] Error 1
please help me out to overcome this problem.
thanks.
I am trying to compile OpenSSH using the Android NDK, but failing.
My attempt consists of the following steps:
cross-compile OpenSSL for Android and install headers / libraries to /home/me/arm
grab OpenSSH 6.2p1 from here
extract the archive and run ./configure:
./configure --prefix=/home/me/arm \
--host=arm-linux-androideabi \
--with-ssl-dir=/home/me/arm
...which resulted in the following error:
getrrsetbyname.c:166:2: error: unknown type name 'HEADER'
modify the ./configure command to include:
ac_cv_search_getrrsetbyname=yes
...which fixed the one problem but still aborted with another error:
/usr/include/linux/un.h:17:8: error: redefinition of 'struct sockaddr_un'
modify the ./configure command again to include:
ac_cv_header_sys_un_h=yes
...which got me even further but still aborted with an error:
channels.c: In function 'channel_prepare_select':
channels.c:2143:2: warning: implicit declaration of function 'howmany'
[-Wimplicit-function-declaration]
channels.c:2145:45: error: 'fd_mask' undeclared (first use in this function)
Now I'm stuck. I've cracked open Android's sys/select.h and discovered that fd_mask isn't defined anywhere. I also was unable to find a ./configure option to work around this. There's also the issue with howmany() being undefined.
What changes do I need to make to get the program to compile?
Edit: I've managed to get a little bit further now. I've added the following line to ./configure to get past the "undefined fd_mask" error:
--with-cflags=-Dfd_mask=int
I then received the following error:
error: 'struct passwd' has no member named 'pw_gecos'
Android's passwd struct does not have a pw_gecos member. This one was impossible to correct without creating an actual patch for the source code. The patch is here.
I am now stuck with the following error:
dns.c: In function 'dns_result_totext':
dns.c:56:7: error: 'ERRSET_SUCCESS' undeclared (first use in this function)
dns.c:56:7: note: each undeclared identifier is reported only once for each
function it appears in
dns.c:58:7: error: 'ERRSET_NOMEMORY' undeclared (first use in this function)
...
Edit: I've made some modifications to the patch above that eliminate quite a few of the errors so far. I've also added ldns. The configure command now looks like this:
patch -p0 <openssh.patch;
autoconf;
./configure --prefix=/home/me/arm \
--host=arm-linux-androideabi \
--with-ldns=/home/me/arm \
--with-ssl-dir=/home/me/arm \
ac_cv_header_sys_un_h=yes
...and here is the new patch. The errors I get now are:
loginrec.c: In function 'construct_utmp':
loginrec.c:665:17: error: 'DEAD_PROCESS' undeclared (first use in this function)
loginrec.c:665:17: note: each undeclared identifier is reported only once for
each function it appears in
loginrec.c: At top level:
loginrec.c:727:45: warning: 'struct utmpx' declared inside parameter list
[enabled by default]
i need to install iw wireless packages on android 4.1 device. but i don't know how and what is the require version of the packages to install !!
also is it need linux platform to do this or it is enough to build and install on adb shell for android rooting device.
i see this link but when i do it from adb terminal i see that git and some shells not found ??? how to do it ?
it seems no one has any idea ??
While building iw version 3.11 (which has an Android.mk file already), I encountered some issues due to missing/ wrong headers and libraries. Since it has an Android.mk file, the NDK can be used.
In the following I will assume the following:
A device image has been built before (the kernel headers and libnl-2 static library should at least be available). I have built CyanogenMod 10 (with kernel 3.0.something) for the i9300, update the paths below to reflect that.
The NDK is installed to ~/android/system/ndk.
The NDK has appropriate platforms and toolchains installed.
Preparation after extracting iw-3.11.tar.xz and changing my directory in it:
ln -s . jni
ln -nsv ~/android/system/external ./
The next issue is the netlink library:
In file included from external/libnl-headers/netlink/genl/genl.h:15:0,
from /tmp/and/iw/jni/iw.c:17:
external/libnl-headers/netlink/netlink.h:27:29: fatal error: linux/genetlink.h: No such file or directory.
Simply creating a link to the android/system/out/target/product/i9300/obj/KERNEL_OBJ/usr/include/linux breaks other headers badly which will give errors such as:
Compile thumb : iw <= iw.c
In file included from /home/user/android/system/ndk/platforms/android-14/arch-arm/usr/include/net/if.h:28:0,
from /tmp/and/iw/jni/iw.c:10:
/tmp/and/iw/jni/linux/if.h:178:19: error: field 'ifru_addr' has incomplete type
/tmp/and/iw/jni/linux/if.h:179:19: error: field 'ifru_dstaddr' has incomplete type
/tmp/and/iw/jni/linux/if.h:180:19: error: field 'ifru_broadaddr' has incomplete type
/tmp/and/iw/jni/linux/if.h:181:19: error: field 'ifru_netmask' has incomplete type
/tmp/and/iw/jni/linux/if.h:182:20: error: field 'ifru_hwaddr' has incomplete type
In file included from external/libnl-headers/netlink/netlink.h:20:0,
from external/libnl-headers/netlink/genl/genl.h:15,
from /tmp/and/iw/jni/iw.c:17:
/home/user/android/system/ndk/platforms/android-14/arch-arm/usr/include/sys/socket.h:74:44: warning: 'struct msghdr' declared inside parameter list [enabled by default]
/home/user/android/system/ndk/platforms/android-14/arch-arm/usr/include/sys/socket.h:74:44: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
/home/user/android/system/ndk/platforms/android-14/arch-arm/usr/include/sys/socket.h:75:38: warning: 'struct msghdr' declared inside parameter list [enabled by default]
In file included from external/libnl-headers/netlink/netlink.h:25:0,
from external/libnl-headers/netlink/genl/genl.h:15,
from /tmp/and/iw/jni/iw.c:17:
/tmp/and/iw/jni/linux/netlink.h:33:2: error: unknown type name 'sa_family_t'
In file included from external/libnl-headers/netlink/genl/genl.h:15:0,
from /tmp/and/iw/jni/iw.c:17:
external/libnl-headers/netlink/netlink.h:51:16: warning: 'struct msghdr' declared inside parameter list [enabled by default]
external/libnl-headers/netlink/netlink.h:54:19: warning: 'struct iovec' declared inside parameter list [enabled by default]
make: *** [/tmp/and/iw/obj/local/armeabi/objs/iw/iw.o] Error 1
A workaround is to create the linux directory and put a symlink to ~/android/system/out/target/product/i9300/obj/KERNEL_OBJ/usr/include/linux/genetlink.h in it:
mkdir -p linux
ln -svn ~/android/system/out/target/product/i9300/obj/KERNEL_OBJ/usr/include/linux/genetlink.h linux/
Finally patch Android.mk to finish linking to the netlink library:
sed "/LOCAL_LDFLAGS/s#\$# -L$HOME/android/system/out/target/product/i9300/obj/STATIC_LIBRARIES/libnl_2_intermediates -lnl_2#" -i Android.mk
Now the build can be started:
NDK_PROJECT_PATH=$PWD ~/android/system/ndk/ndk-build TARGET_PLATFORM=android-14
It will not complete because netlink/genl/genl.h cannot be found, but the iw
binary is available in libs/armeabi!