libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
mdnsrecord.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_MDNS
13#include <cstdint>
14#include <promeki/namespace.h>
15#include <promeki/buffer.h>
16#include <promeki/duration.h>
17#include <promeki/error.h>
18#include <promeki/ipv4address.h>
19#include <promeki/ipv6address.h>
20#include <promeki/list.h>
22#include <promeki/string.h>
23
24PROMEKI_NAMESPACE_BEGIN
25
62class MdnsRecord {
63 public:
65 enum class Type : uint16_t {
66 Unknown = 0,
67 A = 1,
68 Ptr = 12,
69 Txt = 16,
70 Aaaa = 28,
71 Srv = 33,
72 };
73
75 static constexpr int64_t DefaultTtlSeconds = 75 * 60;
76
77 MdnsRecord() = default;
78
90 static MdnsRecord ptr(const String &owner, const String &target,
91 const Duration &ttl = Duration::fromSeconds(DefaultTtlSeconds));
92
107 static MdnsRecord srv(const String &owner, const String &target, uint16_t port,
108 uint16_t priority = 0, uint16_t weight = 0,
109 const Duration &ttl = Duration::fromSeconds(DefaultTtlSeconds));
110
119 static MdnsRecord txt(const String &owner, const MdnsTxtRecord &txt,
120 const Duration &ttl = Duration::fromSeconds(DefaultTtlSeconds));
121
129 static MdnsRecord a(const String &owner, const Ipv4Address &address,
130 const Duration &ttl = Duration::fromSeconds(DefaultTtlSeconds));
131
139 static MdnsRecord aaaa(const String &owner, const Ipv6Address &address,
140 const Duration &ttl = Duration::fromSeconds(DefaultTtlSeconds));
141
143 Type type() const { return _type; }
144
146 const String &name() const { return _name; }
147
149 const Duration &ttl() const { return _ttl; }
150
155 bool cacheFlush() const { return _cacheFlush; }
156
163 void setCacheFlush(bool enable) { _cacheFlush = enable; }
164
166 const String &ptrTarget() const { return _ptrTarget; }
167
169 uint16_t srvPriority() const { return _srvPriority; }
171 uint16_t srvWeight() const { return _srvWeight; }
173 uint16_t srvPort() const { return _srvPort; }
175 const String &srvTarget() const { return _srvTarget; }
176
178 const MdnsTxtRecord &txtRecord() const { return _txt; }
179
181 const Ipv4Address &aAddress() const { return _a; }
182
184 const Ipv6Address &aaaaAddress() const { return _aaaa; }
185
187 bool isGoodbye() const { return _ttl == Duration::zero(); }
188
190 bool operator==(const MdnsRecord &other) const;
191 bool operator!=(const MdnsRecord &other) const { return !(*this == other); }
192
193 private:
194 Type _type = Type::Unknown;
195 String _name;
196 Duration _ttl;
197 bool _cacheFlush = true;
198
199 String _ptrTarget;
200 uint16_t _srvPriority = 0;
201 uint16_t _srvWeight = 0;
202 uint16_t _srvPort = 0;
203 String _srvTarget;
204 MdnsTxtRecord _txt;
205 Ipv4Address _a;
206 Ipv6Address _aaaa;
207};
208
223Buffer mdnsBuildAnnounce(const List<MdnsRecord> &records, uint16_t transactionId = 0);
224
233Buffer mdnsBuildGoodbye(const List<MdnsRecord> &records, uint16_t transactionId = 0);
234
249Buffer mdnsBuildProbe(const List<MdnsRecord> &records, uint16_t transactionId = 0);
250
251PROMEKI_NAMESPACE_END
252
253#endif // PROMEKI_ENABLE_MDNS