Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/dns_parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ pub use self::header::Header;
mod rrdata;
pub use self::rrdata::RRData;
mod builder;
#[allow(unused_imports)]
pub use self::builder::{Answers, Builder, Questions};
2 changes: 2 additions & 0 deletions src/dns_parser/structs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{Class, Header, Name, QueryClass, QueryType, RRData};

/// Parsed DNS packet
#[allow(dead_code)]
#[derive(Debug)]
pub struct Packet<'a> {
pub header: Header,
Expand All @@ -24,6 +25,7 @@ pub struct Question<'a> {
/// We aim to provide whole range of DNS records available. But as time is
/// limited we have some types of packets which are parsed and other provided
/// as unparsed slice of bytes.
#[allow(dead_code)]
#[derive(Debug)]
pub struct ResourceRecord<'a> {
pub name: Name<'a>,
Expand Down
37 changes: 37 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,43 @@ impl Responder {
_shutdown: self.shutdown.clone(),
}
}

#[must_use]
pub fn register_with_ttl(&self, svc_type: String, svc_name: String, port: u16, txt: &[&str], ttl: u32) -> Service {
let txt = if txt.is_empty() {
vec![0]
} else {
txt.iter()
.flat_map(|entry| {
let entry = entry.as_bytes();
if entry.len() > 255 {
panic!("{:?} is too long for a TXT record", entry);
}
std::iter::once(entry.len() as u8).chain(entry.iter().cloned())
})
.collect()
};

let svc = ServiceData {
typ: Name::from_str(format!("{}.local", svc_type)).unwrap(),
name: Name::from_str(format!("{}.{}.local", svc_name, svc_type)).unwrap(),
port: port,
txt: txt,
};

self.commands
.borrow_mut()
.send_unsolicited(svc.clone(), ttl, true);

let id = self.services.write().unwrap().register(svc);

Service {
id: id,
commands: self.commands.borrow().clone(),
services: self.services.clone(),
_shutdown: self.shutdown.clone(),
}
}
}

impl Drop for Service {
Expand Down