-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookupflags.go
126 lines (105 loc) · 3.53 KB
/
lookupflags.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// CGo binding for Avahi
//
// Copyright (C) 2024 and up by Alexander Pevzner ([email protected])
// See LICENSE for license terms and conditions
//
// Avahi lookup flags
//
//go:build linux || freebsd
package avahi
import (
"strings"
)
// #include <avahi-common/defs.h>
import "C"
// LookupFlags provides some options for lookup functions
type LookupFlags int
// LookupFlags values.
//
// Please notice, LookupUseWideArea and LookupUseMulticast are
// mutually exclusive. Each of these flags forces the particular
// lookup methods, so if both are set, no valid lookup methods
// remains. The following simple table summarize usage of these
// flags:
//
// Flags combination Meaning
//
// 0 WAN + Multicast
// LookupUseWideArea WAN only
// LookupUseMulticast mDNS only
// LookupUseWideArea | LookupUseMulticast Invalid
//
// LookupNoTXT and LookupNoAddress are only meaningful for creating
// [ServiceResolver] with the [NewServiceResolver] function. Using
// them for any other purpose may result in [ErrInvalidFlags] error.
const (
// Force lookup via wide area DNS
LookupUseWideArea LookupFlags = C.AVAHI_LOOKUP_USE_WIDE_AREA
// Force lookup via multicast DNS
LookupUseMulticast LookupFlags = C.AVAHI_LOOKUP_USE_MULTICAST
// When doing service resolving, don't lookup TXT record
LookupNoTXT LookupFlags = C.AVAHI_LOOKUP_NO_TXT
// When doing service resolving, don't lookup A/AAAA records
LookupNoAddress LookupFlags = C.AVAHI_LOOKUP_NO_ADDRESS
)
// String returns LookupFlags as string, for debugging
func (flags LookupFlags) String() string {
s := []string{}
if flags&LookupUseWideArea != 0 {
s = append(s, "use-wan")
}
if flags&LookupUseMulticast != 0 {
s = append(s, "use-mdns")
}
if flags&LookupNoTXT != 0 {
s = append(s, "no-txt")
}
if flags&LookupNoAddress != 0 {
s = append(s, "no-addr")
}
return strings.Join(s, ",")
}
// LookupResultFlags provides some additional information about
// lookup response.
type LookupResultFlags int
// LookupResultFlags bits:
const (
// This response originates from the cache
LookupResultCached LookupResultFlags = C.AVAHI_LOOKUP_RESULT_CACHED
// This response originates from wide area DNS
LookupResultWideArea LookupResultFlags = C.AVAHI_LOOKUP_RESULT_WIDE_AREA
// This response originates from multicast DNS
LookupResultMulticast LookupResultFlags = C.AVAHI_LOOKUP_RESULT_MULTICAST
// This record/service resides on and was announced by the local host.
// Only available in service and record browsers and only on
// BrowserNew event.
LookupResultLocal LookupResultFlags = C.AVAHI_LOOKUP_RESULT_LOCAL
// This service belongs to the same local client as the browser object.
// Only for service browsers and only on BrowserNew event.
LookupResultOurOwn LookupResultFlags = C.AVAHI_LOOKUP_RESULT_OUR_OWN
// The returned data was defined statically by server configuration.
LookupResultStatic LookupResultFlags = C.AVAHI_LOOKUP_RESULT_STATIC
)
// String returns LookupResultFlags as string, for debugging
func (flags LookupResultFlags) String() string {
s := []string{}
if flags&LookupResultCached != 0 {
s = append(s, "cached")
}
if flags&LookupResultWideArea != 0 {
s = append(s, "wan-dns")
}
if flags&LookupResultMulticast != 0 {
s = append(s, "mdns")
}
if flags&LookupResultCached != 0 {
s = append(s, "local")
}
if flags&LookupResultOurOwn != 0 {
s = append(s, "our-own")
}
if flags&LookupResultStatic != 0 {
s = append(s, "static")
}
return strings.Join(s, ",")
}