Skip to content

Commit

Permalink
feat : Fixed All Lint Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
akashsinghvance committed Jan 3, 2025
1 parent d5d48cc commit bdaad94
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 102 deletions.
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ fn handle_query(socket : &UdpSocket) -> Result<() , Box<dyn std::error::Error>>
}
}
else{
packet.header.rescode = ResultCode::SERVFAIL;
packet.header.rescode = ResultCode::ServFail;
}
}
//We need to make sure that a question is actually present in the packet
//If not , we'll set the response code to `FORMERR` and return an error
else{
packet.header.rescode = ResultCode::FORMERR;
packet.header.rescode = ResultCode::FormErr;
}

//Now we can just encode our response and send it back to the client
Expand Down Expand Up @@ -133,13 +133,13 @@ pub fn recursive_lookup(qname : &str, qtype : QueryType) -> Result <DnsPacket ,
let response = lookup(qname , qtype , server)?;

//If there are entries in the answer section, we can return the packet
if !response.answers.is_empty() && response.header.rescode == ResultCode::NOERROR {
if !response.answers.is_empty() && response.header.rescode == ResultCode::NoError {
return Ok(response);
}

// We might also get a `NXDOMAIN` reply, which is the authoritative name servers
// way of telling us that the name doesn't exist.
if response.header.rescode == ResultCode::NXDOMAIN {
if response.header.rescode == ResultCode::NXDomain {
return Ok(response);
}

Expand All @@ -161,7 +161,7 @@ pub fn recursive_lookup(qname : &str, qtype : QueryType) -> Result <DnsPacket ,
// Here we go down the rabbit hole by starting _another_ lookup sequence in the
// midst of our current one. Hopefully, this will give us the IP of an appropriate
// name server.
let recursive_response = recursive_lookup(&new_ns_name, QueryType::A)?;
let recursive_response = recursive_lookup(new_ns_name, QueryType::A)?;

// Finally, we pick a random ip from the result, and restart the loop. If no such
// record is available, we again return the last result we got.
Expand Down
6 changes: 6 additions & 0 deletions src/protocol/byte_packet_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ pub struct BytePacketBuffer {
pub pos: usize, // Current position in the buffer
}

impl Default for BytePacketBuffer {
fn default() -> Self {
BytePacketBuffer::new()
}
}

impl BytePacketBuffer {
// Initialize a new buffer
pub fn new() -> BytePacketBuffer {
Expand Down
10 changes: 8 additions & 2 deletions src/protocol/dnsheader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ pub struct DnsHeader {
}

//ye implementation mat puchna , its a lot of bit manipulation circus
impl Default for DnsHeader {
fn default() -> Self {
DnsHeader::new()
}
}

impl DnsHeader {
pub fn new() -> DnsHeader {
DnsHeader {
Expand All @@ -35,7 +41,7 @@ impl DnsHeader {
opcode: 0,
response: false,

rescode: ResultCode::NOERROR,
rescode: ResultCode::NoError,
checking_disabled: false,
authed_data: false,
z: false,
Expand Down Expand Up @@ -81,7 +87,7 @@ impl DnsHeader {
| ((self.truncated_message as u8) << 1)
| ((self.authoritative_answer as u8) << 2)
| (self.opcode << 3)
| ((self.response as u8) << 7) as u8,
| ((self.response as u8) << 7),
)?;

buffer.write_u8(
Expand Down
10 changes: 7 additions & 3 deletions src/protocol/dnspacket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::protocol::dnsheader::DnsHeader;
use crate::protocol::dnsquestion::DnsQuestion;
use crate::protocol::dnsrecord::DnsRecord;
use crate::protocol::querytype::QueryType;
use crate::protocol::resultcode::ResultCode;

#[derive(Clone, Debug)]
pub struct DnsPacket {
Expand All @@ -16,6 +15,12 @@ pub struct DnsPacket {
pub resources: Vec<DnsRecord>,
}

impl Default for DnsPacket {
fn default() -> Self {
DnsPacket::new()
}
}

impl DnsPacket {
pub fn new() -> DnsPacket {
DnsPacket {
Expand All @@ -32,7 +37,7 @@ impl DnsPacket {
result.header.read(buffer)?;

for _ in 0..result.header.questions {
let mut question = DnsQuestion::new("".to_string(), QueryType::UNKNOWN(0));
let mut question = DnsQuestion::new("".to_string(), QueryType::Unknown(0));
question.read(buffer)?;
result.questions.push(question);
}
Expand Down Expand Up @@ -119,7 +124,6 @@ impl DnsPacket {
_ => None,
})
})
.map(| addr | addr)
//Finally pick the first valid entry
.next()
}
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/dnsquestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub struct DnsQuestion {
impl DnsQuestion {
pub fn new(name: String, qtype: QueryType) -> DnsQuestion {
DnsQuestion {
name: name,
qtype: qtype,
name,
qtype,
}
}

Expand Down
Loading

0 comments on commit bdaad94

Please sign in to comment.