Skip to content

maxDcb/libDnsCommunication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libDnsCommunication

libDnsCommunication is a C++ library enabling DNS-based message tunneling.
It encodes arbitrary data into DNS TXT records so a client and server can exchange messages over standard DNS infrastructure.

Features

  • UDP DNS client and server implementation.
  • Message fragmentation and reassembly using JSON and hex encoding.
  • TXT, CNAME, MX, A and AAAA records handled consistently for both encoding and decoding.
  • Random subdomain generation and utility helpers.
  • Cross-platform support for Linux and Windows.

Building

# linux
mkdir build && cd build
cmake ..
make

#windows
mkdir build && cd build
cmake ..
msbuild Dnscommunication.sln

Running Examples

Functional Test

A dedicated binary fonctionalTest is provided to validate client/server communication.

Usage

Server mode

./fonctionalTest server --domain ns.example.com [--port 53] [--test-msg "text"] [--run-seconds 5]

Client mode

./fonctionalTest client --dns <resolver_ip> --host ns.example.com --send "text" [--timeout 5] [--expect "expected-reply"]

Local Testing

You can test locally without a real DNS server:

  1. Pick a fake domain (e.g., test.dnstestdomain).

  2. Add it to /etc/hosts pointing to 127.0.0.1:

    127.0.0.1   test.dnstestdomain
    
  3. Run the server:

    ./fonctionalTest server --domain test.dnstestdomain --port 5353 --run-seconds 60 --test-msg "hello"
  4. Run the client, pointing to localhost (127.0.0.1):

    ./fonctionalTest client --dns 127.0.0.1 --host test.dnstestdomain --send "hello" --expect "hello" --port 5353

If the message is received correctly, the client will print EXPECTATION OK and exit with code 0.

This setup is useful for CI pipelines or quick validation without relying on external resolvers.

Querying a public resolver

The repository also provides a tiny helper that sends a raw DNS query to any resolver and decodes the answer with the library:

cmake --build build --target publicDnsClient
./publicDnsClient 8.8.8.8 example.com TXT

Any RR type supported by the library can be supplied as the optional third argument (for example CNAME, MX, AAAA, …). The tool prints the textual view of the first answer as well as the raw hexadecimal payload, which makes it easy to verify interoperability with public DNS services.


Unit Testing

Unit tests are provided in the tests directory. After building, run:

./utilsTest

License

MIT

About

Simple Client & Server for Dns Communication

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors