forked from mhaberler/directoryd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_browse.cpp
53 lines (40 loc) · 1.06 KB
/
test_browse.cpp
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
53
#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <map>
#include "Avahi.hpp"
#include "Browser.hpp"
#include "Service.hpp"
using namespace std;
void printservice (const Avahi::Service &s)
{
fprintf(stderr, "\nhostname '%s' '%s' %u '%s'\n",
s.hostname().c_str(),
s.address().c_str(),
s.port(),
s.type().c_str());
for (auto iter = s.txt().begin();
iter != s.txt().end();
++iter) {
fprintf(stderr, "\t%s = %s\n",
iter->first.c_str(),
iter->second.c_str());
}
}
int main()
{
Avahi::Browser browser("_hotdec._tcp");
sleep(2);
while (!browser.ready()) sleep(1);
auto result = browser.lookup_by_name("fooservice");
for_each (result.begin(), result.end(), printservice);
result = browser.lookup_by_name("vision");
for_each (result.begin(), result.end(), printservice);
result = browser.lookup_by_name("ruby-vision",
[](Avahi::Service const &x){
(void)x;
return true;
});
for_each (result.begin(), result.end(), printservice);
return 0;
}