Skip to content

Commit 68bd824

Browse files
committed
Check if this is already an FQDN
1 parent c7dd73f commit 68bd824

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

embassy-net/src/lib.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -532,20 +532,12 @@ impl<D: Driver> Stack<D> {
532532
_ => {}
533533
}
534534

535-
// Form name together with domain name.
536535
#[cfg(feature = "dhcpv4-domainname")]
537-
let name = &{
538-
use core::str::FromStr;
539-
540-
let mut name = String::<MAX_DNS_QUERY_LEN>::from_str(name).map_err(|_| dns::Error::NameTooLong)?;
541-
542-
if let Some(Some(domain_name)) = &self.inner.borrow().static_v4.as_ref().map(|c| &c.domain_name) {
543-
if !domain_name.is_empty() {
544-
name.push('.').map_err(|_| dns::Error::NameTooLong)?;
545-
name.push_str(&domain_name).map_err(|_| dns::Error::NameTooLong)?;
546-
}
547-
}
536+
let name = if name.contains(".") {
537+
// Already a FQDN.
548538
name
539+
} else {
540+
&self.create_fqdn(name)?
549541
};
550542

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

624616
res
625617
}
618+
619+
#[cfg(feature = "dhcpv4-domainname")]
620+
fn create_fqdn(&self, name: &str) -> Result<String<MAX_DNS_QUERY_LEN>, dns::Error> {
621+
use core::str::FromStr;
622+
623+
// Form name together with domain name.
624+
let mut name = String::<MAX_DNS_QUERY_LEN>::from_str(name).map_err(|_| dns::Error::NameTooLong)?;
625+
626+
if let Some(Some(domain_name)) = &self.inner.borrow().static_v4.as_ref().map(|c| &c.domain_name) {
627+
if !domain_name.is_empty() {
628+
name.push('.').map_err(|_| dns::Error::NameTooLong)?;
629+
name.push_str(&domain_name).map_err(|_| dns::Error::NameTooLong)?;
630+
}
631+
}
632+
633+
Ok(name)
634+
}
626635
}
627636

628637
#[cfg(feature = "igmp")]

0 commit comments

Comments
 (0)