| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
LibP2P.Discovery.MDNS.Message
Description
Minimal DNS wire-format codec for mDNS (RFC 1035 §4, RFC 6762).
Only what mDNS discovery needs:
- a 12-byte header with the byte counts of the four sections;
- question entries (domain name, type, class);
- resource records with
PTR,TXTandSRVrdata decoded (unknown types are passed through as raw bytes); - name compression (RFC 1035 §4.1.4 pointers) on read: peers using other implementations compress names, so we must follow pointers. On write we emit plain, uncompressed names — valid for every reader.
mDNS-specific notes (RFC 6762): the header ID is 0 on genuine multicast traffic; legacy unicast queries keep their ID and are answered unicast. Class values carry the cache-flush / unicast-response bits in their high bits; we keep the raw 16-bit class and never interpret those bits.
Synopsis
- data DnsPacket = DnsPacket {
- pkID :: !Word16
- pkFlags :: !Word16
- pkQuestion :: ![DnsQuestion]
- pkAnswer :: ![DnsRecord]
- pkAdditional :: ![DnsRecord]
- data DnsQuestion = DnsQuestion {}
- data DnsRecord = DnsRecord {}
- data DnsRData
- typePTR :: Word16
- typeTXT :: Word16
- typeSRV :: Word16
- classIN :: Word16
- encodeDnsPacket :: DnsPacket -> ByteString
- decodeDnsPacket :: ByteString -> Either String DnsPacket
Packet types
An mDNS packet: header plus the four sections (the name-server section is ignored; mDNS never uses it).
Constructors
| DnsPacket | |
Fields
| |
data DnsQuestion Source #
A question section entry.
Constructors
| DnsQuestion | |
Instances
| Show DnsQuestion Source # | |
Defined in LibP2P.Discovery.MDNS.Message Methods showsPrec :: Int -> DnsQuestion -> ShowS # show :: DnsQuestion -> String # showList :: [DnsQuestion] -> ShowS # | |
| Eq DnsQuestion Source # | |
Defined in LibP2P.Discovery.MDNS.Message | |
A resource record from answer / additional sections.
Constructors
| DnsRecord | |
Decoded rdata for the record types mDNS discovery uses; anything else travels as raw bytes, so a forward-compatible peer's extra records never break parsing of the records we do care about.
Constructors
| RdPtr !Text |
|
| RdTxt ![ByteString] |
|
| RdSrv !Word16 !Word16 !Word16 !Text |
|
| RdOther !ByteString |
Record types (RFC 1035)
Codec
decodeDnsPacket :: ByteString -> Either String DnsPacket Source #
Decode a packet, resolving name compression. A structurally
invalid packet is a Left; the mDNS service ignores malformed
packets — multicast input is unauthenticated.