pub struct DnsName {
pub labels: Vec<String>,
}Expand description
A DNS domain name consisting of labels.
Supports encoding/decoding with RFC 1035 compression pointers.
Fields§
§labels: Vec<String>The labels making up the domain name (e.g., [“www”, “example”, “com”]).
Implementations§
Source§impl DnsName
impl DnsName
Sourcepub fn from_str_dotted(s: &str) -> Result<Self, FieldError>
pub fn from_str_dotted(s: &str) -> Result<Self, FieldError>
Parse a DNS name from a dot-separated string. “www.example.com” → labels: [“www”, “example”, “com”] “www.example.com.” → same (trailing dot is ignored)
Sourcepub fn to_fqdn(&self) -> String
pub fn to_fqdn(&self) -> String
Get the fully qualified domain name string. Returns “www.example.com.” with trailing dot.
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
Encode to wire format without compression. Each label is preceded by its length byte, terminated by a zero byte.
Sourcepub fn encode_compressed(
&self,
current_offset: usize,
compression_map: &mut HashMap<String, u16>,
) -> Vec<u8> ⓘ
pub fn encode_compressed( &self, current_offset: usize, compression_map: &mut HashMap<String, u16>, ) -> Vec<u8> ⓘ
Encode to wire format with compression.
Uses compression_map to track previously written name positions.
current_offset is where this name will be written in the packet.
Sourcepub fn decode(packet: &[u8], offset: usize) -> Result<(Self, usize), FieldError>
pub fn decode(packet: &[u8], offset: usize) -> Result<(Self, usize), FieldError>
Decode a DNS name from wire format with pointer decompression.
packet is the full packet buffer (needed for pointer resolution).
offset is the starting position of the name.
Returns the decoded name and the number of bytes consumed from offset
(not counting bytes reached via pointers).