refactor(fakedns): changed module name, refactored classes/types naming
This commit is contained in:
parent
bb417b8a6d
commit
76c2dff67a
5 changed files with 42 additions and 11 deletions
|
|
@ -1 +0,0 @@
|
|||
pub mod dnsfaker;
|
||||
2
src/sniffing/fakedns/mod.rs
Normal file
2
src/sniffing/fakedns/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
mod resolver;
|
||||
pub mod server;
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
use hickory_resolver::{
|
||||
Resolver, TokioResolver,
|
||||
TokioResolver,
|
||||
config::{NameServerConfig, ResolverConfig},
|
||||
net::runtime::TokioRuntimeProvider,
|
||||
proto::rr::IntoName,
|
||||
};
|
||||
use rand::RngExt;
|
||||
|
||||
|
|
@ -29,12 +28,14 @@ enum Protocols {
|
|||
DoTCP,
|
||||
}
|
||||
|
||||
pub struct FakeIPServer {
|
||||
pub struct FakeIPResolver {
|
||||
entries: FakeIPStorage,
|
||||
pub resolver: Option<TokioResolver>,
|
||||
}
|
||||
|
||||
pub trait FakeIPOptions {
|
||||
#[must_use]
|
||||
fn new() -> Self;
|
||||
fn add(&mut self, domain: String) -> Ipv4Addr;
|
||||
async fn add_real_ip(
|
||||
&mut self,
|
||||
|
|
@ -55,10 +56,15 @@ fn generate_ip_from(network: Ipv4Addr, prefix: u32) -> Ipv4Addr {
|
|||
Ipv4Addr::from(network | host)
|
||||
}
|
||||
|
||||
|
||||
// !TODO #[must_use]:FakeIpServer::new() builder AND FakeIPServer::start(), which unnecessary starts
|
||||
// !TODO FakeIPServer::start(), which unnecessary starts
|
||||
// DNS server itself
|
||||
impl FakeIPOptions for FakeIPServer {
|
||||
impl FakeIPOptions for FakeIPResolver {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
entries: HashMap::new(),
|
||||
resolver: None,
|
||||
}
|
||||
}
|
||||
/// Just gets an FakeIP addr from FakeIPStorage.
|
||||
/// ```rust
|
||||
/// x = FakeIPServer::new(/* params */);
|
||||
|
|
@ -69,8 +75,8 @@ impl FakeIPOptions for FakeIPServer {
|
|||
/// }
|
||||
/// ```
|
||||
fn get(&self, domain: &str) -> Option<IpAddr> {
|
||||
self.entries.get(domain).copied()
|
||||
}
|
||||
self.entries.get(domain).copied()
|
||||
}
|
||||
|
||||
/// FakeIPServer function which init's integrated DNS resolver for
|
||||
/// ```rust
|
||||
24
src/sniffing/fakedns/server.rs
Normal file
24
src/sniffing/fakedns/server.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use crate::sniffing::fakedns::resolver::FakeIPResolver;
|
||||
use hickory_proto::{
|
||||
op::Message,
|
||||
op::MessageType,
|
||||
serialize::{binary, txt},
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
pub struct FakeIPServer {
|
||||
bind: SocketAddr,
|
||||
resolver: FakeIPResolver,
|
||||
}
|
||||
|
||||
impl FakeIPServer {
|
||||
#[must_use]
|
||||
pub fn new(bind: SocketAddr, resolver: FakeIPResolver) -> Self {
|
||||
Self { bind, resolver }
|
||||
}
|
||||
pub async fn serve() -> Result<(), std::io::Error> { todo!() }
|
||||
async fn serve_tcp() -> Result<(), std::io::Error> { todo!() }
|
||||
async fn serve_udp() -> Result<(), std::io::Error> { todo!() }
|
||||
fn set_as_default_resolver() -> Result<(), std::io::Error> { todo!() }
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
mod dns;
|
||||
mod fakedns;
|
||||
pub mod headers;
|
||||
mod metadata;
|
||||
pub mod types;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue