mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 17:15:43 +00:00
utils: add a parse function for DNS name
This commit is contained in:
@@ -6,6 +6,7 @@ use serde_with::{DeserializeFromStr, SerializeDisplay};
|
|||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
use std::net::{IpAddr, SocketAddr};
|
use std::net::{IpAddr, SocketAddr};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use hickory_proto::rr::LowerName;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub fn sanitize(name: &str) -> String {
|
pub fn sanitize(name: &str) -> String {
|
||||||
@@ -34,6 +35,16 @@ pub fn sanitize(name: &str) -> String {
|
|||||||
name
|
name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn parse(name: &str) -> LowerName {
|
||||||
|
if let Ok(name) = name.parse() {
|
||||||
|
name
|
||||||
|
} else {
|
||||||
|
let sanitized = sanitize(&name);
|
||||||
|
tracing::debug!("invalid hostname: {}, sanitized to: {}", name, sanitized);
|
||||||
|
sanitized.parse().unwrap_or_default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static DNS_SUPPORTED_PROTOCOLS: [Protocol; 2] = [
|
static DNS_SUPPORTED_PROTOCOLS: [Protocol; 2] = [
|
||||||
Protocol::Udp,
|
Protocol::Udp,
|
||||||
Protocol::Tcp,
|
Protocol::Tcp,
|
||||||
|
|||||||
Reference in New Issue
Block a user