commit f2bcf9225f11a92602d9c88f656636a41e83a7c7
parent 22095e44dcc4ec3f4e5c24188cc443556131c993
Author: Daniel Barlow <dan@telent.net>
Date: Thu, 1 Jan 2026 01:30:36 +0000
send probe packets
Diffstat:
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/ecu-esp32/src/wifi.rs b/ecu-esp32/src/wifi.rs
@@ -136,7 +136,47 @@ impl<'a> MdnsResponder<'a> {
}
async fn send_probe(&self) {
- info!("pretend to send probe at {}", Instant::now().as_millis());
+ info!("sending probe at {}", Instant::now().as_millis());
+
+ let db = &self.database;
+
+ let mut questions : Vec<Question> = db.advertised().iter().filter_map( |record| {
+ // FIXME this sends duplicates because there's both an SRV
+ // and a TXT for the same name
+ if record.is_unique() {
+ Some(
+ Question::new(
+ &record.name[..],
+ ResourceType::Wildcard,
+ 1 | (1<<15) // QU
+ ))
+ } else {
+ None
+ }
+ }).collect();
+
+ let message = Message::new(
+ 0,
+ Flags::standard_query(),
+ &mut questions,
+ &mut [],
+ &mut [],
+ &mut []);
+
+ let mut data_buf = [0; 4096];
+ // Serialize the message into the buffer
+ assert!(message.space_needed() <= data_buf.len());
+
+ match message.write(&mut data_buf) {
+ Result::Ok(len) => {
+ if let Result::Err(x) = self.sock.send_to(&data_buf[..len], MDNS_ENDPOINT).await {
+ info!("sock.send failed: {:?}", x);
+ }
+ },
+ Result::Err(err) => {
+ error!("message.write {:?}", err);
+ }
+ }
}
async fn advertise(&self) {