fixed redundency reports

This commit is contained in:
Tristan Smith 2024-06-10 10:20:06 -04:00
parent 42e73cd431
commit 9c53e692cc

View file

@ -6,6 +6,7 @@ use gtk::{
}; };
use pcap::{Capture, Device}; use pcap::{Capture, Device};
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashSet;
use std::rc::Rc; use std::rc::Rc;
use std::sync::mpsc::{self}; use std::sync::mpsc::{self};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -16,7 +17,7 @@ const DESTINATION_IP: &str = "255.255.255.255";
const SOURCE_PORT: u16 = 14236; const SOURCE_PORT: u16 = 14236;
const DESTINATION_PORT: u16 = 14235; const DESTINATION_PORT: u16 = 14235;
#[derive(Clone)] #[derive(Clone, Hash, Eq, PartialEq)]
struct PacketInfo { struct PacketInfo {
source_ip: String, source_ip: String,
source_mac: String, source_mac: String,
@ -53,10 +54,12 @@ fn main() {
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
let listening = Arc::new(Mutex::new(false)); let listening = Arc::new(Mutex::new(false));
let packets = Arc::new(Mutex::new(Vec::new())); let packets = Arc::new(Mutex::new(Vec::new()));
let unique_packets = Arc::new(Mutex::new(HashSet::new()));
let pool = ThreadPool::new(4); let pool = ThreadPool::new(4);
{ {
let packets = Arc::clone(&packets); let packets = Arc::clone(&packets);
let unique_packets = Arc::clone(&unique_packets);
let list_store = list_store.clone(); let list_store = list_store.clone();
let status_label = Rc::clone(&status_label); let status_label = Rc::clone(&status_label);
let listening_main = Arc::clone(&listening); let listening_main = Arc::clone(&listening);
@ -65,6 +68,7 @@ fn main() {
let tx = tx.clone(); let tx = tx.clone();
let listening = Arc::clone(&listening_main); let listening = Arc::clone(&listening_main);
let packets = Arc::clone(&packets); let packets = Arc::clone(&packets);
let unique_packets = Arc::clone(&unique_packets);
let status_label = Rc::clone(&status_label); let status_label = Rc::clone(&status_label);
let mut is_listening = listening.lock().unwrap(); let mut is_listening = listening.lock().unwrap();
@ -85,8 +89,11 @@ fn main() {
while *listening.lock().unwrap() { while *listening.lock().unwrap() {
if let Ok(packet) = cap.next_packet() { if let Ok(packet) = cap.next_packet() {
if let Some(info) = extract_packet_info(packet.data) { if let Some(info) = extract_packet_info(packet.data) {
packets.lock().unwrap().push(info.clone()); let mut unique_packets_guard = unique_packets.lock().unwrap();
tx.send(info).unwrap(); if unique_packets_guard.insert(info.clone()) {
packets.lock().unwrap().push(info.clone());
tx.send(info).unwrap();
}
} }
} }
} }
@ -164,9 +171,9 @@ fn create_column(title: &str, id: i32) -> TreeViewColumn {
gtk::prelude::TreeViewColumnExt::add_attribute(&column, &cell, "text", id); gtk::prelude::TreeViewColumnExt::add_attribute(&column, &cell, "text", id);
if title == "IP Address" { if title == "IP Address" {
column.set_fixed_width(50); // Set a fixed width for the IP Address column column.set_fixed_width(50);
} else { } else {
column.set_fixed_width(350); // Set a fixed width for other columns column.set_fixed_width(300);
} }
column column