-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub.cc
52 lines (44 loc) · 1.57 KB
/
sub.cc
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
50
51
52
#include "mdnssub.h"
#include <stdio.h>
#include <unistd.h>
#include <string>
#include <thread>
void callback(std::string domain) {
printf("local add: %s\n", domain.data());
}
void OnAddService(std::string service) {
printf("service add: %s\n", service.data());
}
void OnRemoveService(std::string service) {
printf("service remove: %s\n", service.data());
}
void OnAddRecord(std::map<std::string, std::string> service) {
printf("on add\n");
std::map<std::string, std::string>::iterator itr;
for (itr = service.begin(); itr != service.end(); itr++) {
printf("%s: %s\n", itr->first.data(), itr->second.data());
}
}
void OnRemoveRecord(std::map<std::string, std::string> service) {
printf("on remove\n");
std::map<std::string, std::string>::iterator itr;
for (itr = service.begin(); itr != service.end(); itr++) {
printf("%s: %s\n", itr->first.data(), itr->second.data());
}
}
int main() {
mdns::MDnsSub sub("gialuong", "_http._tcp", "local.", 0);
sub.ScanDomain(callback);
// sub.ScanService(OnAddService, OnRemoveService);
sub.ScanRecord(OnAddRecord, NULL);
// printf("host name: %s\n", sub.GetHostname().data());
// printf("ip address: %s\n", sub.GetIpAddress().data());
while(1) {
// printf("domain num: %ld\n", sub.get_domain_list_size());
// printf("service num: %ld\n", sub.get_service_list_size());
// printf("record num: %ld\n", sub.get_record_map_size());
// printf("record name: %s\n", sub.get_record_by_key("name").data());
sleep(2);
};
return 0;
}