Crosscompile tcpdump

From snippet wiki
Jump to navigation Jump to search

In need of a packet dumping tool on a IoT device tcpdump is your friend. On minimal installations it won't be preinstalled, so just compile it on some debian linux:

apt-get install -y gcc-arm-linux-gnueabi flex bison

wget http://www.tcpdump.org/release/libpcap-1.9.1.tar.gz
tar xzf libpcap-1.9.1.tar.gz
cd libpcap-1.9.1
CC=arm-linux-gnueabi-gcc ./configure --host=arm-none-linux-gnueabi
make

cd ..

wget http://www.tcpdump.org/release/tcpdump-4.9.3.tar.gz
tar xzf tcpdump-4.9.3.tar.gz
cd tcpdump-4.9.3
CC=arm-linux-gnueabi-gcc ./configure --host=arm-none-linux-gnueabi
make

file tcpdump
tcpdump: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=1a7963f5d5c8f1e0a00687fe33e4bd115a1d22ad, with debug_info, not stripped

arm-linux-gnueabi-strip tcpdump
file tcpdump
tcpdump: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=1a7963f5d5c8f1e0a00687fe33e4bd115a1d22ad, stripped

You don't need to run make install because the file will only be needed on some other hardware. Even the cross compiled libpcap needs no installation but is automatically found by tcpdump as a sibling folder!