21. Use tcpdump to capture packets on the device side

One:
Download libpcap-1.8.1.tar.gz and tcpdump-4.9.0.tar.gz tools:

Two: compile libpcap:
1. Unzip and modify:
root# tar -zxvf libpcap-1.8.1.tar.gz
root# cd libpcap-1.8.1/
root# vi configure +5435

#注释8行代码:
5435 #add by lt 20170319
5436 #if test -z "$with_pcap" && test "$cross_compiling" = yes; then
5437 #       as_fn_error $? "pcap type not determined when cross-compiling; use --with-pcap=..." "$LINENO" 5
5438 #fi
5439 
5440 # Check whether --with-pcap was given.
5441 #if test "${with_pcap+set}" = set; then :
5442 # withval=$with_pcap;
5443 #fi

2. Configure and compile:

root@user126:/opt/libpcap-1.8.1/# ./configure --prefix=/opt/libpcap/pub --host=arm-himix400-linux --target=arm-himix400-linux CC=arm-himix400-linux-gcc 
make
make install 

Three: compile tcpdump:

root# tar -zxvf tcpdump-4.9.0.tar.gz 

root@user126:/opt/tcpdump-4.9.0# ./configure --prefix=/opt/tcpdump/dump --host=arm-himix400-linux CC=arm-himix400-linux-gcc
make
make install 

Four: Use reference:
Note that you need to wait for the network port to be configured before grabbing data, especially the 4G network port, because when the network port restarts, the packet capture will stop.

1. Grab the data of eth0 network port:

./tcpdump  -i eth0 -s 0 -w /var/aaa.pcap

2. Grab the 23 port data of eth0 network port:

./tcpdump tcp port 23 -i eth0 -s 0 -w /var/bbb.pcap

3. Grab the data of 4G network port:

./tcpdump  -i usb0 -s 0 -w /var/ccc.pcap

Guess you like

Origin blog.csdn.net/yanghangwww/article/details/111772434
Recommended