File: API.md

package info (click to toggle)
mdnsd 0.12-5
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 484 kB
  • sloc: ansic: 4,024; sh: 277; makefile: 107
file content (53 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download | duplicates (2)
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
Library
-------

There are several use-cases for this project, the daemon provides one
use of the library, yet many others are possible.

Here is a small example how to publish a few records:

	char hlocal[384];
	char nlocal[384];
	char hostname[256];
	char *path = "/path/to/service/"

	gethostname(hostname, sizeof(hostname));

	sprintf(hlocal, "%s._http._tcp.local.", hostname);
	sprintf(nlocal, "%s.local.", hostname);

	/* Announce that we have a _http._tcp service */
	r = mdnsd_shared(d, "_services._dns-sd._udp.local.", QTYPE_PTR, 120);
	mdnsd_set_host(d, r, "_http._tcp.local.");

	r = mdnsd_shared(d, "_http._tcp.local.", QTYPE_PTR, 120);
	mdnsd_set_host(d, r, hlocal);
	r = mdnsd_unique(d, hlocal, QTYPE_SRV, 600, conflict, NULL);
	mdnsd_set_srv(d, r, 0, 0, port, nlocal);
	r = mdnsd_unique(d, nlocal, QTYPE_A, 600, conflict, NULL);
	mdnsd_set_ip(d, r, ip_addr);
	r = mdnsd_unique(d, nlocal, QTYPE_AAAA, 600, conflict, NULL);
	mdnsd_set_ipv6(d, r, ip6_addr);

	r = mdnsd_unique(d, hlocal, QTYPE_TXT, 600, conflict, NULL);
	h = xht_new(11);
	if (path && strlen(path))
		xht_set(h, "path", path);
	packet = sd2txt(h, &len);
	xht_free(h);
	mdnsd_set_raw(d, r, (char *)packet, len);
	free(packet);

How to read a previously published record:

	r = mdnsd_get_published(d, "_http._tcp.local.");
	while (r) {
		const mdns_answer_t *data;

		data = mdnsd_record_data(r);
		if (data)
			DBG("Found record of type %d", data->type);

		r = mdnsd_record_next(r);
	}