C++11 Multicast DNS Client
C++11 library intended to discover services and hosts on a local network using MDNS protocol.
The idea behind MDSN disco 6AB9 very is to allow client applications to find IP addresses of their server counterparts by sending a query to broadcast address (255.255.255.255). MDNS client and servers talk to each other by UDP, using packet format similar to generic DNS. The approach is widely used with Apple and IoT devices.
The mainstream implementations of MDNS are Avahi and Bonjour. While doing good job in most scenarios, they are not uniformly available, or might just be too heavy to bundle for the sake of one simple call.
This library comprises a cross-platform and very light MDNS client. It's implemented against both Posix sockets and Winsock using header-only approach.
src/zeroconf-detail.hpp -- data structures, domain logic, networking logic src/zeroconf-util.hpp -- helpers src/zeroconf.hpp -- client interface
test -- unit tests
samples/basic_demo/main.cpp -- console demo app that sends a query and displays the answers
-
Import library sources from src directory to the project
-
Include zerconf.hpp and make a call to Zeroconf::Resolve. There's only a synchronous version of the API.
#include "zeroconf.hpp"
std::vector<Zeroconf::mdns_responce> result;
bool st = Zeroconf::Resolve("_http._tcp.local", /*scanTime*/ 3, &result);
- Access the result as follows:
result[i].peer // Address of the responded machine
result[i].records // Resource records of the answer
result[i].records[j].type; // The type of the RR
result[i].records[j].pos; // The offset of the RR, starting with 0xC0
result[i].records[j].len; // Full length of the RR
result[i].records[j].name; // Name of the node to which the record belongs
- In case of failure, Zeroconf::Resolve returns false and provides diagnostic output to the client's callback:
Zeroconf::SetLogCallback([](Zeroconf::LogLevel level, const std::string& message) { ... });