Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All Sniffnet releases with the relative changes are documented in this file.

## [UNRELEASED]
- Added support for ICMP connections and messages ([#417](https://github.com/GyulyVGC/sniffnet/pull/417) — fixes [#288](https://github.com/GyulyVGC/sniffnet/issues/288))
- Introduced new filtering capabilities to allow users specify custom values of ports and IP addresses ([#414](https://github.com/GyulyVGC/sniffnet/pull/414))
- The size of text and widgets can now be customised by setting a proper zoom value (fixes [#202](https://github.com/GyulyVGC/sniffnet/issues/202) and [#344](https://github.com/GyulyVGC/sniffnet/issues/344))
- Added possibility to totally customize the app's theme via styles defined in TOML files ([#286](https://github.com/GyulyVGC/sniffnet/pull/286))
Expand Down
46 changes: 18 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/countries/types/country.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl Default for Country {
impl fmt::Display for Country {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if self.eq(&Country::ZZ) {
write!(f, "")
write!(f, "?")
} else {
write!(f, "{self:?}")
}
Expand Down
9 changes: 5 additions & 4 deletions src/gui/components/button.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::gui::styles::container::ContainerType;
use crate::gui::types::message::Message;
use crate::translations::translations::hide_translation;
use crate::{Language, StyleType};
use iced::alignment::{Horizontal, Vertical};
use iced::widget::tooltip::Position;
use iced::widget::{button, Text, Tooltip};
use iced::{Font, Length, Renderer};

use crate::gui::styles::container::ContainerType;
use crate::gui::types::message::Message;
use crate::translations::translations::hide_translation;
use crate::{Language, StyleType};

#[allow(clippy::module_name_repetitions)]
pub fn button_hide(
message: Message,
Expand Down
108 changes: 76 additions & 32 deletions src/gui/pages/connection_details_page.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::net::IpAddr;

use iced::alignment::{Horizontal, Vertical};
use iced::widget::scrollable::Direction;
use iced::widget::tooltip::Position;
use iced::widget::{button, horizontal_space, lazy, vertical_space, Rule};
use iced::widget::{button, horizontal_space, lazy, vertical_space, Rule, Scrollable};
use iced::widget::{Column, Container, Row, Text, Tooltip};
use iced::Length::Fixed;
use iced::{Alignment, Font, Length, Renderer};
Expand All @@ -11,6 +12,7 @@ use crate::countries::country_utils::{get_computer_tooltip, get_flag_tooltip};
use crate::countries::flags_pictures::FLAGS_WIDTH_BIG;
use crate::gui::components::button::button_hide;
use crate::gui::styles::container::ContainerType;
use crate::gui::styles::scrollbar::ScrollbarType;
use crate::gui::styles::style_constants::{get_font, get_font_headers, FONT_SIZE_TITLE};
use crate::gui::styles::text::TextType;
use crate::gui::styles::types::gradient_type::GradientType;
Expand All @@ -19,21 +21,23 @@ use crate::gui::types::timing_events::TimingEvents;
use crate::networking::manage_packets::{get_address_to_lookup, get_traffic_type, is_my_address};
use crate::networking::types::address_port_pair::AddressPortPair;
use crate::networking::types::host::Host;
use crate::networking::types::icmp_type::IcmpType;
use crate::networking::types::info_address_port_pair::InfoAddressPortPair;
use crate::networking::types::traffic_direction::TrafficDirection;
use crate::translations::translations::{
application_protocol_translation, incoming_translation, outgoing_translation,
packets_translation, transport_protocol_translation,
address_translation, application_protocol_translation, incoming_translation,
outgoing_translation, packets_translation, protocol_translation,
transport_protocol_translation,
};
use crate::translations::translations_2::{
administrative_entity_translation, connection_details_translation, destination_translation,
fqdn_translation, mac_address_translation, socket_address_translation, source_translation,
transmitted_data_translation,
};
use crate::translations::translations_3::copy_translation;
use crate::translations::translations_3::{copy_translation, messages_translation};
use crate::utils::formatted_strings::{get_formatted_bytes_string_with_b, get_socket_address};
use crate::utils::types::icon::Icon;
use crate::{Language, Sniffer, StyleType};
use crate::{Language, Protocol, Sniffer, StyleType};

pub fn connection_details_page(
sniffer: &Sniffer,
Expand Down Expand Up @@ -186,9 +190,16 @@ fn col_info(
font: Font,
language: Language,
) -> Column<'static, Message, Renderer<StyleType>> {
Column::new()
let is_icmp = key.protocol.eq(&Protocol::ICMP);
let protocol_caption = if is_icmp {
protocol_translation(language)
} else {
transport_protocol_translation(language)
};

let mut ret_val = Column::new()
.spacing(10)
.padding([0, 0, 0, 40])
.padding([20, 10, 20, 40])
.width(Length::FillPortion(2))
.push(vertical_space(Length::FillPortion(1)))
.push(
Expand All @@ -202,34 +213,62 @@ fn col_info(
),
)
.push(TextType::highlighted_subtitle_with_desc(
transport_protocol_translation(language),
protocol_caption,
&key.protocol.to_string(),
font,
))
.push(TextType::highlighted_subtitle_with_desc(
));

if !is_icmp {
ret_val = ret_val.push(TextType::highlighted_subtitle_with_desc(
application_protocol_translation(language),
&val.app_protocol.to_string(),
font,
))
.push(TextType::highlighted_subtitle_with_desc(
&format!(
"{} ({})",
transmitted_data_translation(language),
if val.traffic_direction.eq(&TrafficDirection::Outgoing) {
outgoing_translation(language).to_lowercase()
} else {
incoming_translation(language).to_lowercase()
}
),
&format!(
"{}\n {} {}",
get_formatted_bytes_string_with_b(val.transmitted_bytes),
val.transmitted_packets,
packets_translation(language)
),
font,
))
.push(vertical_space(Length::FillPortion(1)))
));
}

ret_val = ret_val.push(TextType::highlighted_subtitle_with_desc(
&format!(
"{} ({})",
transmitted_data_translation(language),
if val.traffic_direction.eq(&TrafficDirection::Outgoing) {
outgoing_translation(language).to_lowercase()
} else {
incoming_translation(language).to_lowercase()
}
),
&format!(
"{}\n {} {}",
get_formatted_bytes_string_with_b(val.transmitted_bytes),
val.transmitted_packets,
packets_translation(language)
),
font,
));

if is_icmp {
ret_val =
ret_val.push(
Column::new()
.push(
Text::new(format!("{}:", messages_translation(language)))
.style(TextType::Subtitle)
.font(font),
)
.push(
Scrollable::new(Column::new().padding([0, 10, 10, 0]).push(
Text::new(IcmpType::pretty_print_types(&val.icmp_types)).font(font),
))
.direction(Direction::Both {
vertical: ScrollbarType::properties(),
horizontal: ScrollbarType::properties(),
}),
),
);
}

ret_val = ret_val.push(vertical_space(Length::FillPortion(1)));

ret_val
}

fn get_host_info_col(
Expand Down Expand Up @@ -294,12 +333,17 @@ fn get_local_tooltip(
fn get_src_or_dest_col(
caption: Row<'static, Message, Renderer<StyleType>>,
ip: &String,
port: u16,
port: Option<u16>,
mac: &str,
font: Font,
language: Language,
timing_events: &TimingEvents,
) -> Column<'static, Message, Renderer<StyleType>> {
let address_caption = if port.is_some() {
socket_address_translation(language)
} else {
address_translation(language)
};
Column::new()
.spacing(4)
.push(
Expand All @@ -313,7 +357,7 @@ fn get_src_or_dest_col(
.spacing(10)
.align_items(Alignment::End)
.push(TextType::highlighted_subtitle_with_desc(
socket_address_translation(language),
address_caption,
&get_socket_address(ip, port),
font,
))
Expand Down
8 changes: 4 additions & 4 deletions src/gui/pages/overview_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ fn col_app(width: f32, sniffer: &Sniffer) -> Column<'static, Message, Renderer<S
data_info,
);

// check if Other is longer than the first entry
if app.eq(&AppProtocol::Other) && incoming_bar_len + outgoing_bar_len > width * 0.88 {
// check if Unknown is longer than the first entry
if app.eq(&AppProtocol::Unknown) && incoming_bar_len + outgoing_bar_len > width * 0.88 {
let incoming_proportion = incoming_bar_len / (incoming_bar_len + outgoing_bar_len);
incoming_bar_len = width * 0.88 * incoming_proportion;
outgoing_bar_len = width * 0.88 * (1.0 - incoming_proportion);
Expand All @@ -375,7 +375,7 @@ fn col_app(width: f32, sniffer: &Sniffer) -> Column<'static, Message, Renderer<S
.width(Length::Fixed(width))
.push(
Row::new()
.push(Text::new(format!("{app:?}")).font(font))
.push(Text::new(app.to_string()).font(font))
.push(horizontal_space(Length::FillPortion(1)))
.push(
Text::new(if chart_type.eq(&ChartType::Packets) {
Expand All @@ -392,7 +392,7 @@ fn col_app(width: f32, sniffer: &Sniffer) -> Column<'static, Message, Renderer<S
button(content)
.padding([5, 15, 8, 10])
.on_press(Message::Search(SearchParameters {
app: format!("{app:?}"),
app: app.to_string(),
..SearchParameters::default()
}))
.style(ButtonType::Neutral),
Expand Down
9 changes: 8 additions & 1 deletion src/gui/types/sniffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,16 @@ mod tests {
sniffer.update(Message::ProtocolSelection(Protocol::UDP, true));
assert_eq!(sniffer.filters.protocols, HashSet::from(Protocol::ALL));
sniffer.update(Message::ProtocolSelection(Protocol::UDP, false));
assert_eq!(sniffer.filters.protocols, HashSet::from([Protocol::TCP]));
assert_eq!(
sniffer.filters.protocols,
HashSet::from([Protocol::TCP, Protocol::ICMP])
);
sniffer.update(Message::ProtocolSelection(Protocol::TCP, false));
assert_eq!(sniffer.filters.protocols, HashSet::from([Protocol::ICMP]));
sniffer.update(Message::ProtocolSelection(Protocol::ICMP, false));
assert_eq!(sniffer.filters.protocols, HashSet::new());
sniffer.update(Message::ProtocolSelection(Protocol::UDP, true));
assert_eq!(sniffer.filters.protocols, HashSet::from([Protocol::UDP]));
}

#[test]
Expand Down
Loading