Skip to content

Commit

Permalink
adding support for new link_types: null/loopback and ipv4/ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Dec 30, 2023
1 parent f61b4e3 commit 77cbe30
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 135 deletions.
22 changes: 16 additions & 6 deletions src/gui/pages/overview_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use iced::widget::{
use iced::widget::{horizontal_space, Rule};
use iced::Length::{Fill, FillPortion, Fixed};
use iced::{Alignment, Font, Length, Renderer};
use pcap::Linktype;

use crate::countries::country_utils::get_flag_tooltip;
use crate::countries::flags_pictures::FLAGS_WIDTH_BIG;
Expand Down Expand Up @@ -65,11 +66,13 @@ pub fn overview_page(sniffer: &Sniffer) -> Container<Message, Renderer<StyleType
sniffer.runtime_data.tot_sent_packets + sniffer.runtime_data.tot_received_packets;
let dropped = sniffer.runtime_data.dropped_packets;
let total = observed + u128::from(dropped);
let link_type = sniffer.runtime_data.link_type;

match (observed, filtered) {
(0, 0) => {
//no packets observed at all
body = body_no_packets(&sniffer.device, font, language, &sniffer.waiting);
body =
body_no_packets(&sniffer.device, font, language, &sniffer.waiting, link_type);
}
(observed, 0) => {
//no packets have been filtered but some have been observed
Expand Down Expand Up @@ -139,8 +142,10 @@ fn body_no_packets(
font: Font,
language: Language,
waiting: &str,
link_type: Linktype,
) -> Column<'static, Message, Renderer<StyleType>> {
let adapter_name = device.name.clone();
let mut adapter_name = device.name.clone();
adapter_name.push_str(&format!(" ({})", link_type.0,));
let (icon_text, nothing_to_see_text) = if device.addresses.lock().unwrap().is_empty() {
(
Icon::Warning.to_text().size(60),
Expand Down Expand Up @@ -422,8 +427,10 @@ fn lazy_col_info(
let filtered_bytes =
sniffer.runtime_data.tot_sent_bytes + sniffer.runtime_data.tot_received_bytes;
let all_bytes = sniffer.runtime_data.all_bytes;
let link_type = sniffer.runtime_data.link_type;

let col_device_filters = col_device_filters(language, font, &sniffer.filters, &sniffer.device);
let col_device_filters =
col_device_filters(language, font, &sniffer.filters, &sniffer.device, link_type);

let col_data_representation =
col_data_representation(language, font, sniffer.traffic_chart.chart_type);
Expand Down Expand Up @@ -512,19 +519,22 @@ fn col_device_filters(
font: Font,
filters: &Filters,
device: &MyDevice,
link_type: Linktype,
) -> Column<'static, Message, Renderer<StyleType>> {
#[cfg(not(target_os = "windows"))]
let adapter_info = &device.name;
let mut adapter_info = device.name.to_owned();
#[cfg(target_os = "windows")]
let adapter_name = &device.name;
#[cfg(target_os = "windows")]
let adapter_info = device.desc.as_ref().unwrap_or(adapter_name);
let mut adapter_info = device.desc.as_ref().unwrap_or(adapter_name);

adapter_info.push_str(&format!(" ({})", link_type.0,));

Column::new()
.width(Length::FillPortion(1))
.push(TextType::highlighted_subtitle_with_desc(
network_adapter_translation(language),
adapter_info,
&adapter_info,
font,
))
.push(vertical_space(15))
Expand Down
4 changes: 4 additions & 0 deletions src/gui/types/runtime_data.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
//! Module defining the `RunTimeData` struct, useful to to generate chart and to display statistics about network traffic
//!
use pcap::Linktype;
use std::collections::VecDeque;

use crate::notifications::types::logged_notification::LoggedNotification;

/// Struct containing useful data to display statistics about network traffic and the relative notifications
pub struct RunTimeData {
/// Link type of the current capture (e.g., ethernet)
pub link_type: Linktype,
/// Total number of bytes (filtered and not filtered)
pub all_bytes: u128,
/// Total number of packets (filtered and not filtered)
Expand Down Expand Up @@ -38,6 +41,7 @@ impl RunTimeData {
/// Constructs a new `ChartsData` element.
pub fn new() -> Self {
RunTimeData {
link_type: Linktype::ETHERNET,
all_bytes: 0,
all_packets: 0,
tot_sent_bytes: 0,
Expand Down
1 change: 1 addition & 0 deletions src/gui/types/sniffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ impl Sniffer {
self.runtime_data.tot_received_bytes = info_traffic_lock.tot_received_bytes;
self.runtime_data.tot_sent_bytes = info_traffic_lock.tot_sent_bytes;
self.runtime_data.dropped_packets = info_traffic_lock.dropped_packets;
self.runtime_data.link_type = info_traffic_lock.link_type;
drop(info_traffic_lock);
let emitted_notifications = notify_and_log(
&mut self.runtime_data,
Expand Down
2 changes: 1 addition & 1 deletion src/networking/manage_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn analyze_link_header(
*mac_address2 = mac_from_dec_to_hex(header.destination);
true
}
_ => false,
_ => true,
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/networking/types/info_traffic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Module defining the `ReportInfo` struct, useful to format the output report file and
//! to keep track of statistics about the sniffed traffic.
use pcap::Linktype;
use std::collections::{HashMap, HashSet};

use crate::networking::types::address_port_pair::AddressPortPair;
Expand All @@ -13,6 +14,8 @@ use crate::AppProtocol;

/// Struct to be shared between the threads in charge of parsing packets and update reports.
pub struct InfoTraffic {
/// Link type of the current capture (e.g., ethernet)
pub link_type: Linktype,
/// Total amount of filtered bytes received.
pub tot_received_bytes: u128,
/// Total amount of filtered bytes sent.
Expand Down Expand Up @@ -47,6 +50,7 @@ impl InfoTraffic {
/// Constructs a new `InfoTraffic` element.
pub fn new() -> Self {
InfoTraffic {
link_type: Linktype::ETHERNET,
tot_received_bytes: 0,
tot_sent_bytes: 0,
tot_received_packets: 0,
Expand Down
Loading

0 comments on commit 77cbe30

Please sign in to comment.