fixed crash during capture

This commit is contained in:
canep
2022-08-09 20:42:23 +02:00
parent 3f1ed515f3
commit ce0ce05be5
5 changed files with 91 additions and 127 deletions

View File

@@ -1,130 +1,83 @@
-----------------------------------------------
Address: 255.255.255.255:17500
Transmitted: 0.00 B
Initial Timestamp:
Final Timestamp:
trans_protocols:
Report start time: '08/08/2022 15:09:50'
Address: 192.168.56.1:17500
Transmitted: 226.00 B
Initial Timestamp:
Final Timestamp:
trans_protocols:
Packets sniffed from adapter 'en0'
----------------------------------
Address: 255.255.255.255:17500
Transmitted: 0.00 B
Initial Timestamp:
Final Timestamp:
trans_protocols:
Considering port numbers from 0 to 65535
Address: 192.168.56.1:17500
Transmitted: 452.00 B
Initial Timestamp:
Final Timestamp:
trans_protocols:
Considering only addresses featured by more than 5 packets
----------------------------------
Address: 255.255.255.255:17500
Transmitted: 0.00 B
Initial Timestamp:
Final Timestamp:
trans_protocols:
-----------------------------------------------
Address: 192.168.56.255:17500
Transmitted: 0.00 B
Initial Timestamp:
Final Timestamp:
trans_protocols:
Address: 192.168.56.1:17500
Transmitted: 678.00 B
Initial Timestamp:
Final Timestamp:
trans_protocols:
Address: 142.250.184.86:443
Sent data
Sent Bytes: 56.43 kB
Sent packets: 46
Received data
Received Bytes: 2.17 kB
Received packets: 36
Timestamps
Initial Timestamp: 08/08/2022 15:10:06
Final Timestamp: 08/08/2022 15:10:06
Transport layer protocols: TCP
----------------------------------
Address: 255.255.255.255:17500
Transmitted: 0.00 B
Initial Timestamp:
Final Timestamp:
trans_protocols:
Address: 192.168.56.255:17500
Transmitted: 0.00 B
Initial Timestamp:
Final Timestamp:
trans_protocols:
Address: 172.20.10.1:53
Sent data
Sent Bytes: 469.00 B
Sent packets: 4
Received data
Received Bytes: 224.00 B
Received packets: 4
Timestamps
Initial Timestamp: 08/08/2022 15:10:06
Final Timestamp: 08/08/2022 15:10:06
Transport layer protocols: UDP
Address: 192.168.56.1:17500
Transmitted: 904.00 B
Initial Timestamp:
Final Timestamp:
trans_protocols:
----------------------------------
Address: 255.255.255.255:17500
Transmitted: 0.00 B
Initial Timestamp:
Final Timestamp:
trans_protocols:
Address: 224.0.0.251:5353
Sent data
Sent Bytes: 0.00 B
Sent packets: 0
Received data
Received Bytes: 3.35 kB
Received packets: 11
Timestamps
Initial Timestamp: 08/08/2022 15:10:06
Final Timestamp: 08/08/2022 15:10:06
Transport layer protocols: UDP
Address: 172.20.10.2:63137
Sent data
Sent Bytes: 2.17 kB
Sent packets: 36
Received data
Received Bytes: 56.43 kB
Received packets: 46
Timestamps
Initial Timestamp: 08/08/2022 15:10:06
Final Timestamp: 08/08/2022 15:10:06
Transport layer protocols: TCP
Address: 216.58.209.46:443
Sent data
Sent Bytes: 84.56 kB
Sent packets: 87
Received data
Received Bytes: 25.28 kB
Received packets: 84
Timestamps
Initial Timestamp: 08/08/2022 15:10:06
Final Timestamp: 08/08/2022 15:10:06
Transport layer protocols: TCP
Address: 254.128.0.0.0.0.0.0.228.154.220.255.254.156.159.100:5353
Sent data
Sent Bytes: 3.51 kB
Sent packets: 12
Received data
Received Bytes: 0.00 B
Received packets: 0
Timestamps
Initial Timestamp: 08/08/2022 15:10:06
Final Timestamp: 08/08/2022 15:10:06
Transport layer protocols: UDP
Address: 172.20.10.1:5353
Sent data
Sent Bytes: 3.35 kB
Sent packets: 11
Received data
Received Bytes: 337.00 B
Received packets: 1
Timestamps
Initial Timestamp: 08/08/2022 15:10:06
Final Timestamp: 08/08/2022 15:10:06
Transport layer protocols: UDP
Address: 172.20.10.2:63138
Sent data
Sent Bytes: 25.28 kB
Sent packets: 84
Received data
Received Bytes: 84.56 kB
Received packets: 87
Timestamps
Initial Timestamp: 08/08/2022 15:10:06
Final Timestamp: 08/08/2022 15:10:06
Transport layer protocols: TCP
Address: 255.2.0.0.0.0.0.0.0.0.0.0.0.0.0.251:5353
Sent data
Sent Bytes: 0.00 B
Sent packets: 0
Received data
Received Bytes: 3.51 kB
Received packets: 12
Timestamps
Initial Timestamp: 08/08/2022 15:10:06
Final Timestamp: 08/08/2022 15:10:06
Transport layer protocols: UDP
Address: 192.168.56.255:17500
Transmitted: 0.00 B
Initial Timestamp:
Final Timestamp:
trans_protocols:
Address: 192.168.56.1:17500
Transmitted: 1.13 kB
Initial Timestamp:
Final Timestamp:
trans_protocols:
----------------------------------

