struct DnsNameSegment
Defined at line 86 of file ../../src/firmware/gigaboot/cpp/mdns.h
DNS (and mDNS) names are defined using a graph structure a little like an inverted tree: there
are many entry leaves, and at each higher layer the `next` segment aggregates leaves feeding
inwards. The "root" of the tree is an implicit, empty string. It can be replaced with a null
`next` in the graph representation. DNS queries use a simple length+string representation for
serializing each name segment. The length field is 1 octet and has a maximum value of 63, or
0b00111111. The root is indicated with a length of zero. Joining dots are implicit.
Example representation for able.baker.charlie.com:
DnsNameSegment example[] = {
{.name = "able", .loc = 0, .next =
&example
[1]},
{.name = "baker", .loc = 0, .next =
&example
[2]},
{.name = "charlie", .loc = 0, .next =
&example
[3]},
{.name = "com", .loc = 0, .next = nullptr},
};
DnsNameSegment* server =
&example
[0];
Which serializes to
4 a b l e 5 b a k e r 7 c h a r l i e 3 c o m 0
If the two most significant bits of the serialized length are set, then the length
is instead a two octet offset field within the DNS payload describing the
continuation of the fully qualified domain name.
i.e. deserialization might look something like this
uint8_t length = *reinterpret_cast
<uint8
_t*>(ptr);
if(length =
<
63){
// Uncompressed string segment
} else if (length
&
0xC0){
uint16_t offset = ntohs(*reinterpret_cast
<uint16
_t*>(ptr))
&
~0xC000;
length = *reinterpret_cast
<uint8
_t*>(payload + offset);
} else {
// error, inconsistent length.
}
The DnsNameSegment `loc` is then specific to a serialized DNS payload.
It depends on what names were previously serialized in the payload and in what order.
The `loc` field is cleared at the beginning of serialization
and is set as part of serialization.
Public Members
basic_string_view name
uint16_t loc
DnsNameSegment * next