pub struct Header { /* private fields */ }
Expand description
The first part of the header of a DNS message.
This type represents the information contained in the first four bytes of the header: the message ID, opcode, rcode, and the various flags.
The type’s data contains such a header in its wire format which is layed out like this:
1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ID |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|QR| Opcode |AA|TC|RD|RA|Z |AD|CD| RCODE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
Methods are available for accessing each of these fields. See Field Access below.
The basic structure and most of the fields re defined in RFC 1035, except for the AD and CD flags, which are defined in RFC 4035.
Implementations§
Source§impl Header
§Creation and Conversion
impl Header
§Creation and Conversion
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new header.
The new header has all fields as either zero or false. Thus, the
opcode will be Opcode::Query
and the response code will be
Rcode::NoError
.
Sourcepub fn for_message_slice(s: &[u8]) -> &Header
pub fn for_message_slice(s: &[u8]) -> &Header
Creates a header reference from a byte slice of a message.
§Panics
This function panics if the byte slice is too short.
Sourcepub fn for_message_slice_mut(s: &mut [u8]) -> &mut Header
pub fn for_message_slice_mut(s: &mut [u8]) -> &mut Header
Creates a mutable header reference from a byte slice of a message.
§Panics
This function panics if the byte slice is too short.
Source§impl Header
§Field Access
impl Header
§Field Access
Sourcepub fn id(self) -> u16
pub fn id(self) -> u16
Returns the value of the ID field.
The ID field is an identifier chosen by whoever created a query and is copied into a response by a server. It allows matching incoming responses to their queries.
Sourcepub fn set_random_id(&mut self)
pub fn set_random_id(&mut self)
Sets the value of the ID field to a randomly chosen number.
This uses rand::random
which may not be good enough.
Sourcepub fn qr(self) -> bool
pub fn qr(self) -> bool
Returns whether the QR bit is set.
The QR bit specifies whether this message is a query (false
) or
a response (true
). In other words, this bit is actually stating
whether the message is not a query. So, perhaps it might be good
to read ‘QR’ as ‘query response.’
Sourcepub fn opcode(self) -> Opcode
pub fn opcode(self) -> Opcode
Returns the value of the Opcode field.
This field specifies the kind of query this message contains. See
the Opcode
type for more information on the possible values and
their meaning. Normal queries have the variant Opcode::Query
which is also the value set when creating a new header.
Sourcepub fn set_opcode(&mut self, opcode: Opcode)
pub fn set_opcode(&mut self, opcode: Opcode)
Sets the value of the opcode field.
Sourcepub fn aa(self) -> bool
pub fn aa(self) -> bool
Returns whether the AA bit is set.
Using this bit, a name server generating a response states whether it is authoritative for the requested domain name, ie., whether this response is an authoritative answer. The field has no meaning in a query.
Sourcepub fn tc(self) -> bool
pub fn tc(self) -> bool
Returns whether the TC bit is set.
The truncation bit is set if there was more data available then fit into the message. This is typically used when employing datagram transports such as UDP to signal to try again using a stream transport such as TCP.
Sourcepub fn rd(self) -> bool
pub fn rd(self) -> bool
Returns whether the RD bit is set.
The recursion desired bit may be set in a query to ask the name server to try and recursively gather a response if it doesn’t have the data available locally. The bit’s value is copied into the response.
Sourcepub fn ra(self) -> bool
pub fn ra(self) -> bool
Returns whether the RA bit is set.
In a response, the recursion available bit denotes whether the responding name server supports recursion. It has no meaning in a query.
Sourcepub fn z(self) -> bool
pub fn z(self) -> bool
Returns whether the reserved bit is set.
This bit must be false
in all queries and responses.
Sourcepub fn ad(self) -> bool
pub fn ad(self) -> bool
Returns whether the AD bit is set.
The authentic data bit is used by security-aware recursive name servers to indicate that it considers all RRsets in its response to be authentic.
Sourcepub fn cd(self) -> bool
pub fn cd(self) -> bool
Returns whether the CD bit is set.
The checking disabled bit is used by a security-aware resolver to indicate that it does not want upstream name servers to perform verification but rather would like to verify everything itself.