본문 바로가기
Research/Network

tcpdump sh4 cross-compile

by sunnyan 2009. 5. 22.
728x90

먼저 libpcap 라이브러리를 사용하므로 libpcap-1.0.0 을 다운로드해서 컴파일한다.

configure를 아래와 같이 수정해 주어야 한다.

linux)
    { echo "$as_me:$LINENO: checking Linux kernel version" >&5
echo $ECHO_N "checking Linux kernel version... $ECHO_C" >&6; }
    if test "$cross_compiling" = yes; then
        if test "${ac_cv_linux_vers+set}" = set; then
  echo $ECHO_N "(cached) $ECHO_C" >&6
else
  #ac_cv_linux_vers=unknown
  ac_cv_linux_vers=2
fi

위와 같이 수정하지 않으면 아래와 같은 에러가 발생하면서 configure가 중지됨.

checking whether ether_hostton is declared... yes
checking if --disable-protochain option is specified... enabled
checking packet capture type... linux
checking Linux kernel version... unknown
configure: error: cannot determine linux version when cross-compiling

위와 같이 수정한 후, 아래와 같이 configure를 실행하고 make 하면 libpcap.a 가 생성되며,
공유라이브러리는 생성되지 않음.

CC=sh4-weldk-linux-gcc ./configure --target=sh4 --host=i686-pc-linux-gnu --with-pcap=linux

===============================================================================================

다음으로 tcpdump를 다운로드 받아서 libpcap 처럼 configure를 수정한다.

CC=sh4-weldk-linux-gcc ./configure --target=sh4 --host=i686-pc-linux-gnu --disable-ipv6

위와 같이 configure를 실행한 후에, make를 실행하면 아래와 같은 컴파일 에러가 발생한다.

[root@localhost tcpdump-4.0.0]# make
sh4-weldk-linux-gcc -O2 -DHAVE_CONFIG_H  -I./../libpcap-1.0.0  -I/usr/include -I./missing  -D_U_="__attribute__((unused))" -I. -I./../libpcap-1.0.0  -I/usr/include -I./missing -c ./addrtoname.c
/tmp/cccsSz4g.s: Assembler messages:
/tmp/cccsSz4g.s:407: Error: unknown opcode
/tmp/cccsSz4g.s:514: Error: unknown opcode
/tmp/cccsSz4g.s:587: Error: unknown opcode
/tmp/cccsSz4g.s:587: Error: unknown opcode
/tmp/cccsSz4g.s:587: Error: unknown opcode
/tmp/cccsSz4g.s:2132: Error: unknown opcode
/tmp/cccsSz4g.s:2271: Error: unknown opcode
/tmp/cccsSz4g.s:2293: Error: unknown opcode
/tmp/cccsSz4g.s:2327: Error: unknown opcode
/tmp/cccsSz4g.s:2660: Error: unknown opcode
/tmp/cccsSz4g.s:2681: Error: unknown opcode
make: *** [addrtoname.o] Error 1
[root@localhost tcpdump-4.0.0]#

위의 에러를 없애기 위해서 Makefile을 수정해야 하는데, -O2 옵션을 빼주면 된다.

#
# You shouldn't need to edit anything below here.
#

CC = sh4-weldk-linux-gcc
PROG = tcpdump
# CCOPT = -O2 <-- 수정된 부분
INCLS = -I. -I./../libpcap-1.0.0  -I/usr/include -I$(srcdir)/missing
DEFS = -DHAVE_CONFIG_H  -I./../libpcap-1.0.0  -I/usr/include -I$(srcdir)/missing  -D_U_="__attribute__((unused))"

수정한 후에 컴파일을 하면 아래와 같은 에러가 발생한다.

sh4-weldk-linux-gcc  -DHAVE_CONFIG_H  -I./../libpcap-1.0.0  -I/usr/include -I./missing  -D_U_="__attribute__((unused))" -I. -I./../libpcap-1.0.0  -I/usr/include -I./missing -c ./print-esp.c
./print-esp.c:75: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘*’ token
./print-esp.c: In function ‘esp_print_decode_onesecret’:
./print-esp.c:225: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
./print-esp.c:225: error: ‘evp’ undeclared (first use in this function)
./print-esp.c:225: error: (Each undeclared identifier is reported only once
./print-esp.c:225: error: for each function it appears in.)
./print-esp.c:255: error: ‘struct sa_list’ has no member named ‘evp’
./print-esp.c:256: error: ‘struct sa_list’ has no member named ‘authlen’
./print-esp.c:257: error: ‘struct sa_list’ has no member named ‘ivlen’
./print-esp.c:261: error: ‘struct sa_list’ has no member named ‘evp’
./print-esp.c:262: error: ‘struct sa_list’ has no member named ‘authlen’
./print-esp.c:263: error: ‘struct sa_list’ has no member named ‘ivlen’
./print-esp.c:283: error: ‘struct sa_list’ has no member named ‘secret’
./print-esp.c:284: error: ‘struct sa_list’ has no member named ‘secretlen’
./print-esp.c:288: error: ‘struct sa_list’ has no member named ‘secret’
./print-esp.c:289: error: ‘struct sa_list’ has no member named ‘secret’
./print-esp.c:290: error: ‘struct sa_list’ has no member named ‘secretlen’
./print-esp.c:292: error: ‘struct sa_list’ has no member named ‘secret’
./print-esp.c:292: error: ‘struct sa_list’ has no member named ‘secret’
./print-esp.c:293: error: ‘struct sa_list’ has no member named ‘secretlen’
./print-esp.c:293: error: ‘struct sa_list’ has no member named ‘secret’
./print-esp.c: In function ‘esp_init’:
./print-esp.c:323: error: ‘SN_des_ede3_cbc’ undeclared (first use in this function)
./print-esp.c: In function ‘esp_print’:
./print-esp.c:360: error: ‘EVP_CIPHER_CTX’ undeclared (first use in this function)
./print-esp.c:360: error: expected ‘;’ before ‘ctx’
./print-esp.c:469: error: ‘struct sa_list’ has no member named ‘ivlen’
./print-esp.c:470: error: ‘struct sa_list’ has no member named ‘secret’
./print-esp.c:471: error: ‘struct sa_list’ has no member named ‘secretlen’
./print-esp.c:472: error: ‘struct sa_list’ has no member named ‘authlen’
./print-esp.c:474: error: ‘struct sa_list’ has no member named ‘evp’
./print-esp.c:475: error: ‘ctx’ undeclared (first use in this function)
./print-esp.c:476: error: ‘struct sa_list’ has no member named ‘evp’
make: *** [print-esp.o] Error 1

위의 에러를 Skip 하기 위해 config.h에서 HAVE_LIBCRYPT를 comment out 한다. 0으로 설정하면 안됨.

/* Define to 1 if you have the `crypto' library (-lcrypto). */
//#define HAVE_LIBCRYPTO 1

또한 소스를 수정해야 한다.  print-enc.c에 ip6_print를 사용하는 부분이 있는데, #ifdef INET6로 감싸줘야 한다.

81라인
#ifdef INET6
  ip6_print(p, length);
#endif  

728x90

'Research > Network' 카테고리의 다른 글

Boost socket performance on Linux  (0) 2011.10.25
How to enable IP Forwarding in Linux  (0) 2009.10.13
tcp packet을 받을때 커널의 흐름  (0) 2008.11.26
Network performance test  (0) 2005.09.20
TCP/IP 동영상  (0) 2002.12.04