From 3159ecf743255c51e26c79ee1e87c41a03faf8be Mon Sep 17 00:00:00 2001 From: Pierre Lalet Date: Tue, 14 Feb 2023 00:16:46 +0100 Subject: [PATCH] pcap-file: switch to 2.0 API --- src/utils/parsers.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils/parsers.rs b/src/utils/parsers.rs index 6198c7d..e2a9ac7 100644 --- a/src/utils/parsers.rs +++ b/src/utils/parsers.rs @@ -5,12 +5,12 @@ use std::io::BufReader; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use log::*; -use pcap_file::pcap::{Packet, PcapReader}; +use pcap_file::pcap::{PcapPacket, PcapReader}; use pnet::packet::{ ethernet::{EtherTypes, EthernetPacket}, ipv4::Ipv4Packet, ipv6::Ipv6Packet, - Packet as Pkt, + Packet, }; /* Generic IP packet (either IPv4 or IPv6) */ @@ -173,7 +173,7 @@ impl IpAddrParser for &str { } /* Get the IP address of source and dest. from an IP packet. * works with both IPv4 and IPv6 packets/addresses */ -fn extract_ip(pkt: Packet) -> Option<(IpAddr, IpAddr)> { +fn extract_ip(pkt: PcapPacket) -> Option<(IpAddr, IpAddr)> { let eth = EthernetPacket::new(&pkt.data).expect("error parsing Ethernet packet"); let payload = eth.payload(); let ip = match eth.get_ethertype() { @@ -206,13 +206,13 @@ impl IpAddrParser for PcapReader { /* Extract IP addresses (v4 and v6) from a capture and count occurrences of * each. */ fn extract_ip_addresses_with_count( - self: PcapReader, + mut self: PcapReader, blacklist: Option>, ) -> HashMap { let mut ip_addresses = HashMap::new(); // pcap.map(fn) , map_Ok // .iter, into_iter - for pkt in self { + while let Some(pkt) = self.next_packet() { match pkt { Ok(pkt) => { // map_Some map_None @@ -246,13 +246,13 @@ impl IpAddrParser for PcapReader { ip_addresses } fn extract_ip_addresses_only( - self: PcapReader, + mut self: PcapReader, blacklist: Option>, ) -> HashSet { let mut ip_addresses = HashSet::new(); // pcap.map(fn) , map_Ok // .iter, into_iter - for pkt in self { + while let Some(pkt) = self.next_packet() { match pkt { Ok(pkt) => { // map_Some map_None