-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathquery.cpp
More file actions
49 lines (37 loc) · 934 Bytes
/
query.cpp
File metadata and controls
49 lines (37 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <thread>
#ifdef _WIN32
#include <winsock2.h>
#endif
#include "mdns_cpp/logger.hpp"
#include "mdns_cpp/mdns.hpp"
void onInterruptHandler(int s) {
std::cout << "Caught signal: " << s << std::endl;
exit(0);
}
int main() {
signal(SIGINT, onInterruptHandler);
#ifdef _WIN32
WSADATA wsaData;
// Initialize Winsock
const int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
std::cout << "WSAStartup failed: " << iResult << "\n";
return 1;
}
#endif
mdns_cpp::Logger::setLoggerSink([](const std::string& log_msg) {
std::cout << "MDNS_LIBRARY: " << log_msg;
std::flush(std::cout);
});
mdns_cpp::mDNS mdns;
const std::string service = "_http._tcp.local.";
mdns.executeQuery({{service, 0}});
while (true) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
return 0;
}