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

@ -60,6 +60,12 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "arrayvec"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"
@ -145,6 +151,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "etherparse"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21696e6dfe1057a166a042c6d27b89a46aad2ee1003e6e1e03c49d54fd3270d7"
dependencies = [
"arrayvec",
]
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.5.0" version = "0.5.0"
@ -199,6 +214,7 @@ name = "pcap_analyzer"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap", "clap",
"etherparse",
"pcap", "pcap",
] ]

View file

@ -5,4 +5,5 @@ edition = "2021"
[dependencies] [dependencies]
clap = { version = "4.5.7", features = ["derive"] } clap = { version = "4.5.7", features = ["derive"] }
etherparse = "0.15.0"
pcap = "2.0.0" pcap = "2.0.0"

View file

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

View file

@ -1,5 +1,16 @@
#!/bin/sh #!/bin/sh
set -e
cd "$(dirname "$(realpath "$0")")"
echo "checks compile"
cd pcap_analyzer
cargo build
cd ..
echo "pushing"
git add .
git commit -m "dm secu"
git push
git add .
git commit -m "dm secu"
git push