View File

@@ -3,6 +3,8 @@
use std::collections::HashMap;
use std::collections::HashSet;
use std::fmt;
use std::fmt::Formatter;
use etherparse::{IpHeader, PacketHeaders, TransportHeader};
use pcap::{Device, Capture};
use std::fs::File;
@@ -35,6 +37,13 @@ struct Args {
minimum_packets: u32,
}
// impl fmt::Display for Device {
// fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
// let mut device = String::from(format!("Device: {}\n", self.name));
//
// write!(f, "Device: {}\n\tAddresses: ")
// }
// }
fn main() {
@@ -66,6 +75,7 @@ fn main() {
}
}
if found_device.name.len() == 0 {
panic!("Specified network adapter does not exist\n");
}
}
@@ -82,7 +92,7 @@ fn main() {
let mut cap = Capture::from_device(found_device).unwrap()
.promisc(true)
.open().unwrap();
let mut map:HashMap<AddressPort,ReportInfo> = HashMap::new();
let mut num_packets = 0; //dopo 300 pacchetti interrompo la cattura e stampo
@@ -102,8 +112,8 @@ fn main() {
let exchanged_bytes: u32;
let mut protocol = TransProtocol::Other;
match value.ip.unwrap() {
IpHeader::Version4(ipv4header, _) => {
match value.ip {
Some(IpHeader::Version4(ipv4header, _)) => {
address1 = format!("{:?}", ipv4header.source)
.replace("[","")
.replace("]","")
@@ -116,7 +126,7 @@ fn main() {
.replace(" ","");
exchanged_bytes = ipv4header.payload_len as u32;
}
IpHeader::Version6(ipv6header, _) => {
Some(IpHeader::Version6(ipv6header, _)) => {
address1 = format!("{:?}", ipv6header.source)
.replace("[", "")
.replace("]", "")
@@ -129,6 +139,7 @@ fn main() {
.replace(" ", "");
exchanged_bytes = ipv6header.payload_length as u32;
}
None => {continue;}
}
match value.transport.unwrap() {
@@ -142,10 +153,10 @@ fn main() {
protocol = TransProtocol::TCP;
port2 = tcpheader.destination_port
}
TransportHeader::Icmpv4(_) => {}
TransportHeader::Icmpv6(_) => {}
TransportHeader::Icmpv4(_) => {continue;}
TransportHeader::Icmpv6(_) => {continue;}
}
let key1: AddressPort = AddressPort::new(address1,port1);
let key2: AddressPort = AddressPort::new(address2,port2);

View File

@@ -72,4 +72,4 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TransProtocol { Other, TCP, UDP, }
pub enum TransProtocol { Other, TCP, UDP, ICMP}

View File

@@ -1 +1 @@
{"rustc_fingerprint":2971462514782156308,"outputs":{"2797684049618456168":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n","stderr":""},"5309432699494263626":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n","stderr":""},"931469667778813386":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/giulianobellini/.rustup/toolchains/stable-x86_64-apple-darwin\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"ssse3\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n","stderr":""},"17598535894874457435":{"success":true,"status":"","code":0,"stdout":"rustc 1.59.0 (9d1b2106e 2022-02-23)\nbinary: rustc\ncommit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a\ncommit-date: 2022-02-23\nhost: x86_64-apple-darwin\nrelease: 1.59.0\nLLVM version: 13.0.0\n","stderr":""}},"successes":{}}
{"rustc_fingerprint":345831468887381716,"outputs":{"10376369925670944939":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\canep\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"15697416045686424142":{"success":false,"status":"exit code: 1","code":1,"stdout":"","stderr":"error: `-Csplit-debuginfo` is unstable on this platform\n\n"},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.62.1 (e092d0b6b 2022-07-16)\nbinary: rustc\ncommit-hash: e092d0b6b43f2de967af0887873151bb1c0b18d3\ncommit-date: 2022-07-16\nhost: x86_64-pc-windows-msvc\nrelease: 1.62.1\nLLVM version: 14.0.5\n","stderr":""}},"successes":{}}

View File

@@ -1 +1 @@
/Users/giulianobellini/Desktop/PoliTO/Courses/PDS/project/pdsproject/packet_sniffer/target/debug/packet_sniffer: /Users/giulianobellini/Desktop/PoliTO/Courses/PDS/project/pdsproject/packet_sniffer/src/address_port.rs /Users/giulianobellini/Desktop/PoliTO/Courses/PDS/project/pdsproject/packet_sniffer/src/main.rs /Users/giulianobellini/Desktop/PoliTO/Courses/PDS/project/pdsproject/packet_sniffer/src/report_info.rs
C:\Users\canep\CLionProjects\pdsproject\packet_sniffer\target\debug\packet_sniffer.exe: C:\Users\canep\CLionProjects\pdsproject\packet_sniffer\src\address_port.rs C:\Users\canep\CLionProjects\pdsproject\packet_sniffer\src\main.rs C:\Users\canep\CLionProjects\pdsproject\packet_sniffer\src\report_info.rs