fixed redundency reports
This commit is contained in:
parent
42e73cd431
commit
9c53e692cc
1 changed files with 12 additions and 5 deletions
13
src/main.rs
13
src/main.rs
|
@ -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,11 +89,14 @@ 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) {
|
||||||
|
let mut unique_packets_guard = unique_packets.lock().unwrap();
|
||||||
|
if unique_packets_guard.insert(info.clone()) {
|
||||||
packets.lock().unwrap().push(info.clone());
|
packets.lock().unwrap().push(info.clone());
|
||||||
tx.send(info).unwrap();
|
tx.send(info).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
*is_listening = false;
|
*is_listening = false;
|
||||||
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue