Skip to content

Commit

Permalink
support parsing packets without ethernet header: mac addresses are no…
Browse files Browse the repository at this point in the history
…w optional
  • Loading branch information
GyulyVGC committed Dec 30, 2023
1 parent 77cbe30 commit 4696a5e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
11 changes: 9 additions & 2 deletions src/gui/pages/connection_details_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ fn get_src_or_dest_col(
caption: Row<'static, Message, Renderer<StyleType>>,
ip: &String,
port: Option<u16>,
mac: &str,
mac: &Option<String>,
font: Font,
language: Language,
timing_events: &TimingEvents,
Expand All @@ -348,6 +348,13 @@ fn get_src_or_dest_col(
} else {
address_translation(language)
};

let mac_str = if let Some(val) = mac {
&val
} else {
"-"
};

Column::new()
.spacing(4)
.push(
Expand All @@ -369,7 +376,7 @@ fn get_src_or_dest_col(
)
.push(TextType::highlighted_subtitle_with_desc(
mac_address_translation(language),
mac,
mac_str,
font,
))
}
Expand Down
24 changes: 12 additions & 12 deletions src/networking/manage_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ use crate::{AppProtocol, InfoTraffic, IpVersion, Protocol};
/// Returns the relevant collected information.
pub fn analyze_headers(
headers: PacketHeaders,
mac_addresses: &mut (String, String),
mac_addresses: &mut (Option<String>, Option<String>),
exchanged_bytes: &mut u128,
icmp_type: &mut IcmpType,
packet_filters_fields: &mut PacketFiltersFields,
) -> Option<AddressPortPair> {
if !analyze_link_header(headers.link, &mut mac_addresses.0, &mut mac_addresses.1) {
return None;
}
analyze_link_header(headers.link, &mut mac_addresses.0, &mut mac_addresses.1);

if !analyze_network_header(
headers.ip,
Expand Down Expand Up @@ -71,16 +69,18 @@ pub fn analyze_headers(
/// Returns false if packet has to be skipped.
fn analyze_link_header(
link_header: Option<Ethernet2Header>,
mac_address1: &mut String,
mac_address2: &mut String,
) -> bool {
mac_address1: &mut Option<String>,
mac_address2: &mut Option<String>,
) {
match link_header {
Some(header) => {
*mac_address1 = mac_from_dec_to_hex(header.source);
*mac_address2 = mac_from_dec_to_hex(header.destination);
true
*mac_address1 = Some(mac_from_dec_to_hex(header.source));
*mac_address2 = Some(mac_from_dec_to_hex(header.destination));
}
_ => true,
_ => {
*mac_address1 = None;
*mac_address2 = None;
},
}
}

Expand Down Expand Up @@ -167,7 +167,7 @@ pub fn modify_or_insert_in_map(
info_traffic_mutex: &Arc<Mutex<InfoTraffic>>,
key: &AddressPortPair,
my_device: &MyDevice,
mac_addresses: (String, String),
mac_addresses: (Option<String>, Option<String>),
icmp_type: IcmpType,
exchanged_bytes: u128,
application_protocol: AppProtocol,
Expand Down
4 changes: 2 additions & 2 deletions src/networking/types/info_address_port_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use crate::AppProtocol;
#[derive(Clone, Default)]
pub struct InfoAddressPortPair {
/// Source MAC address
pub mac_address1: String,
pub mac_address1: Option<String>,
/// Destination MAC address
pub mac_address2: String,
pub mac_address2: Option<String>,
/// Amount of bytes transmitted between the pair.
pub transmitted_bytes: u128,
/// Amount of packets transmitted between the pair.
Expand Down
2 changes: 1 addition & 1 deletion src/secondary_threads/parse_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn parse_packets(
},
} {
let mut exchanged_bytes = 0;
let mut mac_addresses = (String::new(), String::new());
let mut mac_addresses = (None, None);
let mut icmp_type = IcmpType::default();
let mut packet_filters_fields = PacketFiltersFields::default();

Expand Down

0 comments on commit 4696a5e

Please sign in to comment.