eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 0f327bf29338d7a08d404bc989502064ae95ed1f
parent 791a1e246fac978b46503b7e757eb9eea4edf049
Author: Daniel Barlow <dan@telent.net>
Date:   Mon, 29 Dec 2025 16:55:50 +0000

add RData::{Txt,A}

Diffstat:
Mecu-esp32/src/wifi.rs | 29++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/ecu-esp32/src/wifi.rs b/ecu-esp32/src/wifi.rs @@ -94,7 +94,7 @@ impl<'a> MdnsResponder<'a> { Self { sock, - database: DnsDatabase::create(&my_address), + database: DnsDatabase::create(my_address), } } @@ -229,7 +229,9 @@ impl<'a> MdnsResponder<'a> { enum RData { Raw(Vec<u8>), Srv { target: String, port: u16, priority: u16, weight: u16 }, - Ptr(String) + Ptr(String), + A([u8; 4]), + Txt(Vec<String>) } impl RData { @@ -265,6 +267,23 @@ impl RData { RData::Ptr(name) => { Self::encode_as_label(name, out, 0) } + RData::A(octets) => { + out[..4].clone_from_slice(octets); + &out[..4] + }, + RData::Txt(strings) => { + let mut offset = 0; + for s in strings { + out[offset] = (s.len() & 0xff) as u8; + offset += 1; + for c in s.as_bytes().iter() { + out[offset] = *c; + offset += 1; + } + } + out[offset] = 0; + &out[..(offset+1)] + } } } } @@ -316,12 +335,12 @@ struct DnsDatabase { } impl DnsDatabase { - fn create(my_ip_address : &[u8]) -> Self { + fn create(my_ip_address : [u8; 4]) -> Self { let static_records = [ DnsResource::new( "eculogical.local", ResourceType::A, - RData::Raw(my_ip_address.try_into().unwrap()) + RData::A(my_ip_address) ), DnsResource::new( "Bike._keihin._udp.local", @@ -334,7 +353,7 @@ impl DnsDatabase { DnsResource::new( "Bike._keihin._udp.local", ResourceType::Txt, - RData::Raw(b"\x09txtvers=1".to_vec()) + RData::Txt(["txtvers=1".into()].into()) ), DnsResource::new( "_keihin._udp.local",