-
Notifications
You must be signed in to change notification settings - Fork 1
/
dns.go
59 lines (48 loc) · 1.13 KB
/
dns.go
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
54
55
56
57
58
59
package main
import (
"net"
"github.com/holoplot/go-avahi"
"ldddns.arnested.dk/internal/log"
)
const (
iface = int32(net.FlagUp)
tld = "local"
)
func addAddress(entryGroup *avahi.EntryGroup, hostname string, ipNumbers []string) {
for _, ipNumber := range ipNumbers {
if ipNumber == "" {
continue
}
err := entryGroup.AddAddress(iface, avahi.ProtoInet, uint32(net.FlagMulticast), hostname, ipNumber)
if err != nil {
log.Logf(log.PriErr, "addAddess() failed: %v", err)
continue
}
log.Logf(log.PriDebug, "added address for %q pointing to %q", hostname, ipNumber)
}
}
func addServices(entryGroup *avahi.EntryGroup, hostname string, ips []string, services map[string]uint16, name string) {
for _, ip := range ips {
if ip == "" {
continue
}
for service, portNumber := range services {
err := entryGroup.AddService(
iface,
avahi.ProtoInet,
0,
name,
service,
tld,
hostname,
portNumber,
nil,
)
if err != nil {
log.Logf(log.PriErr, "AddService() failed: %v", err)
continue
}
log.Logf(log.PriDebug, "added service %q pointing to %q", service, hostname)
}
}
}