Skip to content

Commit b319ca2

Browse files
tomDev5mrmonday
authored andcommitted
fixed dns code
1 parent a3a46e6 commit b319ca2

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

pnet_packet/src/dns.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub struct Dns {
289289
#[length_fn = "authority_length"]
290290
pub authorities: Vec<DnsResponse>,
291291
#[length_fn = "additional_length"]
292-
pub additionals: Vec<DnsResponse>,
292+
pub additional: Vec<DnsResponse>,
293293
#[payload]
294294
pub payload: Vec<u8>,
295295
}
@@ -438,7 +438,7 @@ impl DnsQuery {
438438
if label_len == 0 {
439439
break;
440440
}
441-
if qname.is_empty() {
441+
if !qname.is_empty() {
442442
qname.push('.');
443443
}
444444
qname.push_str(
@@ -492,11 +492,11 @@ fn test_dns_query_packet() {
492492
assert_eq!(packet.get_queries()[0].qclass, DnsClasses::IN);
493493
assert_eq!(packet.get_responses().len(), 0);
494494
assert_eq!(packet.get_authorities().len(), 0);
495-
assert_eq!(packet.get_additionals().len(), 0);
495+
assert_eq!(packet.get_additional().len(), 0);
496496
}
497497

498498
#[test]
499-
fn test_dns_reponse_packet() {
499+
fn test_dns_response_packet() {
500500
let packet = DnsPacket::new(b"\xbc\x12\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x05s4dc1\x05samba\x08windows8\x07private\x00\x00\x01\x00\x01\xc0\x0c\x00\x01\x00\x01\x00\x00\x03\x84\x00\x04\xc0\xa8z\xbd").unwrap();
501501
assert_eq!(packet.get_id(), 48146);
502502
assert_eq!(packet.get_is_response(), 1);
@@ -523,9 +523,12 @@ fn test_dns_reponse_packet() {
523523
assert_eq!(packet.get_responses()[0].rclass, DnsClasses::IN);
524524
assert_eq!(packet.get_responses()[0].ttl, 900);
525525
assert_eq!(packet.get_responses()[0].data_len, 4);
526-
assert_eq!(packet.get_responses()[0].data, vec![192, 168, 122, 189]);
526+
assert_eq!(
527+
packet.get_responses()[0].data.as_slice(),
528+
[192, 168, 122, 189]
529+
);
527530
assert_eq!(packet.get_authorities().len(), 0);
528-
assert_eq!(packet.get_additionals().len(), 0);
531+
assert_eq!(packet.get_additional().len(), 0);
529532
}
530533

531534
#[test]
@@ -538,10 +541,10 @@ fn test_dns_query() {
538541
}
539542

540543
#[test]
541-
fn test_dns_reponse() {
544+
fn test_dns_response() {
542545
let data = b"\xc0\x0c\x00\x01\x00\x01\x00\x00\x00<\x00\x04\x0d\xe2\x02\x12";
543546
let packet = DnsResponsePacket::new(data).expect("Failed to parse dns response");
544-
assert_eq!(packet.get_data(), vec![13, 226, 2, 18]);
547+
assert_eq!(packet.get_data().as_slice(), [13, 226, 2, 18]);
545548
assert_eq!(packet.get_rtype(), DnsTypes::A);
546549
assert_eq!(packet.get_rclass(), DnsClasses::IN);
547550
assert_eq!(packet.get_ttl(), 60);

0 commit comments

Comments
 (0)