Add mdns package and Client implementation (#55)

* add mdns

* define mdns.Client

* fix some mdns stuff

* refine dns package for use with mdns

* remove Querier and Responder and replace with Client

* add record setting methods on dns.record to reuse record buffer

* protect against unbounded client answer growth

* round off sharp mdns edges; reduce allocs

* add mutlicast to stacks; add xnet tests for mdns

* fix documentation on acceptmulticast field

* mdns working
This commit is contained in:
Pat Whittingslow
2026-03-16 19:48:17 +01:00
committed by GitHub
parent 376e1a0b4f
commit bd645b5e1e
14 changed files with 1402 additions and 67 deletions
+38
View File
@@ -52,3 +52,41 @@ func SetIPAddrs(buf []byte, id uint16, src, dst []byte) (err error) {
copy(dstaddr, dst)
return nil
}
// SetMulticast sets the IP destination to multicastAddr and derives the
// Ethernet destination MAC from it. It supports IPv4 (RFC 1112 §6.4) and
// IPv6 (RFC 2464 §7) multicast MAC mapping.
func SetMulticast(ethernetCarrier []byte, ipOff int, multicastAddr []byte) (err error) {
ip := ethernetCarrier[ipOff:]
mac := ethernetCarrier[0:6]
version := ip[0] >> 4
switch version {
case 4:
if len(multicastAddr) != 4 {
return lneto.ErrMismatchLen
}
copy(ip[16:20], multicastAddr)
// IPv4 multicast MAC: 01:00:5e + low 23 bits of IP destination.
mac[0] = 0x01
mac[1] = 0x00
mac[2] = 0x5e
mac[3] = multicastAddr[1] & 0x7f
mac[4] = multicastAddr[2]
mac[5] = multicastAddr[3]
case 6:
if len(multicastAddr) != 16 {
return lneto.ErrMismatchLen
}
copy(ip[24:40], multicastAddr)
// IPv6 multicast MAC: 33:33 + last 4 bytes of IP destination.
mac[0] = 0x33
mac[1] = 0x33
mac[2] = multicastAddr[12]
mac[3] = multicastAddr[13]
mac[4] = multicastAddr[14]
mac[5] = multicastAddr[15]
default:
return lneto.ErrUnsupported
}
return nil
}