This commit is contained in:
JOLIMAITRE Matthieu 2024-06-21 03:06:51 +02:00
parent 08933e3529
commit 303c31a179
4 changed files with 35 additions and 6 deletions

View file

@ -1,6 +1,7 @@
use std::{error::Error, path::PathBuf};
use clap::{Parser, Subcommand};
use etherparse::{NetSlice, SlicedPacket};
use pcap::Capture;
fn main() -> Result<(), Box<dyn Error>> {
@ -20,11 +21,11 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut total_ipv4 = 0;
let mut total = 0;
while let Ok(packet) = pcap.next_packet() {
total += 1;
let ether_type = &packet.data[20..][..2];
if ether_type == [0x00, 0x08] {
let packet = SlicedPacket::from_ethernet(packet.data)?;
if let Some(NetSlice::Ipv4(_)) = packet.net {
total_ipv4 += 1;
}
total += 1;
}
println!("Count: {total: >9}");
println!("Count IPv4: {total_ipv4: >9}");