Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support CNAME record #2

Merged
merged 3 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use trust_dns_client::op::DnsResponse;
use trust_dns_client::rr::{DNSClass, Name, RecordType};
use trust_dns_client::udp::UdpClientConnection;

// Record Types
/// Record Types
#[derive(Debug, Clone, Copy)]
pub enum RTypes {
A,
AAAA,
CNAME,
MX,
NS,
SOA,
Expand All @@ -23,6 +24,7 @@ impl FromStr for RTypes {
match s {
"A" => Ok(RTypes::A),
"AAAA" => Ok(RTypes::AAAA),
"CNAME" => Ok(RTypes::CNAME),
"MX" => Ok(RTypes::MX),
"NS" => Ok(RTypes::NS),
"SOA" => Ok(RTypes::SOA),
Expand All @@ -36,13 +38,15 @@ fn get_rtype(rtype: RTypes) -> RecordType {
match rtype {
RTypes::A => RecordType::A,
RTypes::AAAA => RecordType::AAAA,
RTypes::CNAME => RecordType::CNAME,
RTypes::MX => RecordType::MX,
RTypes::NS => RecordType::NS,
RTypes::SOA => RecordType::SOA,
RTypes::TXT => RecordType::TXT,
}
}
// Parse address string

/// Parse address string
fn get_address(nameserver: &str) -> std::net::SocketAddr {
let address = format!("{}:53", nameserver).parse::<std::net::SocketAddr>();
match address {
Expand Down
12 changes: 11 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
)
.arg(
Arg::new("rtype")
.possible_values(&["A", "AAAA", "MX", "NS", "SOA", "TXT"])
.possible_values(&["A", "AAAA", "CNAME", "MX", "NS", "SOA", "TXT"])
.default_value("A"),
)
.arg(
Expand Down Expand Up @@ -71,6 +71,16 @@ fn main() {
res.rdata().to_string().bold()
);
}
for res in res.name_servers() {
let rr_type = res.rr_type().to_string().green().bold();

println!(
" {0: <15} {1: <15} {2: <10}",
rr_type.to_string(),
res.name().to_string().blue(),
res.rdata().to_string().bold()
);
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ fn address_invalid() {
.stderr(predicate::str::contains("Invalid addres"));
}

#[test]
fn domain_invalid() {
let mut cmd = Command::cargo_bin("digs").unwrap();
cmd.arg("example")
.arg("-f")
.arg("tests/fixture/invalid-address.toml");
cmd.assert()
.failure()
.stderr(predicate::str::contains("Invalid domain name"));
}

#[test]
fn query() {
let mut cmd = Command::cargo_bin("digs").unwrap();
Expand Down