mirror of
https://github.com/GyulyVGC/sniffnet.git
synced 2025-12-23 22:29:01 -05:00
remove PacketFiltersFields, don't start captures from unsupported link types
This commit is contained in:
@@ -99,7 +99,7 @@ fn page_content<'a>(sniffer: &Sniffer, key: &AddressPortPair) -> Container<'a, M
|
|||||||
let host_info = host_info_option.unwrap_or_default();
|
let host_info = host_info_option.unwrap_or_default();
|
||||||
let flag = get_flag_tooltip(host.country, &host_info, language, font, false);
|
let flag = get_flag_tooltip(host.country, &host_info, language, font, false);
|
||||||
let computer = get_local_tooltip(sniffer, &address_to_lookup, key);
|
let computer = get_local_tooltip(sniffer, &address_to_lookup, key);
|
||||||
if address_to_lookup.eq(&key.address1) {
|
if address_to_lookup.eq(&key.source) {
|
||||||
source_caption = source_caption.push(flag);
|
source_caption = source_caption.push(flag);
|
||||||
dest_caption = dest_caption.push(computer);
|
dest_caption = dest_caption.push(computer);
|
||||||
} else {
|
} else {
|
||||||
@@ -110,8 +110,8 @@ fn page_content<'a>(sniffer: &Sniffer, key: &AddressPortPair) -> Container<'a, M
|
|||||||
|
|
||||||
let mut source_col = get_src_or_dest_col(
|
let mut source_col = get_src_or_dest_col(
|
||||||
source_caption,
|
source_caption,
|
||||||
&key.address1,
|
&key.source,
|
||||||
key.port1,
|
key.sport,
|
||||||
val.mac_address1.as_ref(),
|
val.mac_address1.as_ref(),
|
||||||
font,
|
font,
|
||||||
language,
|
language,
|
||||||
@@ -119,15 +119,15 @@ fn page_content<'a>(sniffer: &Sniffer, key: &AddressPortPair) -> Container<'a, M
|
|||||||
);
|
);
|
||||||
let mut dest_col = get_src_or_dest_col(
|
let mut dest_col = get_src_or_dest_col(
|
||||||
dest_caption,
|
dest_caption,
|
||||||
&key.address2,
|
&key.dest,
|
||||||
key.port2,
|
key.dport,
|
||||||
val.mac_address2.as_ref(),
|
val.mac_address2.as_ref(),
|
||||||
font,
|
font,
|
||||||
language,
|
language,
|
||||||
&sniffer.timing_events,
|
&sniffer.timing_events,
|
||||||
);
|
);
|
||||||
|
|
||||||
if address_to_lookup.eq(&key.address1) {
|
if address_to_lookup.eq(&key.source) {
|
||||||
source_col = source_col.push(host_info_col);
|
source_col = source_col.push(host_info_col);
|
||||||
} else {
|
} else {
|
||||||
dest_col = dest_col.push(host_info_col);
|
dest_col = dest_col.push(host_info_col);
|
||||||
@@ -304,10 +304,10 @@ fn get_local_tooltip<'a>(
|
|||||||
style, language, ..
|
style, language, ..
|
||||||
} = sniffer.conf.settings;
|
} = sniffer.conf.settings;
|
||||||
|
|
||||||
let local_address = if address_to_lookup.eq(&key.address1) {
|
let local_address = if address_to_lookup.eq(&key.source) {
|
||||||
&key.address2
|
&key.dest
|
||||||
} else {
|
} else {
|
||||||
&key.address1
|
&key.source
|
||||||
};
|
};
|
||||||
let my_interface_addresses = sniffer.capture_source.get_addresses();
|
let my_interface_addresses = sniffer.capture_source.get_addresses();
|
||||||
get_computer_tooltip(
|
get_computer_tooltip(
|
||||||
@@ -315,10 +315,10 @@ fn get_local_tooltip<'a>(
|
|||||||
is_local_connection(local_address, my_interface_addresses),
|
is_local_connection(local_address, my_interface_addresses),
|
||||||
is_bogon(local_address),
|
is_bogon(local_address),
|
||||||
get_traffic_type(
|
get_traffic_type(
|
||||||
if address_to_lookup.eq(&key.address1) {
|
if address_to_lookup.eq(&key.source) {
|
||||||
&key.address2
|
&key.dest
|
||||||
} else {
|
} else {
|
||||||
&key.address1
|
&key.source
|
||||||
},
|
},
|
||||||
my_interface_addresses,
|
my_interface_addresses,
|
||||||
TrafficDirection::Outgoing,
|
TrafficDirection::Outgoing,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
use gui::styles::types::style_type::StyleType;
|
use gui::styles::types::style_type::StyleType;
|
||||||
use networking::types::data_representation::ByteMultiple;
|
use networking::types::data_representation::ByteMultiple;
|
||||||
use networking::types::info_traffic::InfoTraffic;
|
use networking::types::info_traffic::InfoTraffic;
|
||||||
use networking::types::ip_version::IpVersion;
|
|
||||||
use networking::types::protocol::Protocol;
|
use networking::types::protocol::Protocol;
|
||||||
use networking::types::service::Service;
|
use networking::types::service::Service;
|
||||||
use translations::types::language::Language;
|
use translations::types::language::Language;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
};
|
};
|
||||||
use pcap::Address;
|
use pcap::Address;
|
||||||
|
|
||||||
|
use crate::Protocol;
|
||||||
use crate::networking::types::address_port_pair::AddressPortPair;
|
use crate::networking::types::address_port_pair::AddressPortPair;
|
||||||
use crate::networking::types::arp_type::ArpType;
|
use crate::networking::types::arp_type::ArpType;
|
||||||
use crate::networking::types::bogon::is_bogon;
|
use crate::networking::types::bogon::is_bogon;
|
||||||
@@ -13,12 +14,10 @@
|
|||||||
use crate::networking::types::icmp_type::{IcmpType, IcmpTypeV4, IcmpTypeV6};
|
use crate::networking::types::icmp_type::{IcmpType, IcmpTypeV4, IcmpTypeV6};
|
||||||
use crate::networking::types::info_address_port_pair::InfoAddressPortPair;
|
use crate::networking::types::info_address_port_pair::InfoAddressPortPair;
|
||||||
use crate::networking::types::info_traffic::InfoTraffic;
|
use crate::networking::types::info_traffic::InfoTraffic;
|
||||||
use crate::networking::types::packet_filters_fields::PacketFiltersFields;
|
|
||||||
use crate::networking::types::service::Service;
|
use crate::networking::types::service::Service;
|
||||||
use crate::networking::types::service_query::ServiceQuery;
|
use crate::networking::types::service_query::ServiceQuery;
|
||||||
use crate::networking::types::traffic_direction::TrafficDirection;
|
use crate::networking::types::traffic_direction::TrafficDirection;
|
||||||
use crate::networking::types::traffic_type::TrafficType;
|
use crate::networking::types::traffic_type::TrafficType;
|
||||||
use crate::{IpVersion, Protocol};
|
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/services.rs"));
|
include!(concat!(env!("OUT_DIR"), "/services.rs"));
|
||||||
@@ -31,8 +30,9 @@ pub fn analyze_headers(
|
|||||||
exchanged_bytes: &mut u128,
|
exchanged_bytes: &mut u128,
|
||||||
icmp_type: &mut IcmpType,
|
icmp_type: &mut IcmpType,
|
||||||
arp_type: &mut ArpType,
|
arp_type: &mut ArpType,
|
||||||
packet_filters_fields: &mut PacketFiltersFields,
|
|
||||||
) -> Option<AddressPortPair> {
|
) -> Option<AddressPortPair> {
|
||||||
|
let mut retval = AddressPortPair::default();
|
||||||
|
|
||||||
analyze_link_header(
|
analyze_link_header(
|
||||||
headers.link,
|
headers.link,
|
||||||
&mut mac_addresses.0,
|
&mut mac_addresses.0,
|
||||||
@@ -45,9 +45,8 @@ pub fn analyze_headers(
|
|||||||
if !analyze_network_header(
|
if !analyze_network_header(
|
||||||
headers.net,
|
headers.net,
|
||||||
exchanged_bytes,
|
exchanged_bytes,
|
||||||
&mut packet_filters_fields.ip_version,
|
&mut retval.source,
|
||||||
&mut packet_filters_fields.source,
|
&mut retval.dest,
|
||||||
&mut packet_filters_fields.dest,
|
|
||||||
arp_type,
|
arp_type,
|
||||||
) {
|
) {
|
||||||
return None;
|
return None;
|
||||||
@@ -56,22 +55,16 @@ pub fn analyze_headers(
|
|||||||
if !is_arp
|
if !is_arp
|
||||||
&& !analyze_transport_header(
|
&& !analyze_transport_header(
|
||||||
headers.transport,
|
headers.transport,
|
||||||
&mut packet_filters_fields.sport,
|
&mut retval.sport,
|
||||||
&mut packet_filters_fields.dport,
|
&mut retval.dport,
|
||||||
&mut packet_filters_fields.protocol,
|
&mut retval.protocol,
|
||||||
icmp_type,
|
icmp_type,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(AddressPortPair::new(
|
Some(retval)
|
||||||
packet_filters_fields.source,
|
|
||||||
packet_filters_fields.sport,
|
|
||||||
packet_filters_fields.dest,
|
|
||||||
packet_filters_fields.dport,
|
|
||||||
packet_filters_fields.protocol,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function analyzes the data link layer header passed as parameter and updates variables
|
/// This function analyzes the data link layer header passed as parameter and updates variables
|
||||||
@@ -114,21 +107,18 @@ fn analyze_link_header(
|
|||||||
fn analyze_network_header(
|
fn analyze_network_header(
|
||||||
network_header: Option<NetHeaders>,
|
network_header: Option<NetHeaders>,
|
||||||
exchanged_bytes: &mut u128,
|
exchanged_bytes: &mut u128,
|
||||||
network_protocol: &mut IpVersion,
|
|
||||||
address1: &mut IpAddr,
|
address1: &mut IpAddr,
|
||||||
address2: &mut IpAddr,
|
address2: &mut IpAddr,
|
||||||
arp_type: &mut ArpType,
|
arp_type: &mut ArpType,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
match network_header {
|
match network_header {
|
||||||
Some(NetHeaders::Ipv4(ipv4header, _)) => {
|
Some(NetHeaders::Ipv4(ipv4header, _)) => {
|
||||||
*network_protocol = IpVersion::IPv4;
|
|
||||||
*address1 = IpAddr::from(ipv4header.source);
|
*address1 = IpAddr::from(ipv4header.source);
|
||||||
*address2 = IpAddr::from(ipv4header.destination);
|
*address2 = IpAddr::from(ipv4header.destination);
|
||||||
*exchanged_bytes += u128::from(ipv4header.total_len);
|
*exchanged_bytes += u128::from(ipv4header.total_len);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Some(NetHeaders::Ipv6(ipv6header, _)) => {
|
Some(NetHeaders::Ipv6(ipv6header, _)) => {
|
||||||
*network_protocol = IpVersion::IPv6;
|
|
||||||
*address1 = IpAddr::from(ipv6header.source);
|
*address1 = IpAddr::from(ipv6header.source);
|
||||||
*address2 = IpAddr::from(ipv6header.destination);
|
*address2 = IpAddr::from(ipv6header.destination);
|
||||||
*exchanged_bytes += u128::from(40 + ipv6header.payload_length);
|
*exchanged_bytes += u128::from(40 + ipv6header.payload_length);
|
||||||
@@ -137,7 +127,6 @@ fn analyze_network_header(
|
|||||||
Some(NetHeaders::Arp(arp_packet)) => {
|
Some(NetHeaders::Arp(arp_packet)) => {
|
||||||
match arp_packet.proto_addr_type {
|
match arp_packet.proto_addr_type {
|
||||||
EtherType::IPV4 => {
|
EtherType::IPV4 => {
|
||||||
*network_protocol = IpVersion::IPv4;
|
|
||||||
*address1 =
|
*address1 =
|
||||||
match TryInto::<[u8; 4]>::try_into(arp_packet.sender_protocol_addr()) {
|
match TryInto::<[u8; 4]>::try_into(arp_packet.sender_protocol_addr()) {
|
||||||
Ok(source) => IpAddr::from(source),
|
Ok(source) => IpAddr::from(source),
|
||||||
@@ -150,7 +139,6 @@ fn analyze_network_header(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
EtherType::IPV6 => {
|
EtherType::IPV6 => {
|
||||||
*network_protocol = IpVersion::IPv6;
|
|
||||||
*address1 =
|
*address1 =
|
||||||
match TryInto::<[u8; 16]>::try_into(arp_packet.sender_protocol_addr()) {
|
match TryInto::<[u8; 16]>::try_into(arp_packet.sender_protocol_addr()) {
|
||||||
Ok(source) => IpAddr::from(source),
|
Ok(source) => IpAddr::from(source),
|
||||||
@@ -222,10 +210,10 @@ pub fn get_service(
|
|||||||
return Service::NotApplicable;
|
return Service::NotApplicable;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(port1) = key.port1 else {
|
let Some(port1) = key.sport else {
|
||||||
return Service::NotApplicable;
|
return Service::NotApplicable;
|
||||||
};
|
};
|
||||||
let Some(port2) = key.port2 else {
|
let Some(port2) = key.dport else {
|
||||||
return Service::NotApplicable;
|
return Service::NotApplicable;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -249,7 +237,7 @@ pub fn get_service(
|
|||||||
.get(&ServiceQuery(port2, key.protocol))
|
.get(&ServiceQuery(port2, key.protocol))
|
||||||
.unwrap_or(&unknown);
|
.unwrap_or(&unknown);
|
||||||
|
|
||||||
let dest_ip = key.address2;
|
let dest_ip = key.dest;
|
||||||
let bonus_dest = traffic_direction.eq(&TrafficDirection::Outgoing)
|
let bonus_dest = traffic_direction.eq(&TrafficDirection::Outgoing)
|
||||||
|| dest_ip.is_multicast()
|
|| dest_ip.is_multicast()
|
||||||
|| is_broadcast_address(&dest_ip, my_interface_addresses);
|
|| is_broadcast_address(&dest_ip, my_interface_addresses);
|
||||||
@@ -282,13 +270,13 @@ pub fn modify_or_insert_in_map(
|
|||||||
|
|
||||||
let my_interface_addresses = cs.get_addresses();
|
let my_interface_addresses = cs.get_addresses();
|
||||||
// determine traffic direction
|
// determine traffic direction
|
||||||
let source_ip = &key.address1;
|
let source_ip = &key.source;
|
||||||
let destination_ip = &key.address2;
|
let destination_ip = &key.dest;
|
||||||
traffic_direction = get_traffic_direction(
|
traffic_direction = get_traffic_direction(
|
||||||
source_ip,
|
source_ip,
|
||||||
destination_ip,
|
destination_ip,
|
||||||
key.port1,
|
key.sport,
|
||||||
key.port2,
|
key.dport,
|
||||||
my_interface_addresses,
|
my_interface_addresses,
|
||||||
);
|
);
|
||||||
// determine upper layer service
|
// determine upper layer service
|
||||||
@@ -517,8 +505,8 @@ pub fn is_my_address(local_address: &IpAddr, my_interface_addresses: &Vec<Addres
|
|||||||
|
|
||||||
pub fn get_address_to_lookup(key: &AddressPortPair, traffic_direction: TrafficDirection) -> IpAddr {
|
pub fn get_address_to_lookup(key: &AddressPortPair, traffic_direction: TrafficDirection) -> IpAddr {
|
||||||
match traffic_direction {
|
match traffic_direction {
|
||||||
TrafficDirection::Outgoing => key.address2,
|
TrafficDirection::Outgoing => key.dest,
|
||||||
TrafficDirection::Incoming => key.address1,
|
TrafficDirection::Incoming => key.source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
use crate::networking::types::icmp_type::IcmpType;
|
use crate::networking::types::icmp_type::IcmpType;
|
||||||
use crate::networking::types::info_traffic::InfoTraffic;
|
use crate::networking::types::info_traffic::InfoTraffic;
|
||||||
use crate::networking::types::my_link_type::MyLinkType;
|
use crate::networking::types::my_link_type::MyLinkType;
|
||||||
use crate::networking::types::packet_filters_fields::PacketFiltersFields;
|
|
||||||
use crate::networking::types::traffic_direction::TrafficDirection;
|
use crate::networking::types::traffic_direction::TrafficDirection;
|
||||||
use crate::utils::error_logger::{ErrorLogger, Location};
|
use crate::utils::error_logger::{ErrorLogger, Location};
|
||||||
use crate::utils::formatted_strings::get_domain_from_r_dns;
|
use crate::utils::formatted_strings::get_domain_from_r_dns;
|
||||||
@@ -49,6 +48,10 @@ pub fn parse_packets(
|
|||||||
let (mut freeze_rx, mut freeze_rx_2) = freeze_rxs;
|
let (mut freeze_rx, mut freeze_rx_2) = freeze_rxs;
|
||||||
|
|
||||||
let my_link_type = capture_context.my_link_type();
|
let my_link_type = capture_context.my_link_type();
|
||||||
|
if !my_link_type.is_supported() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let (Some(cap), mut savefile) = capture_context.consume() else {
|
let (Some(cap), mut savefile) = capture_context.consume() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@@ -143,7 +146,6 @@ pub fn parse_packets(
|
|||||||
let mut mac_addresses = (None, None);
|
let mut mac_addresses = (None, None);
|
||||||
let mut icmp_type = IcmpType::default();
|
let mut icmp_type = IcmpType::default();
|
||||||
let mut arp_type = ArpType::default();
|
let mut arp_type = ArpType::default();
|
||||||
let mut packet_filters_fields = PacketFiltersFields::default();
|
|
||||||
|
|
||||||
let key_option = analyze_headers(
|
let key_option = analyze_headers(
|
||||||
headers,
|
headers,
|
||||||
@@ -151,7 +153,6 @@ pub fn parse_packets(
|
|||||||
&mut exchanged_bytes,
|
&mut exchanged_bytes,
|
||||||
&mut icmp_type,
|
&mut icmp_type,
|
||||||
&mut arp_type,
|
&mut arp_type,
|
||||||
&mut packet_filters_fields,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let Some(key) = key_option else {
|
let Some(key) = key_option else {
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
use crate::gui::types::filters::Filters;
|
use crate::gui::types::filters::Filters;
|
||||||
use crate::location;
|
use crate::location;
|
||||||
|
use crate::networking::manage_packets::analyze_headers;
|
||||||
use crate::networking::parse_packets::get_sniffable_headers;
|
use crate::networking::parse_packets::get_sniffable_headers;
|
||||||
|
use crate::networking::types::arp_type::ArpType;
|
||||||
use crate::networking::types::capture_context::{CaptureContext, CaptureSource, CaptureType};
|
use crate::networking::types::capture_context::{CaptureContext, CaptureSource, CaptureType};
|
||||||
|
use crate::networking::types::icmp_type::IcmpType;
|
||||||
use crate::networking::types::my_device::MyDevice;
|
use crate::networking::types::my_device::MyDevice;
|
||||||
use crate::networking::types::my_link_type::MyLinkType;
|
use crate::networking::types::my_link_type::MyLinkType;
|
||||||
use crate::utils::error_logger::{ErrorLogger, Location};
|
use crate::utils::error_logger::{ErrorLogger, Location};
|
||||||
@@ -42,7 +45,16 @@ pub fn traffic_preview(tx: &Sender<TrafficPreview>) {
|
|||||||
if let Ok(packet) = packet_res {
|
if let Ok(packet) = packet_res {
|
||||||
let dev_info = packet.dev_info;
|
let dev_info = packet.dev_info;
|
||||||
let my_link_type = dev_info.my_link_type;
|
let my_link_type = dev_info.my_link_type;
|
||||||
if get_sniffable_headers(&packet.data, my_link_type).is_some() {
|
if let Some(headers) = get_sniffable_headers(&packet.data, my_link_type)
|
||||||
|
&& analyze_headers(
|
||||||
|
headers,
|
||||||
|
&mut (None, None),
|
||||||
|
&mut 0,
|
||||||
|
&mut IcmpType::default(),
|
||||||
|
&mut ArpType::default(),
|
||||||
|
)
|
||||||
|
.is_some()
|
||||||
|
{
|
||||||
data.entry(dev_info.name)
|
data.entry(dev_info.name)
|
||||||
.and_modify(|p| *p += 1)
|
.and_modify(|p| *p += 1)
|
||||||
.or_insert(1);
|
.or_insert(1);
|
||||||
@@ -96,6 +108,9 @@ fn packet_stream(
|
|||||||
tx: &std::sync::mpsc::SyncSender<(Result<PacketOwned, pcap::Error>, Option<pcap::Stat>)>,
|
tx: &std::sync::mpsc::SyncSender<(Result<PacketOwned, pcap::Error>, Option<pcap::Stat>)>,
|
||||||
dev_info: &DevInfo,
|
dev_info: &DevInfo,
|
||||||
) {
|
) {
|
||||||
|
if !dev_info.my_link_type.is_supported() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
loop {
|
loop {
|
||||||
let packet_res = cap.next_packet();
|
let packet_res = cap.next_packet();
|
||||||
let packet_owned = packet_res.map(|p| PacketOwned {
|
let packet_owned = packet_res.map(|p| PacketOwned {
|
||||||
|
|||||||
@@ -1,44 +1,50 @@
|
|||||||
//! Module defining the `AddressPortPair` struct, which represents a network address:port pair.
|
//! Module defining the `AddressPortPair` struct, which represents a network address:port pair.
|
||||||
|
|
||||||
use crate::Protocol;
|
use crate::Protocol;
|
||||||
use std::net::IpAddr;
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
|
|
||||||
/// Struct representing a network address:port pair.
|
/// Struct representing a network address:port pair.
|
||||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
||||||
pub struct AddressPortPair {
|
pub struct AddressPortPair {
|
||||||
/// Network layer IPv4 or IPv6 source address.
|
/// Network layer IPv4 or IPv6 source address.
|
||||||
pub address1: IpAddr,
|
pub source: IpAddr,
|
||||||
/// Transport layer source port number (in the range 0..=65535).
|
/// Transport layer source port number (in the range 0..=65535).
|
||||||
pub port1: Option<u16>,
|
pub sport: Option<u16>,
|
||||||
/// Network layer IPv4 or IPv6 destination address.
|
/// Network layer IPv4 or IPv6 destination address.
|
||||||
pub address2: IpAddr,
|
pub dest: IpAddr,
|
||||||
/// Transport layer destination port number (in the range 0..=65535).
|
/// Transport layer destination port number (in the range 0..=65535).
|
||||||
pub port2: Option<u16>,
|
pub dport: Option<u16>,
|
||||||
/// Transport layer protocol carried through the associate address:port pair (TCP or UPD).
|
/// Transport layer protocol carried through the associate address:port pair (TCP or UPD).
|
||||||
pub protocol: Protocol,
|
pub protocol: Protocol,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
impl AddressPortPair {
|
impl AddressPortPair {
|
||||||
/// Returns a new `AddressPort` element.
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `address` - A string representing the network layer IPv4 or IPv6 address.
|
|
||||||
///
|
|
||||||
/// * `port` - An integer representing the transport layer port number (in the range 0..=65535).
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
address1: IpAddr,
|
source: IpAddr,
|
||||||
port1: Option<u16>,
|
sport: Option<u16>,
|
||||||
address2: IpAddr,
|
dest: IpAddr,
|
||||||
port2: Option<u16>,
|
dport: Option<u16>,
|
||||||
protocol: Protocol,
|
protocol: Protocol,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
AddressPortPair {
|
AddressPortPair {
|
||||||
address1,
|
source,
|
||||||
port1,
|
sport,
|
||||||
address2,
|
dest,
|
||||||
port2,
|
dport,
|
||||||
protocol,
|
protocol,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for AddressPortPair {
|
||||||
|
fn default() -> Self {
|
||||||
|
AddressPortPair {
|
||||||
|
source: IpAddr::V4(Ipv4Addr::UNSPECIFIED),
|
||||||
|
dest: IpAddr::V4(Ipv4Addr::UNSPECIFIED),
|
||||||
|
sport: None,
|
||||||
|
dport: None,
|
||||||
|
protocol: Protocol::ARP,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
use std::fmt;
|
|
||||||
|
|
||||||
/// Enum representing the possible observed values of IP protocol version.
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
||||||
pub enum IpVersion {
|
|
||||||
/// Internet Protocol version 4
|
|
||||||
IPv4,
|
|
||||||
/// Internet Protocol version 6
|
|
||||||
IPv6,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for IpVersion {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "{self:?}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,10 +13,8 @@
|
|||||||
pub mod info_address_port_pair;
|
pub mod info_address_port_pair;
|
||||||
pub mod info_traffic;
|
pub mod info_traffic;
|
||||||
pub mod ip_collection;
|
pub mod ip_collection;
|
||||||
pub mod ip_version;
|
|
||||||
pub mod my_device;
|
pub mod my_device;
|
||||||
pub mod my_link_type;
|
pub mod my_link_type;
|
||||||
pub mod packet_filters_fields;
|
|
||||||
pub mod protocol;
|
pub mod protocol;
|
||||||
pub mod service;
|
pub mod service;
|
||||||
pub mod service_query;
|
pub mod service_query;
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
use std::net::{IpAddr, Ipv6Addr};
|
|
||||||
|
|
||||||
use crate::{IpVersion, Protocol};
|
|
||||||
|
|
||||||
/// Fields extracted from a packet to determine if this packet matches the defined filters
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct PacketFiltersFields {
|
|
||||||
/// Internet Protocol version
|
|
||||||
pub ip_version: IpVersion,
|
|
||||||
/// Protocol
|
|
||||||
pub protocol: Protocol,
|
|
||||||
/// Source IP address
|
|
||||||
pub source: IpAddr,
|
|
||||||
/// Destination IP address
|
|
||||||
pub dest: IpAddr,
|
|
||||||
/// Source port
|
|
||||||
pub sport: Option<u16>,
|
|
||||||
/// Destination port
|
|
||||||
pub dport: Option<u16>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for PacketFiltersFields {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
ip_version: IpVersion::IPv4,
|
|
||||||
protocol: Protocol::ARP,
|
|
||||||
source: IpAddr::V6(Ipv6Addr::UNSPECIFIED),
|
|
||||||
dest: IpAddr::V6(Ipv6Addr::UNSPECIFIED),
|
|
||||||
sport: None,
|
|
||||||
dport: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -71,17 +71,17 @@ pub(crate) fn get_value(
|
|||||||
data_repr: DataRepr,
|
data_repr: DataRepr,
|
||||||
) -> String {
|
) -> String {
|
||||||
match self {
|
match self {
|
||||||
ReportCol::SrcIp => key.address1.to_string(),
|
ReportCol::SrcIp => key.source.to_string(),
|
||||||
ReportCol::SrcPort => {
|
ReportCol::SrcPort => {
|
||||||
if let Some(port) = key.port1 {
|
if let Some(port) = key.sport {
|
||||||
port.to_string()
|
port.to_string()
|
||||||
} else {
|
} else {
|
||||||
"-".to_string()
|
"-".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ReportCol::DstIp => key.address2.to_string(),
|
ReportCol::DstIp => key.dest.to_string(),
|
||||||
ReportCol::DstPort => {
|
ReportCol::DstPort => {
|
||||||
if let Some(port) = key.port2 {
|
if let Some(port) = key.dport {
|
||||||
port.to_string()
|
port.to_string()
|
||||||
} else {
|
} else {
|
||||||
"-".to_string()
|
"-".to_string()
|
||||||
|
|||||||
@@ -164,17 +164,17 @@ pub fn entry_value(
|
|||||||
r_dns_host: Option<&(String, Host)>,
|
r_dns_host: Option<&(String, Host)>,
|
||||||
) -> String {
|
) -> String {
|
||||||
match self {
|
match self {
|
||||||
FilterInputType::AddressSrc => key.address1.to_string(),
|
FilterInputType::AddressSrc => key.source.to_string(),
|
||||||
FilterInputType::PortSrc => {
|
FilterInputType::PortSrc => {
|
||||||
if let Some(port) = key.port1 {
|
if let Some(port) = key.sport {
|
||||||
port.to_string()
|
port.to_string()
|
||||||
} else {
|
} else {
|
||||||
"-".to_string()
|
"-".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FilterInputType::AddressDst => key.address2.to_string(),
|
FilterInputType::AddressDst => key.dest.to_string(),
|
||||||
FilterInputType::PortDst => {
|
FilterInputType::PortDst => {
|
||||||
if let Some(port) = key.port2 {
|
if let Some(port) = key.dport {
|
||||||
port.to_string()
|
port.to_string()
|
||||||
} else {
|
} else {
|
||||||
"-".to_string()
|
"-".to_string()
|
||||||
|
|||||||
Reference in New Issue
Block a user