Skip to content

Commit

Permalink
Add draft structs for Message, Header
Browse files Browse the repository at this point in the history
  • Loading branch information
matei-radu committed Jul 13, 2024
1 parent 9dddc06 commit c1da859
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dns_lib"
version = "0.9.0"
version = "0.10.0"
description = "An implementation of the DNS protocol from scratch based on the many DNS RFCs."

rust-version.workspace = true
Expand Down
1 change: 1 addition & 0 deletions lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ An implementation of the DNS protocol from scratch based on the many DNS RFCs.
## RFCs
### Work in progress
- [1034: Domain Names - Concepts and Facilities](https://datatracker.ietf.org/doc/html/rfc1034)
- [1035: Domain Names - Implementation and Specification](https://datatracker.ietf.org/doc/html/rfc1035)

1 change: 1 addition & 0 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

pub mod domain;
pub mod message;

pub use domain::{Domain, TryFromError};

Expand Down
50 changes: 50 additions & 0 deletions lib/src/message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2024 Matei Bogdan Radu
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/// `Message` format used by the DNS protocol.
///
/// For more details, see [RFC 1035, Section 4].
///
/// [RFC 1035, Section 4]: https://datatracker.ietf.org/doc/html/rfc1035#section-4
pub struct Message {
pub header: Header,
}

/// `Header` section of a DNS `Message`.
///
/// The header section is always present. It includes fields that specify
/// which of the remaining sections are present, and also specify
/// whether the message is a query or a response, a standard query or some
/// other opcode, etc.
///
/// For more details, see [RFC 1035, Section 4.1.1].
///
/// [RFC 1035, Section 4.1.1]: https://datatracker.ietf.org/doc/html/rfc1035#section-4.1.1
pub struct Header {
pub id: u16,

pub qr: bool,
pub opcode: u8, // Actually 4-bit, prefer a custom type here
pub aa: bool,
pub tc: bool,
pub rd: bool,
pub ra: bool,
pub z: u8, // Acutally 3 bits, prefer a custom type here,
pub rcode: u8, // Acutally 4 bits, prefer a custom type here,

pub qdcount: u16,
pub ancount: u16,
pub nscount: u16,
pub arcount: u16,
}

0 comments on commit c1da859

Please sign in to comment.