mdnscpp is a lightweight C++ library for browsing mDNS (Multicast DNS) services, also known as DNS-SD (DNS-based Service Discovery). It provides a unified API to discover services across platforms using one of the following backends:
- Bonjour / dns_sd (macOS, iOS)
- Avahi (Linux)
- Win32 API (Windows)
The main goal of this library is to abstract away platform-specific implementations, enabling developers to write portable mDNS client code.
- Cross-platform support
- Automatic backend selection
- Asynchronous event-driven design
- Sorted service result listing
- Simple and consistent C++ API
mdnscpp
internally abstracts the event loop to allow flexibility and seamless integration with different runtime environments. This makes the library adaptable for a variety of use cases, from simple command-line tools to full-featured GUI or server applications.
-
Default Poll-Based Loop
A minimal, platform-independent implementation usingpoll()
—intended primarily for testing and standalone use. -
libuv Integration
Full support for libuv, enabling integration with applications already using thelibuv
event loop (e.g. Node.js backends or other asynchronous systems).
The event loop system is designed with extensibility in mind. Future or user-contributed integrations could include support for other frameworks such as Boost.Asio.
This architecture ensures that mdnscpp
can be embedded cleanly into existing systems without imposing its own threading or timing model.
- C++17 or later
- Platform-specific mDNS backend:
dns_sd.h
(Bonjour) on macOS/iOSavahi-client
andavahi-common
on Linux- Native DNS-SD support on Windows
You can build mdnscpp
using CMake:
cmake -Bbuild
cmake --build build -j4
#include <iostream>
#include <mdnscpp/DefaultLoop.h>
#include <mdnscpp/Platform.h>
#include <mdnscpp/utils.h>
int main(int argc, const char **argv)
{
mdnscpp::DefaultLoop loop;
auto platform = mdnscpp::createPlatform(loop);
auto browser = platform->createBrowser("_http_", "_tcp", [](auto browser) {
auto results = mdnscpp::getSortedList(browser->getResults());
std::cout << "Results (" << results.size() << "): " << std::endl;
for (const auto &result : results)
{
std::cout << result.describe() << std::endl;
}
});
loop.run();
return 0;
}
This example sets up a service browser for services advertising _oca._tcp, prints out sorted results, and runs the event loop until interrupted.
mdnscpp::DefaultLoop
- Event loop abstractionmdnscpp::createPlatform()
- Initializes platform-specific backendPlatform::createBrowser()
- Starts browsing for a given service typeBrowser::getResults()
- Access discovered servicesmdnscpp::getSortedList()
- Helper to get sorted service listServiceResult::describe()
- Returns a human-readable description of the result
Contributions, suggestions, and bug reports are welcome! Please open an issue or submit a pull request.
For questions or feedback, feel free to reach out or open an issue on the repository.
This library is released under the terms of the MIT License.
Copyright (c) 2024-2025 Arne Gödeke