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 octets of the header: the message ID, opcode, rcode, and the various flags. It keeps those four octets in wire representation, i.e., in network byte order. The data 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. For more information on the fields, see these methods in the section Field Access below.

You can create owned values via the new method or the Default trait. However, more often the type will be used via a reference into the octets of an actual message. The functions for_message_slice and for_message_slice_mut create such references from an octets slice.

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

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.

Creates a header reference from an octets slice of a message.

Panics

This function panics if the slice is less than four octets long.

Creates a mutable header reference from an octets slice of a message.

Panics

This function panics if the slice is less than four octets long.

Returns a reference to the underlying octets slice.

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.

When choosing an ID for an outgoing message, make sure it is random to avoid spoofing by guessing the message ID. If std support is enabled, the method set_random_id can be used for this purpose.

Sets the value of the ID field.

Sets the value of the ID field to a randomly chosen number.

Returns whether the QR bit is set.

Sets the value of the QR bit.

Returns the value of the Opcode field.

This field specifies the kind of query a 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 default value when creating a new header.

Sets the value of the opcode field.

Returns all flags contained in the header.

This is a virtual field composed of all the flag bits that are present in the header. The returned Flags type can be useful when you’re working with all flags, rather than a single one, which can be easily obtained from the header directly.

Sets all flag bits.

Returns whether the AA bit is set.

Sets the value of the AA bit.

Returns whether the TC bit is set.

Sets the value of the TC bit.

Returns whether the RD bit is set.

Sets the value of the RD bit.

Returns whether the RA bit is set.

Sets the value of the RA bit.

Returns whether the reserved bit is set.

This bit must be false in all queries and responses.

Sets the value of the reserved bit.

Returns whether the AD bit is set.

Sets the value of the AD bit.

Returns whether the CD bit is set.

Sets the value of the CD bit.

Returns the value of the RCODE field.

The response code is used in a response to indicate what happened when processing the query. See the Rcode type for information on possible values and their meaning.

Sets the value of the RCODE field.

Trait Implementations

Converts this type into a mutable reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.