Skip to content

Commit

Permalink
Merge pull request #421 from GyulyVGC/link-type
Browse files Browse the repository at this point in the history
Add support for more link types: raw IP and null/loopback
  • Loading branch information
GyulyVGC authored Jan 1, 2024
2 parents f61b4e3 + e38c202 commit 6c7be34
Show file tree
Hide file tree
Showing 19 changed files with 537 additions and 305 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All Sniffnet releases with the relative changes are documented in this file.
- 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) and [#419](https://github.com/GyulyVGC/sniffnet/pull/419))
- Added support for more link types in addition to Ethernet: raw IP packets and null/loopback packets are now correctly parsed ([#421](https://github.com/GyulyVGC/sniffnet/pull/421))
- IP addresses can now be copied to clipboard from the popup related to a given entry of the connections table, and a new search parameter has been introduced in Inspect page to allow users filter their connections based on IP address values ([#409](https://github.com/GyulyVGC/sniffnet/pull/409))
- Added Japanese translation 🇯🇵 ([#343](https://github.com/GyulyVGC/sniffnet/pull/343))
- Added Uzbek translation 🇺🇿 ([#385](https://github.com/GyulyVGC/sniffnet/pull/385))
Expand Down
60 changes: 30 additions & 30 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions src/configs/types/config_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use pcap::{Device, DeviceFlags};
use serde::{Deserialize, Serialize};

use crate::networking::types::my_device::MyDevice;
use crate::networking::types::my_link_type::MyLinkType;
#[cfg(not(test))]
use crate::SNIFFNET_LOWERCASE;

Expand Down Expand Up @@ -57,6 +58,7 @@ impl ConfigDevice {
name: device.name,
desc: device.desc,
addresses: Arc::new(Mutex::new(device.addresses)),
link_type: MyLinkType::NotYetAssigned,
};
}
}
Expand All @@ -70,6 +72,7 @@ impl ConfigDevice {
name: standard_device.name,
desc: standard_device.desc,
addresses: Arc::new(Mutex::new(standard_device.addresses)),
link_type: MyLinkType::NotYetAssigned,
}
}
}
Expand Down
47 changes: 32 additions & 15 deletions src/countries/country_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::countries::types::country::Country;
use crate::gui::styles::container::ContainerType;
use crate::gui::styles::svg::SvgType;
use crate::gui::types::message::Message;
use crate::networking::types::data_info_host::DataInfoHost;
use crate::networking::types::traffic_type::TrafficType;
use crate::translations::translations_2::{
local_translation, unknown_translation, your_network_adapter_translation,
Expand All @@ -31,6 +32,7 @@ fn get_flag_from_country(
country: Country,
width: f32,
is_local: bool,
is_loopback: bool,
traffic_type: TrafficType,
language: Language,
) -> (Svg<Renderer<StyleType>>, String) {
Expand Down Expand Up @@ -284,7 +286,11 @@ fn get_flag_from_country(
Country::ZM => ZM,
Country::ZW => ZW,
Country::ZZ => {
if is_local {
if is_loopback {
tooltip = your_network_adapter_translation(language);
svg_style = SvgType::AdaptColor;
COMPUTER
} else if is_local {
tooltip = local_translation(language);
svg_style = SvgType::AdaptColor;
HOME
Expand Down Expand Up @@ -313,13 +319,21 @@ fn get_flag_from_country(
pub fn get_flag_tooltip(
country: Country,
width: f32,
is_local: bool,
traffic_type: TrafficType,
host_info: &DataInfoHost,
language: Language,
font: Font,
) -> Tooltip<'static, Message, Renderer<StyleType>> {
let (content, tooltip) =
get_flag_from_country(country, width, is_local, traffic_type, language);
let is_local = host_info.is_local;
let is_loopback = host_info.is_loopback;
let traffic_type = host_info.traffic_type;
let (content, tooltip) = get_flag_from_country(
country,
width,
is_local,
is_loopback,
traffic_type,
language,
);

let mut tooltip = Tooltip::new(content, tooltip, Position::FollowCursor)
.font(font)
Expand All @@ -335,27 +349,30 @@ pub fn get_flag_tooltip(

pub fn get_computer_tooltip(
is_my_address: bool,
is_local: bool,
traffic_type: TrafficType,
language: Language,
font: Font,
) -> Tooltip<'static, Message, Renderer<StyleType>> {
let content = Svg::new(Handle::from_memory(Vec::from(
match (is_my_address, traffic_type) {
(true, _) => COMPUTER,
(false, TrafficType::Multicast) => MULTICAST,
(false, TrafficType::Broadcast) => BROADCAST,
(false, TrafficType::Unicast) => UNKNOWN,
match (is_my_address, is_local, traffic_type) {
(true, _, _) => COMPUTER,
(false, true, _) => HOME,
(false, false, TrafficType::Multicast) => MULTICAST,
(false, false, TrafficType::Broadcast) => BROADCAST,
(false, false, TrafficType::Unicast) => UNKNOWN,
},
)))
.style(SvgType::AdaptColor)
.width(Length::Fixed(FLAGS_WIDTH_BIG))
.height(Length::Fixed(FLAGS_WIDTH_BIG * 0.75));

let tooltip = match (is_my_address, traffic_type) {
(true, _) => your_network_adapter_translation(language),
(false, TrafficType::Multicast) => "Multicast".to_string(),
(false, TrafficType::Broadcast) => "Broadcast".to_string(),
(false, TrafficType::Unicast) => unknown_translation(language),
let tooltip = match (is_my_address, is_local, traffic_type) {
(true, _, _) => your_network_adapter_translation(language),
(false, true, _) => local_translation(language),
(false, false, TrafficType::Multicast) => "Multicast".to_string(),
(false, false, TrafficType::Broadcast) => "Broadcast".to_string(),
(false, false, TrafficType::Unicast) => unknown_translation(language),
};

Tooltip::new(content, tooltip, Position::FollowCursor)
Expand Down
Loading

0 comments on commit 6c7be34

Please sign in to comment.