mirror of
https://github.com/EmilHernvall/dnsguide.git
synced 2024-12-22 20:24:15 +07:00
commit
506c61c92c
@ -256,7 +256,7 @@ fn main() -> Result<()> {
|
|||||||
loop {
|
loop {
|
||||||
match handle_query(&socket) {
|
match handle_query(&socket) {
|
||||||
Ok(_) => {},
|
Ok(_) => {},
|
||||||
Err(e) => eprintln!("An error occured: {}", e),
|
Err(e) => eprintln!("An error occurred: {}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,10 +300,7 @@ pub struct DnsQuestion {
|
|||||||
|
|
||||||
impl DnsQuestion {
|
impl DnsQuestion {
|
||||||
pub fn new(name: String, qtype: QueryType) -> DnsQuestion {
|
pub fn new(name: String, qtype: QueryType) -> DnsQuestion {
|
||||||
DnsQuestion {
|
DnsQuestion { name, qtype }
|
||||||
name: name,
|
|
||||||
qtype: qtype,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> {
|
pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> {
|
||||||
@ -352,20 +349,16 @@ impl DnsRecord {
|
|||||||
((raw_addr >> 0) & 0xFF) as u8,
|
((raw_addr >> 0) & 0xFF) as u8,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(DnsRecord::A {
|
Ok(DnsRecord::A { domain, addr, ttl })
|
||||||
domain: domain,
|
|
||||||
addr: addr,
|
|
||||||
ttl: ttl,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
QueryType::UNKNOWN(_) => {
|
QueryType::UNKNOWN(_) => {
|
||||||
buffer.step(data_len as usize)?;
|
buffer.step(data_len as usize)?;
|
||||||
|
|
||||||
Ok(DnsRecord::UNKNOWN {
|
Ok(DnsRecord::UNKNOWN {
|
||||||
domain: domain,
|
domain,
|
||||||
qtype: qtype_num,
|
qtype: qtype_num,
|
||||||
data_len: data_len,
|
data_len,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,10 +336,7 @@ pub struct DnsQuestion {
|
|||||||
|
|
||||||
impl DnsQuestion {
|
impl DnsQuestion {
|
||||||
pub fn new(name: String, qtype: QueryType) -> DnsQuestion {
|
pub fn new(name: String, qtype: QueryType) -> DnsQuestion {
|
||||||
DnsQuestion {
|
DnsQuestion { name, qtype }
|
||||||
name: name,
|
|
||||||
qtype: qtype,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> {
|
pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> {
|
||||||
@ -398,20 +395,16 @@ impl DnsRecord {
|
|||||||
((raw_addr >> 0) & 0xFF) as u8,
|
((raw_addr >> 0) & 0xFF) as u8,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(DnsRecord::A {
|
Ok(DnsRecord::A { domain, addr, ttl })
|
||||||
domain: domain,
|
|
||||||
addr: addr,
|
|
||||||
ttl: ttl,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
QueryType::UNKNOWN(_) => {
|
QueryType::UNKNOWN(_) => {
|
||||||
buffer.step(data_len as usize)?;
|
buffer.step(data_len as usize)?;
|
||||||
|
|
||||||
Ok(DnsRecord::UNKNOWN {
|
Ok(DnsRecord::UNKNOWN {
|
||||||
domain: domain,
|
domain,
|
||||||
qtype: qtype_num,
|
qtype: qtype_num,
|
||||||
data_len: data_len,
|
data_len,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,10 +361,7 @@ pub struct DnsQuestion {
|
|||||||
|
|
||||||
impl DnsQuestion {
|
impl DnsQuestion {
|
||||||
pub fn new(name: String, qtype: QueryType) -> DnsQuestion {
|
pub fn new(name: String, qtype: QueryType) -> DnsQuestion {
|
||||||
DnsQuestion {
|
DnsQuestion { name, qtype }
|
||||||
name: name,
|
|
||||||
qtype: qtype,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> {
|
pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> {
|
||||||
@ -444,11 +441,7 @@ impl DnsRecord {
|
|||||||
((raw_addr >> 0) & 0xFF) as u8,
|
((raw_addr >> 0) & 0xFF) as u8,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(DnsRecord::A {
|
Ok(DnsRecord::A { domain, addr, ttl })
|
||||||
domain: domain,
|
|
||||||
addr: addr,
|
|
||||||
ttl: ttl,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
QueryType::AAAA => {
|
QueryType::AAAA => {
|
||||||
let raw_addr1 = buffer.read_u32()?;
|
let raw_addr1 = buffer.read_u32()?;
|
||||||
@ -466,20 +459,16 @@ impl DnsRecord {
|
|||||||
((raw_addr4 >> 0) & 0xFFFF) as u16,
|
((raw_addr4 >> 0) & 0xFFFF) as u16,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(DnsRecord::AAAA {
|
Ok(DnsRecord::AAAA { domain, addr, ttl })
|
||||||
domain: domain,
|
|
||||||
addr: addr,
|
|
||||||
ttl: ttl,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
QueryType::NS => {
|
QueryType::NS => {
|
||||||
let mut ns = String::new();
|
let mut ns = String::new();
|
||||||
buffer.read_qname(&mut ns)?;
|
buffer.read_qname(&mut ns)?;
|
||||||
|
|
||||||
Ok(DnsRecord::NS {
|
Ok(DnsRecord::NS {
|
||||||
domain: domain,
|
domain,
|
||||||
host: ns,
|
host: ns,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
QueryType::CNAME => {
|
QueryType::CNAME => {
|
||||||
@ -487,9 +476,9 @@ impl DnsRecord {
|
|||||||
buffer.read_qname(&mut cname)?;
|
buffer.read_qname(&mut cname)?;
|
||||||
|
|
||||||
Ok(DnsRecord::CNAME {
|
Ok(DnsRecord::CNAME {
|
||||||
domain: domain,
|
domain,
|
||||||
host: cname,
|
host: cname,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
QueryType::MX => {
|
QueryType::MX => {
|
||||||
@ -498,20 +487,20 @@ impl DnsRecord {
|
|||||||
buffer.read_qname(&mut mx)?;
|
buffer.read_qname(&mut mx)?;
|
||||||
|
|
||||||
Ok(DnsRecord::MX {
|
Ok(DnsRecord::MX {
|
||||||
domain: domain,
|
domain,
|
||||||
priority: priority,
|
priority,
|
||||||
host: mx,
|
host: mx,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
QueryType::UNKNOWN(_) => {
|
QueryType::UNKNOWN(_) => {
|
||||||
buffer.step(data_len as usize)?;
|
buffer.step(data_len as usize)?;
|
||||||
|
|
||||||
Ok(DnsRecord::UNKNOWN {
|
Ok(DnsRecord::UNKNOWN {
|
||||||
domain: domain,
|
domain,
|
||||||
qtype: qtype_num,
|
qtype: qtype_num,
|
||||||
data_len: data_len,
|
data_len,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,10 +361,7 @@ pub struct DnsQuestion {
|
|||||||
|
|
||||||
impl DnsQuestion {
|
impl DnsQuestion {
|
||||||
pub fn new(name: String, qtype: QueryType) -> DnsQuestion {
|
pub fn new(name: String, qtype: QueryType) -> DnsQuestion {
|
||||||
DnsQuestion {
|
DnsQuestion { name, qtype }
|
||||||
name: name,
|
|
||||||
qtype: qtype,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> {
|
pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> {
|
||||||
@ -444,11 +441,7 @@ impl DnsRecord {
|
|||||||
((raw_addr >> 0) & 0xFF) as u8,
|
((raw_addr >> 0) & 0xFF) as u8,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(DnsRecord::A {
|
Ok(DnsRecord::A { domain, addr, ttl })
|
||||||
domain: domain,
|
|
||||||
addr: addr,
|
|
||||||
ttl: ttl,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
QueryType::AAAA => {
|
QueryType::AAAA => {
|
||||||
let raw_addr1 = buffer.read_u32()?;
|
let raw_addr1 = buffer.read_u32()?;
|
||||||
@ -466,20 +459,16 @@ impl DnsRecord {
|
|||||||
((raw_addr4 >> 0) & 0xFFFF) as u16,
|
((raw_addr4 >> 0) & 0xFFFF) as u16,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(DnsRecord::AAAA {
|
Ok(DnsRecord::AAAA { domain, addr, ttl })
|
||||||
domain: domain,
|
|
||||||
addr: addr,
|
|
||||||
ttl: ttl,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
QueryType::NS => {
|
QueryType::NS => {
|
||||||
let mut ns = String::new();
|
let mut ns = String::new();
|
||||||
buffer.read_qname(&mut ns)?;
|
buffer.read_qname(&mut ns)?;
|
||||||
|
|
||||||
Ok(DnsRecord::NS {
|
Ok(DnsRecord::NS {
|
||||||
domain: domain,
|
domain,
|
||||||
host: ns,
|
host: ns,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
QueryType::CNAME => {
|
QueryType::CNAME => {
|
||||||
@ -487,9 +476,9 @@ impl DnsRecord {
|
|||||||
buffer.read_qname(&mut cname)?;
|
buffer.read_qname(&mut cname)?;
|
||||||
|
|
||||||
Ok(DnsRecord::CNAME {
|
Ok(DnsRecord::CNAME {
|
||||||
domain: domain,
|
domain,
|
||||||
host: cname,
|
host: cname,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
QueryType::MX => {
|
QueryType::MX => {
|
||||||
@ -498,20 +487,20 @@ impl DnsRecord {
|
|||||||
buffer.read_qname(&mut mx)?;
|
buffer.read_qname(&mut mx)?;
|
||||||
|
|
||||||
Ok(DnsRecord::MX {
|
Ok(DnsRecord::MX {
|
||||||
domain: domain,
|
domain,
|
||||||
priority: priority,
|
priority,
|
||||||
host: mx,
|
host: mx,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
QueryType::UNKNOWN(_) => {
|
QueryType::UNKNOWN(_) => {
|
||||||
buffer.step(data_len as usize)?;
|
buffer.step(data_len as usize)?;
|
||||||
|
|
||||||
Ok(DnsRecord::UNKNOWN {
|
Ok(DnsRecord::UNKNOWN {
|
||||||
domain: domain,
|
domain,
|
||||||
qtype: qtype_num,
|
qtype: qtype_num,
|
||||||
data_len: data_len,
|
data_len,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -793,8 +782,8 @@ fn main() -> Result<()> {
|
|||||||
// requests is initiated.
|
// requests is initiated.
|
||||||
loop {
|
loop {
|
||||||
match handle_query(&socket) {
|
match handle_query(&socket) {
|
||||||
Ok(_) => {},
|
Ok(_) => {}
|
||||||
Err(e) => eprintln!("An error occured: {}", e),
|
Err(e) => eprintln!("An error occurred: {}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,10 +361,7 @@ pub struct DnsQuestion {
|
|||||||
|
|
||||||
impl DnsQuestion {
|
impl DnsQuestion {
|
||||||
pub fn new(name: String, qtype: QueryType) -> DnsQuestion {
|
pub fn new(name: String, qtype: QueryType) -> DnsQuestion {
|
||||||
DnsQuestion {
|
DnsQuestion { name, qtype }
|
||||||
name: name,
|
|
||||||
qtype: qtype,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> {
|
pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> {
|
||||||
@ -444,11 +441,7 @@ impl DnsRecord {
|
|||||||
((raw_addr >> 0) & 0xFF) as u8,
|
((raw_addr >> 0) & 0xFF) as u8,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(DnsRecord::A {
|
Ok(DnsRecord::A { domain, addr, ttl })
|
||||||
domain: domain,
|
|
||||||
addr: addr,
|
|
||||||
ttl: ttl,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
QueryType::AAAA => {
|
QueryType::AAAA => {
|
||||||
let raw_addr1 = buffer.read_u32()?;
|
let raw_addr1 = buffer.read_u32()?;
|
||||||
@ -466,20 +459,16 @@ impl DnsRecord {
|
|||||||
((raw_addr4 >> 0) & 0xFFFF) as u16,
|
((raw_addr4 >> 0) & 0xFFFF) as u16,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(DnsRecord::AAAA {
|
Ok(DnsRecord::AAAA { domain, addr, ttl })
|
||||||
domain: domain,
|
|
||||||
addr: addr,
|
|
||||||
ttl: ttl,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
QueryType::NS => {
|
QueryType::NS => {
|
||||||
let mut ns = String::new();
|
let mut ns = String::new();
|
||||||
buffer.read_qname(&mut ns)?;
|
buffer.read_qname(&mut ns)?;
|
||||||
|
|
||||||
Ok(DnsRecord::NS {
|
Ok(DnsRecord::NS {
|
||||||
domain: domain,
|
domain,
|
||||||
host: ns,
|
host: ns,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
QueryType::CNAME => {
|
QueryType::CNAME => {
|
||||||
@ -487,9 +476,9 @@ impl DnsRecord {
|
|||||||
buffer.read_qname(&mut cname)?;
|
buffer.read_qname(&mut cname)?;
|
||||||
|
|
||||||
Ok(DnsRecord::CNAME {
|
Ok(DnsRecord::CNAME {
|
||||||
domain: domain,
|
domain,
|
||||||
host: cname,
|
host: cname,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
QueryType::MX => {
|
QueryType::MX => {
|
||||||
@ -498,20 +487,20 @@ impl DnsRecord {
|
|||||||
buffer.read_qname(&mut mx)?;
|
buffer.read_qname(&mut mx)?;
|
||||||
|
|
||||||
Ok(DnsRecord::MX {
|
Ok(DnsRecord::MX {
|
||||||
domain: domain,
|
domain,
|
||||||
priority: priority,
|
priority,
|
||||||
host: mx,
|
host: mx,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
QueryType::UNKNOWN(_) => {
|
QueryType::UNKNOWN(_) => {
|
||||||
buffer.step(data_len as usize)?;
|
buffer.step(data_len as usize)?;
|
||||||
|
|
||||||
Ok(DnsRecord::UNKNOWN {
|
Ok(DnsRecord::UNKNOWN {
|
||||||
domain: domain,
|
domain,
|
||||||
qtype: qtype_num,
|
qtype: qtype_num,
|
||||||
data_len: data_len,
|
data_len,
|
||||||
ttl: ttl,
|
ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -886,8 +875,8 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
match handle_query(&socket) {
|
match handle_query(&socket) {
|
||||||
Ok(_) => {},
|
Ok(_) => {}
|
||||||
Err(e) => eprintln!("An error occured: {}", e),
|
Err(e) => eprintln!("An error occurred: {}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user