Library that converts DNS transmission to C-DNS, the compacted DNS Packet Capture format.
This project has the following dependencies:
- [CMake >= 3.5] (https://cmake.org/)
- [Boost] (https://www.boost.org/)
- [zlib] (https://www.zlib.net/)
- [XZ Utils] (https://tukaani.org/xz/)
Optional:
- [GoogleTest] (https://github.com/google/googletest)
- [pybind11] (https://github.com/pybind/pybind11)
Basic build instructions using CMake.
mkdir build
cd build
cmake -DBUILD_PYTHON_BINDINGS=ON -DBUILD_TESTS=ON ..
make
make install
If you don't want to build the Python bindings, you can omit -DBUILD_PYTHON_BINDINGS
option.
If you don't want to build the test suite with the library, you can omit -DBUILD_TESTS
option.
You can disable building of CLI tools with -DBUILD_CLI_TOOLS=OFF
option.
To generate Doxygen documentation run make doc
. Doxygen documentation for current release can be found here.
Packages for Debian 12, 11, 10, 9; Ubuntu 24.04, 22.04, 20.04, 18.04, 16.04; Fedora 42 - 36, Rawhide; EPEL 8 and Arch are available from OBS (openSUSE Build Service).
Python bindings are, for the moment, available only when building the library from sources.
sudo apt-get update
sudo apt-get install -y lsb-release curl gpg
DISTRO=$(lsb_release -i -s)
RELEASE=$(lsb_release -r -s)
if [[ $DISTRO == "Ubuntu" ]]; then DISTRO="xUbuntu"; fi
if [[ $DISTRO == "Debian" && "$RELEASE" =~ ^9\..*$ ]]; then RELEASE="9.0"; fi
echo "deb http://download.opensuse.org/repositories/home:/CZ-NIC:/dns-probe/${DISTRO}_${RELEASE}/ /" | sudo tee /etc/apt/sources.list.d/dns-probe.list
curl -fsSL https://download.opensuse.org/repositories/home:CZ-NIC:/dns-probe/${DISTRO}_${RELEASE}/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/dns-probe.gpg > /dev/null
sudo apt-get update
sudo apt-get install libcdns1 libcdns-dev
sudo dnf config-manager --add-repo https://download.opensuse.org/repositories/home:/CZ-NIC:/dns-probe/Fedora_$(cut -d: -f5 /etc/system-release-cpe | cut -d. -f1)/home:CZ-NIC:dns-probe.repo
sudo dnf install libcdns libcdns-devel
sudo dnf config-manager --add-repo https://download.opensuse.org/repositories/home:/CZ-NIC:/dns-probe/Fedora_Rawhide/home:CZ-NIC:dns-probe.repo
sudo dnf install libcdns libcdns-devel
cd /etc/yum.repos.d/
sudo wget https://download.opensuse.org/repositories/home:/CZ-NIC:/dns-probe/Fedora_EPEL_8_CentOS/home:CZ-NIC:dns-probe.repo
sudo yum install libcdns libcdns-devel
echo "[home_CZ-NIC_dns-probe_Arch]" | sudo tee -a /etc/pacman.conf
echo "Server = https://download.opensuse.org/repositories/home:/CZ-NIC:/dns-probe/Arch/$(uname -m)" | sudo tee -a /etc/pacman.conf
key=$(curl -fsSL https://download.opensuse.org/repositories/home:/CZ-NIC:/dns-probe/Arch/$(uname -m)/home_CZ-NIC_dns-probe_Arch.key)
fingerprint=$(gpg --quiet --with-colons --import-options show-only --import --fingerprint <<< "${key}" | awk -F: '$1 == "fpr" { print $10 }')
sudo pacman-key --init
sudo pacman-key --add - <<< "${key}"
sudo pacman-key --lsign-key "${fingerprint}"
sudo pacman -Sy home_CZ-NIC_dns-probe_Arch/c-dns
To use the C-DNS library you only have to include the <cdns/cdns.h>
header file.
#include <cdns/cdns.h>
...
// Create C-DNS file
CDNS::FilePreamble fp;
CDNS::CdnsExporter* exporter = new CDNS::CdnsExporter(fp, "output.out", CDNS::CborOutputCompression::NO_COMPRESSION);
CDNS::GenericQueryResponse qr;
qr.client_port = 1234;
exporter->buffer_qr(qr);
exporter->write_block();
delete exporter;
// Read C-DNS file
std::ifstream ifs("output.out", std::ifstream::binary);
CDNS::CdnsReader* reader = new CDNS::CdnsReader(ifs);
bool end = false;
while (true) {
CDNS::CdnsBlockRead block = reader->read_block(end);
if (end)
break;
while (true) {
CDNS::GenericQueryResponse gqr = block.read_generic_qr(end);
if (end)
break;
...
}
}
delete reader;
The C-DNS library comes with a set of CLI tools for easy inspection and merging of C-DNS files.
cdns-blocks - Prints summary information about individual Blocks in C-DNS file.
cdns-itemcount - Prints the counts of Query/Response, Address Event Count and Malformed Message items in a C-DNS file.
cdns-items - Prints full contents of individual Query/Response, Address Event Count and Malformed Message items in a C-DNS file.
cdns-merge - Merges multiple C-DNS files into one. Can only merge files with compatible major.minor.private version.
cdns-preamble - Prints human readable contents of C-DNS file preamble.