0.assume that your toolchain is
arm-linux-gcc
arm-linux-g++
arm-linux-ar
arm-linux-ld
arm-linux-as
arm-linux-strip
...
and under your $PATH
1.download
libpcap and
tcpdump
$ wget http://www.tcpdump.org/release/libpcap-1.1.1.tar.gz
$ wget http://www.tcpdump.org/release/tcpdump-4.1.1.tar.gz
2.configure libpcap
$ CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/path/to/install
if error has occurred like this:
configure: error: pcap type not determined when cross-compiling; use --with-pcap=...
the type of packet capture could be found in configure
6914 if test ! -z "$with_pcap" ; then
6915 V_PCAP="$withval"
6916 elif test -r /dev/bpf -o -h /dev/bpf ; then
6917 #
6918 # Cloning BPF device.
6919 #
6920 V_PCAP=bpf
6921
6922 cat >>confdefs.h <<\_ACEOF
6923 #define HAVE_CLONING_BPF 1
6924 _ACEOF
6925
6926 elif test -r /dev/bpf0 ; then
6927 V_PCAP=bpf
6928 elif test -r /usr/include/net/pfilt.h ; then
6929 V_PCAP=pf
6930 elif test -r /dev/enet ; then
6931 V_PCAP=enet
6932 elif test -r /dev/nit ; then
6933 V_PCAP=snit
6934 elif test -r /usr/include/sys/net/nit.h ; then
6935 V_PCAP=nit
6936 elif test -r /usr/include/linux/socket.h ; then
6937 V_PCAP=linux
6938 elif test -r /usr/include/net/raw.h ; then
6939 V_PCAP=snoop
6940 elif test -r /usr/include/odmi.h ; then
6941 #
6942 # On AIX, the BPF devices might not yet be present - they're
6943 # created the first time libpcap runs after booting.
6944 # We check for odmi.h instead.
6945 #
6946 V_PCAP=bpf
6947 elif test -c /dev/bpf0 ; then # check again in case not readable
6948 V_PCAP=bpf
6949 elif test -r /usr/include/sys/dlpi.h ; then
6950 V_PCAP=dlpi
6951 elif test -c /dev/enet ; then # check again in case not readable
6952 V_PCAP=enet
6953 elif test -c /dev/nit ; then # check again in case not readable
6954 V_PCAP=snit
6955 else
6956 V_PCAP=null
6957 fi
configure with pcap type=null could avoid error,
$ CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/path/to/install --with-pcap=null
OR
modify configure(mark cross-compiling linux version check)
$ vim configure
6901 #if test -z "$with_pcap" && test "$cross_compiling" = yes; then
6902 # { { echo "$as_me:$LINENO: error: pcap type not determined when cross-compiling; use --with-pcap=..." >&5
6903 #echo "$as_me: error: pcap type not determined when cross-compiling; use --with-pcap=..." >&2;}
6904 # { (exit 1); exit 1; }; }
6905 #fi
...
7237 # if test $ac_cv_linux_vers = unknown ; then
7238 # { { echo "$as_me:$LINENO: error: cannot determine linux version when cross-compiling" >&5
7239 #echo "$as_me: error: cannot determine linux version when cross-compiling" >&2;}
7240 # { (exit 1); exit 1; }; }
7241 # fi
7242 # if test $ac_cv_linux_vers -lt 2 ; then
7243 # { { echo "$as_me:$LINENO: error: version 2 or higher required; see the INSTALL doc for more info" >&5
7244 #echo "$as_me: error: version 2 or higher required; see the INSTALL doc for more info" >&2;}
7245 # { (exit 1); exit 1; }; }
7246 # fi
make and install
$ sudo make && sudo make install
check
$ file /path/to/install/libpcap
/path/to/install/libpcap/lib/libpcap.so.1.1.1: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, not stripped
4.configure tcpdump
$ CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/path/to/install
if error has occurred like this:
configure: error: cannot determine linux version when cross-compiling
modify configure(mark cross-compiling linux version check)
$ vim configure
4393 # if test "$cross_compiling" = yes; then
4394 # if test "${ac_cv_linux_vers+set}" = set; then
4395 # echo $ECHO_N "(cached) $ECHO_C" >&6
4396 #else
4397 # ac_cv_linux_vers=unknown
4398 #fi
4399 #
4400 # else
4401 # if test "${ac_cv_linux_vers+set}" = set; then
4402 # echo $ECHO_N "(cached) $ECHO_C" >&6
4403 #else
4404 # ac_cv_linux_vers=`uname -r 2>&1 | \
4405 # sed -n -e '$s/.* //' -e '$s/\..*//p'`
4406 #fi
4407 #
4408 # fi
4409 # { echo "$as_me:$LINENO: result: $ac_cv_linux_vers" >&5
4410 #echo "${ECHO_T}$ac_cv_linux_vers" >&6; }
4411 # if test $ac_cv_linux_vers = unknown ; then
4412 # { { echo "$as_me:$LINENO: error: cannot determine linux version when cross-compiling" >&5
4413 #echo "$as_me: error: cannot determine linux version when cross-compiling" >&2;}
4414 # { (exit 1); exit 1; }; }
4415 # fi
make and install
$ sudo make && sudo make install
if error has occurred like this:
./addrtoname.c: In function 'ipxsap_string':
./addrtoname.c:682: error: invalid 'asm': invalid operand for code 'w'
make: *** [addrtoname.o] Error 1
modify Makefile
$ vim Makefile
-INCLS = -I. -I./../libpcap-1.1.1 -I/usr/include -I$(srcdir)/missing
-DEFS = -DHAVE_CONFIG_H -I./../libpcap-1.1.1 -I/usr/include -I$(srcdir)/missing -D_U_="__attribute__((unused))"
+INCLS = -I. -I./../libpcap-1.1.1 -I$(prefix)/include -I$(srcdir)/missing
+DEFS = -DHAVE_CONFIG_H -I./../libpcap-1.1.1 -I$(prefix)/include -I$(srcdir)/missing -D_U_="__attribute__((unused))"
make and install again
$ sudo make && sudo make install
check
$ file /path/to/install/tcpdump/sbin/tcpdump
/path/to/install/tcpdump/sbin/tcpdump: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.27, not stripped
reference:
如何將tcpdump移植到arm嵌入式系統