Skip to content

Commit cf98f49

Browse files
committed
add process column to inspect page table
1 parent bbaec98 commit cf98f49

5 files changed

Lines changed: 35 additions & 11 deletions

File tree

src/gui/pages/inspect_page.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn inspect_page(sniffer: &Sniffer) -> Container<Message, StyleType> {
107107
.align_y(Alignment::Center)
108108
.align_x(Alignment::Center)
109109
.padding(Padding::new(7.0).top(10).bottom(3))
110-
.width(1042)
110+
.width(1042 + 221 - 95)
111111
.class(ContainerType::BorderedRound),
112112
);
113113

src/networking/manage_packets.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ pub fn modify_or_insert_in_map(
222222
let now = Local::now();
223223
let mut traffic_direction = TrafficDirection::default();
224224
let mut service = Service::Unknown;
225+
let mut process = "-".to_string();
225226

226227
if !info_traffic_mutex.lock().unwrap().map.contains_key(key) {
227228
// first occurrence of key
@@ -252,12 +253,11 @@ pub fn modify_or_insert_in_map(
252253
// determine process
253254
if let Some(local_port) = get_local_port(&key, traffic_direction) {
254255
let processes = listeners::get_processes_by_port(local_port);
255-
if let Ok(processes) = processes {
256-
println!("Processes listening on port {local_port}:");
257-
for process in processes {
258-
println!("\t--> {process}");
259-
}
260-
}
256+
process = processes
257+
.iter()
258+
.flatten()
259+
.next()
260+
.map_or("?".to_string(), |p| p.name.to_owned());
261261
}
262262
};
263263

@@ -287,6 +287,7 @@ pub fn modify_or_insert_in_map(
287287
initial_timestamp: now,
288288
final_timestamp: now,
289289
service,
290+
process,
290291
traffic_direction,
291292
icmp_types: if key.protocol.eq(&Protocol::ICMP) {
292293
HashMap::from([(icmp_type, 1)])

src/networking/types/info_address_port_pair.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub struct InfoAddressPortPair {
2828
pub final_timestamp: DateTime<Local>,
2929
/// Upper layer service carried by the associated address:port pair.
3030
pub service: Service,
31+
/// Process using the local port of this connection.
32+
pub process: String,
3133
/// Determines if the connection is incoming or outgoing
3234
pub traffic_direction: TrafficDirection,
3335
/// Types of the ICMP messages exchanged, with the relative count (this is empty if not ICMP)

src/report/types/report_col.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub enum ReportCol {
2525
DstPort,
2626
Proto,
2727
Service,
28+
Process,
2829
Bytes,
2930
Packets,
3031
}
@@ -37,8 +38,9 @@ impl ReportCol {
3738
ReportCol::DstPort,
3839
ReportCol::Proto,
3940
ReportCol::Service,
41+
ReportCol::Process,
4042
ReportCol::Bytes,
41-
ReportCol::Packets,
43+
// ReportCol::Packets,
4244
];
4345

4446
pub(crate) const FILTER_COLUMNS_WIDTH: f32 = 4.0 * SMALL_COL_WIDTH + 2.0 * LARGE_COL_WIDTH;
@@ -49,6 +51,7 @@ impl ReportCol {
4951
ReportCol::SrcPort | ReportCol::DstPort => port_translation(language).to_string(),
5052
ReportCol::Proto => protocol_translation(language).to_string(),
5153
ReportCol::Service => service_translation(language).to_string(),
54+
ReportCol::Process => "Process".to_string(),
5255
ReportCol::Bytes => {
5356
let mut str = bytes_translation(language).to_string();
5457
str.remove(0).to_uppercase().to_string() + &str
@@ -92,14 +95,15 @@ impl ReportCol {
9295
}
9396
ReportCol::Proto => key.protocol.to_string(),
9497
ReportCol::Service => val.service.to_string(),
98+
ReportCol::Process => val.process.clone(),
9599
ReportCol::Bytes => ByteMultiple::formatted_string(val.transmitted_bytes),
96100
ReportCol::Packets => val.transmitted_packets.to_string(),
97101
}
98102
}
99103

100104
pub(crate) fn get_width(&self) -> f32 {
101105
match self {
102-
ReportCol::SrcIp | ReportCol::DstIp => LARGE_COL_WIDTH,
106+
ReportCol::SrcIp | ReportCol::DstIp | ReportCol::Process => LARGE_COL_WIDTH,
103107
_ => SMALL_COL_WIDTH,
104108
}
105109
}
@@ -113,7 +117,9 @@ impl ReportCol {
113117
1
114118
};
115119
match self {
116-
ReportCol::SrcIp | ReportCol::DstIp => LARGE_COL_MAX_CHARS / reduction_factor,
120+
ReportCol::SrcIp | ReportCol::DstIp | ReportCol::Process => {
121+
LARGE_COL_MAX_CHARS / reduction_factor
122+
}
117123
_ => SMALL_COL_MAX_CHARS / reduction_factor,
118124
}
119125
}
@@ -126,6 +132,7 @@ impl ReportCol {
126132
ReportCol::DstPort => FilterInputType::PortDst,
127133
ReportCol::Proto => FilterInputType::Proto,
128134
ReportCol::Service => FilterInputType::Service,
135+
ReportCol::Process => FilterInputType::Process,
129136
ReportCol::Bytes | ReportCol::Packets => FilterInputType::Country, // just to not panic...
130137
}
131138
}

src/report/types/search_parameters.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub struct SearchParameters {
1919
pub proto: String,
2020
/// Service
2121
pub service: String,
22+
/// Process
23+
pub process: String,
2224
/// Country
2325
pub country: String,
2426
/// Domain
@@ -103,19 +105,21 @@ pub enum FilterInputType {
103105
PortDst,
104106
Proto,
105107
Service,
108+
Process,
106109
Country,
107110
Domain,
108111
AsName,
109112
}
110113

111114
impl FilterInputType {
112-
pub const ALL: [FilterInputType; 9] = [
115+
pub const ALL: [FilterInputType; 10] = [
113116
Self::AddressSrc,
114117
Self::PortSrc,
115118
Self::AddressDst,
116119
Self::PortDst,
117120
Self::Proto,
118121
Self::Service,
122+
Self::Process,
119123
Self::Country,
120124
Self::Domain,
121125
Self::AsName,
@@ -151,6 +155,7 @@ impl FilterInputType {
151155
FilterInputType::PortDst => &search_params.port_dst,
152156
FilterInputType::Proto => &search_params.proto,
153157
FilterInputType::Service => &search_params.service,
158+
FilterInputType::Process => &search_params.process,
154159
FilterInputType::Country => &search_params.country,
155160
FilterInputType::Domain => &search_params.domain,
156161
FilterInputType::AsName => &search_params.as_name,
@@ -182,6 +187,7 @@ impl FilterInputType {
182187
}
183188
FilterInputType::Proto => key.protocol.to_string(),
184189
FilterInputType::Service => value.service.to_string(),
190+
FilterInputType::Process => value.process.clone(),
185191
FilterInputType::Country => r_dns_host.unwrap().1.country.to_string(),
186192
FilterInputType::Domain => r_dns_host.unwrap().0.to_string(),
187193
FilterInputType::AsName => r_dns_host.unwrap().1.asn.name.to_string(),
@@ -214,6 +220,10 @@ impl FilterInputType {
214220
service: String::new(),
215221
..search_params.clone()
216222
},
223+
FilterInputType::Process => SearchParameters {
224+
process: String::new(),
225+
..search_params.clone()
226+
},
217227
FilterInputType::Domain => SearchParameters {
218228
domain: String::new(),
219229
..search_params.clone()
@@ -259,6 +269,10 @@ impl FilterInputType {
259269
service: new_value.trim().to_string(),
260270
..search_params.clone()
261271
},
272+
FilterInputType::Process => SearchParameters {
273+
process: new_value,
274+
..search_params.clone()
275+
},
262276
FilterInputType::Domain => SearchParameters {
263277
domain: new_value.trim().to_string(),
264278
..search_params.clone()

0 commit comments

Comments
 (0)