pub struct DnsName(/* private fields */);
Expand description
2.3.1. Preferred name syntax
The DNS specifications attempt to be as general as possible in the rules for constructing domain names. The idea is that the name of any existing object can be expressed as a domain name with minimal changes.
However, when assigning a domain name for an object, the prudent user will select a name which satisfies both the rules of the domain system and any existing rules for the object, whether these rules are published or implied by existing programs.
For example, when naming a mail domain, the user should satisfy both the rules of this memo and those in RFC-822. When creating a new host name, the old rules for HOSTS.TXT should be followed. This avoids problems when old software is converted to use domain names.
The following syntax will result in fewer problems with many
applications that use domain names (e.g., mail, TELNET).
<domain> ::= <subdomain> | " "
<subdomain> ::= <label> | <subdomain> "." <label>
<label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]
<ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
<let-dig-hyp> ::= <let-dig> | "-"
<let-dig> ::= <letter> | <digit>
<letter> ::=
any one of the 52 alphabetic charactersA
throughZ
in upper case anda
throughz
in lower case
<digit> ::=
any one of the ten digits0
through9
Note that while upper and lower case letters are allowed in domain names, no significance is attached to the case. That is, two names with the same spelling but different case are to be treated as if identical.
The labels must follow the rules for ARPANET host names. They must start with a letter, end with a letter or digit, and have as interior characters only letters, digits, and hyphen. There are also some restrictions on the length. Labels must be 63 characters or less.
For example, the following strings identify hosts in the Internet:
A.ISI.EDU XX.LCS.MIT.EDU SRI-NIC.ARPA
https://datatracker.ietf.org/doc/html/rfc1035#section-2.3.1
Various objects and parameters in the DNS have size limits. They are listed below. Some could be easily changed, others are more fundamental.
- labels: 63 octets or less
- names: 255 octets or less
- TTL: positive values of a signed 32 bit number.
- UDP messages: 512 octets or less
Implementations§
Source§impl DnsName
impl DnsName
Sourcepub fn new(value: &str) -> Result<Self, String>
pub fn new(value: &str) -> Result<Self, String>
§Errors
Returns an error when value
is not a valid DNS name.
Sourcepub fn read<const N: usize>(buf: &mut FixedBuf<N>) -> Result<DnsName, DnsError>
pub fn read<const N: usize>(buf: &mut FixedBuf<N>) -> Result<DnsName, DnsError>
§Errors
Returns an error when buf
does not contain a valid name.
Sourcepub fn write<const N: usize>(
&self,
out: &mut FixedBuf<N>,
) -> Result<(), DnsError>
pub fn write<const N: usize>( &self, out: &mut FixedBuf<N>, ) -> Result<(), DnsError>
§Errors
Returns an error when buf
fills up.
Sourcepub fn as_bytes(&self) -> Result<FixedBuf<256>, DnsError>
pub fn as_bytes(&self) -> Result<FixedBuf<256>, DnsError>
§Errors
Returns an error when the name is longer than 255 bytes. This cannot happen.