summaryrefslogtreecommitdiffstats
path: root/src/network/sniffer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/sniffer.rs')
-rw-r--r--src/network/sniffer.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/network/sniffer.rs b/src/network/sniffer.rs
index bd16cc4..9d44275 100644
--- a/src/network/sniffer.rs
+++ b/src/network/sniffer.rs
@@ -80,16 +80,19 @@ macro_rules! extract_transport_protocol {
pub struct Sniffer {
network_interface: NetworkInterface,
network_frames: Box<dyn DataLinkReceiver>,
+ dns_shown: bool,
}
impl Sniffer {
pub fn new(
network_interface: NetworkInterface,
network_frames: Box<dyn DataLinkReceiver>,
+ dns_shown: bool,
) -> Self {
Sniffer {
network_interface,
network_frames,
+ dns_shown,
}
}
pub fn next(&mut self) -> Option<Segment> {
@@ -109,7 +112,7 @@ impl Sniffer {
let version = ip_packet.get_version();
match version {
- 4 => Self::handle_v4(ip_packet, &self.network_interface),
+ 4 => Self::handle_v4(ip_packet, &self.network_interface, self.dns_shown),
6 => Self::handle_v6(
Ipv6Packet::new(&bytes[payload_offset..])?,
&self.network_interface,
@@ -117,9 +120,11 @@ impl Sniffer {
_ => {
let pkg = EthernetPacket::new(bytes)?;
match pkg.get_ethertype() {
- EtherTypes::Ipv4 => {
- Self::handle_v4(Ipv4Packet::new(pkg.payload())?, &self.network_interface)
- }
+ EtherTypes::Ipv4 => Self::handle_v4(
+ Ipv4Packet::new(pkg.payload())?,
+ &self.network_interface,
+ self.dns_shown,
+ ),
EtherTypes::Ipv6 => {
Self::handle_v6(Ipv6Packet::new(pkg.payload())?, &self.network_interface)
}
@@ -148,7 +153,11 @@ impl Sniffer {
direction,
})
}
- fn handle_v4(ip_packet: Ipv4Packet, network_interface: &NetworkInterface) -> Option<Segment> {
+ fn handle_v4(
+ ip_packet: Ipv4Packet,
+ network_interface: &NetworkInterface,
+ show_dns: bool,
+ ) -> Option<Segment> {
let (protocol, source_port, destination_port, data_length) =
extract_transport_protocol!(ip_packet);
@@ -161,6 +170,10 @@ impl Sniffer {
Direction::Download => Connection::new(from, to.ip(), destination_port, protocol),
Direction::Upload => Connection::new(to, from.ip(), source_port, protocol),
};
+
+ if !show_dns && connection.remote_socket.port == 53 {
+ return None;
+ }
Some(Segment {
interface_name,
connection,