commit 6ec2545507ab09e7a413c97eafef9a415a23459e
parent 0b4ea48d94cc7e0315d62b28603d57c10ff9df3f
Author: Daniel Barlow <dan@telent.net>
Date: Sat, 20 Dec 2025 20:35:27 +0000
extract method send_responses
Diffstat:
| M | src/wifi.rs | | | 57 | ++++++++++++++++++++++++++++++++++----------------------- |
1 file changed, 34 insertions(+), 23 deletions(-)
diff --git a/src/wifi.rs b/src/wifi.rs
@@ -7,7 +7,7 @@ use embassy_executor::Spawner;
use embassy_net::{
Runner,
StackResources,
- udp::{PacketMetadata, UdpSocket},
+ udp::{PacketMetadata, UdpSocket, UdpMetadata},
IpAddress,
IpEndpoint
};
@@ -110,6 +110,38 @@ async fn send_advert(sock: &UdpSocket<'_>,
}
}
+async fn send_responses(sock: &UdpSocket<'_>,
+ my_address: &[u8],
+ message: &Message<'_,'_>,
+ meta: &UdpMetadata) {
+
+ let my_hostname = Label::from("eculogical.local");
+ let q_id = message.id();
+
+ // for each relevant question we want to add RRs (as answers
+ // or additional) to the reply packet. I'm uncertain whether
+ // it's ok to do this for legacy queries but they probably
+ // don't have multiple questions anyway
+ for q in message.questions() {
+ log::info!("question {:?} {:?} {:?} flags {:?} from {:?}",
+ q.name(), q.ty(), q.class(),
+ message.flags().raw(),
+ meta.endpoint);
+ if q.name().eq(&my_hostname) {
+ if meta.endpoint.port == 5353 {
+ send_advert(&sock, q_id, MDNS_ENDPOINT, None, &my_address).await;
+ } else if (q.class() & 0x8000) != 0 {
+ log::info!("unicast");
+ send_advert(&sock, q_id, meta.endpoint, None, &my_address).await;
+ } else {
+ // legacy unicast, send questions
+ send_advert(&sock, q_id, meta.endpoint, Some(q), &my_address).await;
+ }
+ log::info!("IT ME");
+ }
+ }
+}
+
pub async fn start_wifi(spawner: &Spawner,
wifi_peripheral: esp_hal::peripherals::WIFI<'static>) -> ! {
@@ -176,8 +208,6 @@ pub async fn start_wifi(spawner: &Spawner,
);
- let my_hostname = Label::from("eculogical.local");
-
send_advert(&sock, rng.random() as u16, MDNS_ENDPOINT, None, &my_address).await;
let mut data_buf = [0; 4096];
@@ -202,26 +232,7 @@ pub async fn start_wifi(spawner: &Spawner,
match message {
Result::Ok(message) => {
- let q_id = message.id();
- for q in message.questions() {
- log::info!("question {:?} {:?} {:?} flags {:?} from {:?}",
- q.name(), q.ty(), q.class(),
- message.flags().raw(),
- meta.endpoint);
- if q.name().eq(&my_hostname) {
- if meta.endpoint.port == 5353 {
- send_advert(&sock, q_id, MDNS_ENDPOINT, None, &my_address).await;
- } else if (q.class() & 0x8000) != 0 {
- log::info!("unicast");
- send_advert(&sock, q_id, meta.endpoint, None, &my_address).await;
- } else {
- // legacy unicast, send questions
- send_advert(&sock, q_id, meta.endpoint, Some(q), &my_address).await;
- }
- log::info!("IT ME");
- }
- }
-
+ send_responses(&sock, &my_address, &message, &meta).await;
},
Result::Err(err) => {
log::error!("parsing dns message: {:?}", err);