helper functions, re-imports
This commit is contained in:
parent
325e825b1d
commit
8d92a97850
@ -6,11 +6,8 @@ use clap::Parser;
|
|||||||
use log::{info, LevelFilter};
|
use log::{info, LevelFilter};
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use simplelog::*;
|
use simplelog::*;
|
||||||
use dnstplib::message::header::{Direction, DNSHeader, Opcode, ResponseCode};
|
use dnstplib::message::{DNSQuestion, DNSRequest, DNSHeader, QClass, QType, Direction, Opcode, ResponseCode};
|
||||||
use dnstplib::message::question::{DNSQuestion, QClass, QType};
|
use dnstplib::net::{DNSSocket, NetworkMessage};
|
||||||
use dnstplib::message::request::DNSRequest;
|
|
||||||
use dnstplib::net::socket::DNSSocket;
|
|
||||||
use dnstplib::net::raw_request::NetworkMessage;
|
|
||||||
use dnstplib::processor::ResponseProcesor;
|
use dnstplib::processor::ResponseProcesor;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
@ -49,32 +46,7 @@ fn main() {
|
|||||||
|
|
||||||
info!("sending...");
|
info!("sending...");
|
||||||
|
|
||||||
let message = DNSRequest {
|
let message = DNSRequest::from_hostname(address, rng.next_u32() as u16, "duck.com".to_string());
|
||||||
header: DNSHeader {
|
|
||||||
id: rng.next_u32() as u16,
|
|
||||||
direction: Direction::Request,
|
|
||||||
opcode: Opcode::Query,
|
|
||||||
authoritative: false,
|
|
||||||
truncation: false,
|
|
||||||
recursion_desired: true,
|
|
||||||
recursion_available: false,
|
|
||||||
valid_zeroes: true,
|
|
||||||
response: ResponseCode::NoError,
|
|
||||||
question_count: 1,
|
|
||||||
answer_record_count: 0,
|
|
||||||
authority_record_count: 0,
|
|
||||||
additional_record_count: 0
|
|
||||||
},
|
|
||||||
questions: vec![
|
|
||||||
DNSQuestion {
|
|
||||||
qname: "duck.com".to_string(),
|
|
||||||
qtype: QType::A,
|
|
||||||
qclass: QClass::Internet
|
|
||||||
}
|
|
||||||
],
|
|
||||||
additional_records: vec![],
|
|
||||||
peer: address
|
|
||||||
};
|
|
||||||
|
|
||||||
let bytes = message.to_bytes();
|
let bytes = message.to_bytes();
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use simplelog::*;
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use dnstplib::net::socket::DNSSocket;
|
use dnstplib::net::DNSSocket;
|
||||||
use dnstplib::processor::RequestProcesor;
|
use dnstplib::processor::RequestProcesor;
|
||||||
|
|
||||||
/// Command-line arguments for configuring the server
|
/// Command-line arguments for configuring the server
|
||||||
|
@ -128,4 +128,26 @@ impl DNSHeader {
|
|||||||
|
|
||||||
header_bytes
|
header_bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_request(id: u16, questions: Option<u16>) -> DNSHeader
|
||||||
|
{
|
||||||
|
DNSHeader {
|
||||||
|
id,
|
||||||
|
direction: Direction::Request,
|
||||||
|
opcode: Opcode::Query,
|
||||||
|
authoritative: false,
|
||||||
|
truncation: false,
|
||||||
|
recursion_desired: true,
|
||||||
|
recursion_available: false,
|
||||||
|
valid_zeroes: true,
|
||||||
|
response: ResponseCode::NoError,
|
||||||
|
question_count: match questions {
|
||||||
|
None => 1,
|
||||||
|
Some(v) => v
|
||||||
|
},
|
||||||
|
answer_record_count: 0,
|
||||||
|
authority_record_count: 0,
|
||||||
|
additional_record_count: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use crate::message::{DNSQuestion, DNSHeader, questions_to_bytes};
|
use crate::message::{DNSQuestion, DNSHeader, questions_to_bytes, Direction, Opcode, ResponseCode, QType, QClass};
|
||||||
|
|
||||||
#[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Clone)]
|
#[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Clone)]
|
||||||
pub struct DNSRequest {
|
pub struct DNSRequest {
|
||||||
@ -20,4 +20,38 @@ impl DNSRequest {
|
|||||||
|
|
||||||
return header_bytes
|
return header_bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_hostname(peer: SocketAddr, id: u16, hostname: String) -> DNSRequest
|
||||||
|
{
|
||||||
|
DNSRequest {
|
||||||
|
header: DNSHeader::new_request(id, None),
|
||||||
|
questions: vec![
|
||||||
|
DNSQuestion {
|
||||||
|
qname: hostname,
|
||||||
|
qtype: QType::A,
|
||||||
|
qclass: QClass::Internet
|
||||||
|
}
|
||||||
|
],
|
||||||
|
additional_records: vec![],
|
||||||
|
peer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_hostnames(peer: SocketAddr, id: u16, hostnames: Vec<String>) -> DNSRequest
|
||||||
|
{
|
||||||
|
DNSRequest {
|
||||||
|
header: DNSHeader::new_request(id, Some(hostnames.len() as u16)),
|
||||||
|
questions: hostnames
|
||||||
|
.into_iter()
|
||||||
|
.map(|n|
|
||||||
|
DNSQuestion {
|
||||||
|
qname: n,
|
||||||
|
qclass: QClass::Internet,
|
||||||
|
qtype: QType::A
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
additional_records: vec![],
|
||||||
|
peer
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,6 +3,7 @@ use std::sync::mpsc::{Receiver, Sender};
|
|||||||
use std::thread;
|
use std::thread;
|
||||||
use log::info;
|
use log::info;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use crate::message::DNSResponse;
|
||||||
use crate::net::raw_request::NetworkMessagePtr;
|
use crate::net::raw_request::NetworkMessagePtr;
|
||||||
|
|
||||||
pub struct ResponseProcesor {
|
pub struct ResponseProcesor {
|
||||||
@ -25,7 +26,7 @@ impl ResponseProcesor {
|
|||||||
|
|
||||||
for mut m in rx
|
for mut m in rx
|
||||||
{
|
{
|
||||||
info!("processing: {}", str::from_utf8(&(*(*m).buffer)).unwrap());
|
info!("processing response");
|
||||||
|
|
||||||
// match sending_channel.send(m) {
|
// match sending_channel.send(m) {
|
||||||
// Ok(_) => {}
|
// Ok(_) => {}
|
||||||
|
Loading…
Reference in New Issue
Block a user