I implemented a webserver in rust to serve on port 80/443. No I'm trying to add a mdns server, s.t. I can resolve a hostname/domain automatically to the webserver (e.g. ip of PC + port 80/443). I tried doing so using libmdns, and mdns-sd but both without success. What I'm wondering is, if I really need a service for this, or is there a crate which allows me to just resolve A/AAAA? This is what I tried:
fn main() {
// Initialize the pretty environment logger.
pretty_env_logger::init();
info!("Starting mDNS service advertisement...");
// Create an mDNS daemon that handles publishing and responding.
let mdns = match ServiceDaemon::new() {
Ok(daemon) => daemon,
Err(e) => {
error!("Failed to create mDNS daemon: {}", e);
return;
}
};
// Although we only advertise a name and IP, it seems mDNS/DNS-SD requires a service type.
let service_type = "myserver._http._tcp.local."; // What should I put here???.
let instance_name = "myserver"; // Instance name.
let host_name = "myserver.local."; // Fully qualified name (must end with a dot).
let ip = ""; // IP can be empty with enable_addr_auto
let port = 80; // Port; Is it needed??.
let properties: &[(&str, &str)] = &[("path", "/")]; // What should go here??.
// Create a new ServiceInfo instance that encapsulates the advertisement.
let _service_info = ServiceInfo::new(
service_type,
instance_name,
host_name,
ip,
port,
properties,
).unwrap().enable_addr_auto();
info!("Advertising {} -> {}:{}", host_name, ip, port);
// Keep the application running so the service stays advertised.
loop {
thread::sleep(Duration::from_secs(10));
}
}
When trying to access it with firefox, I get the following trace log:
TRACE mdns_sd::service_daemon > query question: DnsQuestion { entry: DnsEntry { name: "myserver.local.", ty: AAAA, class: 1, cache_flush: false } }
TRACE mdns_sd::service_daemon > send outgoing response: 0 questions 0 answers 0 authorities 0 additional
TRACE mdns_sd::service_daemon > sent out 12 bytes on interface Interface { name: "wlan0", addr: V4(Ifv4Addr { ip: 10.6.51.115, netmask: 255.255.240.0, prefixlen: 20, broadcast: Some(10.6.63.255) }), index: Some(3) }
So the request arrives at the rust mdns server, but somehow outgoing response remains 0.