Tcpdump Source Analysis (3)--android system porting (TCPDUMP,GDB,NETSTAT)

Source: Internet
Author: User

There are two ways to compile and run tcpdump in Android, one for the source code in the Android system, the other for cross compilation on the x86 system, and then copy the compiled binaries to the Android system. The second method is used in this paper.

First compile Libpcap, download the address below, in fact, and tcpdump on the same page:

Http://www.tcpdump.org/release/libpcap-1.8.1.tar.gz

Unzip the downloaded tcpdump and Libpcap and put them in the same folder.

First go to the Libpcap folder and perform the following compile installation command

(You may need to install Flex, command: Yum install flex Bison)

#./configure--prefix=/root/androidtcpdump/tools--host=arm-linux--target=arm-linux CC=ARM-NONE-LINUX-GNUEABI-GCC --with-pcap=linux

Make && make install

Then compile the tcpdump

./configure--prefix=/root/androidtcpdump/tools--host=arm-linux--target=arm-linux CC=ARM-NONE-LINUX-GNUEABI-GCC

Make && make install

A standalone executable file is found in the ~/androidtcpdump/tools/sbin directory when the compilation is complete tcpdump

Note You need to specify the same directory when compiling both, otherwise you need to specify the path of the libpcap when compiling tcpdump

If it is dynamically compiled, the file is displayed tcpdump:no such file or directory after it is placed on the Android system. Static compilation is required, and-static parameters are added to the makefile.

Then you can grab the bag. 1.1.1.1 Compilation Netstat

About Netstat's source code and general compilation, refer to:

Netstat tool source code analysis--Network diagnosis must

Modify the Makefile file,

Modify the CC as follows:

CC = ARM-NONE-LINUX-GNUEABI-GCC

Add-static parameters, as follows

Netstat: $ (net_lib) NETSTAT.O STATISTICS.O

$ (CC)-static $ (ldflags)-O netstat netstat.o statistics.o $ (nlib) $ (reslib)

If you are missing if_strip.h and if_tc.h files, you can copy the files on the/usr/include/linux/if_strip.h path to the include in the source code, and then Lib/tr.c and lib/ The header file contained in the STRIP.C is changed to

#include <linux/if_strip.h>

#include <if_strip.h>

.....

#include <linux/if_tr.h>

#include <if_tr.h>

#make Netstat to complete the compilation. 1.1.1.2 Transplant GdB

SOURCE Download Address: https://www.gnu.org/software/gdb/download/

Or: https://ftp.gnu.org/gnu/gdb/

After the decompression, to compile

./configure--prefix=/root/androidtcpdump/tools--host=arm-linux--target=arm-none-linux-gnueabi CC= ARM-NONE-LINUX-GNUEABI-GCC As=arm-none-linux-gnueabi-as Ar=arm-none-linux-gnueabi-ar CXX=arm-none-linux-gnueabi-g + + ldflags= "-static"              then execute: Make && Make install, which produces binaries in the/root/androidtcpdump/tools/bin folder, can be copied directly to the Android system.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.