---
# System prepended metadata

title: Cross Compile TCPDUMP & LIBPCAP
tags: [Openwrt]

---


* If want to cross compile TCPDUMP, should also cross compile LIBPCAP


## Configure
* Make sure all eol of files are **lf**. Can use dos2unix tool to help.
* Make sure use chmod command so that can modify files.
* Follow the install step on github page first.(**See References**)
```
./configure CC=mipsel-openwrt-linux-gcc --host=mips-openwrt-linux-uclibc --build=x86_64-unknown-linux-gnu 
build unnecessary
```

* When compiling LIBPCAP,if error shows "neither bison nor win bison nor black nor yacc was found" then exe the following commands.
```
    sudo apt install bison -y
    sudo apt install byacc -y
```

* After ./configure success then do make.
* After make then access root first, and then do make install.
* Here make sure add CC path to root's PATH
```
sudo su
export PATH="<path/to/directory/bin/:${PATH}"
make install
```
* Then the exe file will appear in /usr/local/bin


* 還不確定如何使用 make menuconfig 將檔案包成 ipk， 不過直接將 /usr/local/bin 底下的 tcpdump 丟到 openwrt上的 /usr/bin，執行出來是有改的。



### References
[libpcap](https://github.com/the-tcpdump-group/libpcap/blob/master/INSTALL.md)
[tcpdump](https://github.com/the-tcpdump-group/tcpdump/blob/master/INSTALL.md)

## 2024.01.22
* libpcap 以及 tcpdump的跟目錄需要放在同一個目錄底下。
![image](https://hackmd.io/_uploads/ryjHVosY6.png)
* Compile步驟如下(在 libpcap已經 compile完成的情況)
    1. 執行下面這行```./configure CC=mipsel-openwrt-linux-gcc --host=mips-openwrt-linux-uclibc --build=x86_64-unknown-linux-gnu```
    2. 直接執行 make，並且確認是否有任何 error。
    3. sudo su
    4. 將 cross compiler加入系統路徑。```export PATH="/home/monk/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl/bin/:${PATH}"```
    5. 至 /usr/local/bin 底下會看到 tcpdump exe file，將其 scp 至 openwrt /usr/bin。
