Skip to content

Commit

Permalink
Check if this is already an FQDN
Browse files Browse the repository at this point in the history
  • Loading branch information
korken89 committed Aug 12, 2024
1 parent c7dd73f commit 68bd824
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions embassy-net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,20 +532,12 @@ impl<D: Driver> Stack<D> {
_ => {}
}

// Form name together with domain name.
#[cfg(feature = "dhcpv4-domainname")]
let name = &{
use core::str::FromStr;

let mut name = String::<MAX_DNS_QUERY_LEN>::from_str(name).map_err(|_| dns::Error::NameTooLong)?;

if let Some(Some(domain_name)) = &self.inner.borrow().static_v4.as_ref().map(|c| &c.domain_name) {
if !domain_name.is_empty() {
name.push('.').map_err(|_| dns::Error::NameTooLong)?;
name.push_str(&domain_name).map_err(|_| dns::Error::NameTooLong)?;
}
}
let name = if name.contains(".") {
// Already a FQDN.
name
} else {
&self.create_fqdn(name)?
};

let query = poll_fn(|cx| {
Expand Down Expand Up @@ -623,6 +615,23 @@ impl<D: Driver> Stack<D> {

res
}

#[cfg(feature = "dhcpv4-domainname")]
fn create_fqdn(&self, name: &str) -> Result<String<MAX_DNS_QUERY_LEN>, dns::Error> {
use core::str::FromStr;

// Form name together with domain name.
let mut name = String::<MAX_DNS_QUERY_LEN>::from_str(name).map_err(|_| dns::Error::NameTooLong)?;

if let Some(Some(domain_name)) = &self.inner.borrow().static_v4.as_ref().map(|c| &c.domain_name) {
if !domain_name.is_empty() {
name.push('.').map_err(|_| dns::Error::NameTooLong)?;
name.push_str(&domain_name).map_err(|_| dns::Error::NameTooLong)?;
}
}

Ok(name)
}
}

#[cfg(feature = "igmp")]
Expand Down

0 comments on commit 68bd824

Please sign in to comment.