Forward UDP packets captured by libpcap.
This command-line tool leverages the functionality of libpcap to facilitate the forwarding of filtered UDP packets without affecting the original UDP data flow.
The third-party source code argparse.hpp
is involved for the advantage of parsing arguments.
For performance, a simple pre-allocated ring-buffer is used in the program to avoid continually malloc and free memory.
make
Then udpfwd
is built. See Makefile
for details.
See the help message with the -h
option:
$ ./udpfwd -h
Terminal-1:
# Send UDP packets from 9000 to 9001.
$ ./test/test.py
Terminal-2:
# Forward UDP packets (filtered by dst port 9001) to 9002.
$ ./test/udpfwd.sh
Terminal-3:
# Listen to UDP port 9002 and print the content onto stdout.
$ ./test/nc.sh
Terminal-4 (optional):
# Use tcpdump to capture the UDP packets going to port 9002.
$ ./test/tcpdump.sh
# On Ubuntu
sudo apt install libpcap-dev
# On macOS
brew install libpcap
clang++
is the default C++ compiler on macOS.- On Ubuntu, install clang++ with the following cmdline.
sudo apt install llvm clang
The argparse.hpp
file under the top directory is simply copied from p-ranav/argparse, which is a good C++ argument parser.