mirror of
https://github.com/ivre/masscanned.git
synced 2025-10-02 06:38:21 +00:00
pcap-file: switch to 2.0 API
This commit is contained in:
parent
498c811323
commit
3159ecf743
1 changed files with 7 additions and 7 deletions
|
@ -5,12 +5,12 @@ use std::io::BufReader;
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||||
|
|
||||||
use log::*;
|
use log::*;
|
||||||
use pcap_file::pcap::{Packet, PcapReader};
|
use pcap_file::pcap::{PcapPacket, PcapReader};
|
||||||
use pnet::packet::{
|
use pnet::packet::{
|
||||||
ethernet::{EtherTypes, EthernetPacket},
|
ethernet::{EtherTypes, EthernetPacket},
|
||||||
ipv4::Ipv4Packet,
|
ipv4::Ipv4Packet,
|
||||||
ipv6::Ipv6Packet,
|
ipv6::Ipv6Packet,
|
||||||
Packet as Pkt,
|
Packet,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Generic IP packet (either IPv4 or IPv6) */
|
/* 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.
|
/* Get the IP address of source and dest. from an IP packet.
|
||||||
* works with both IPv4 and IPv6 packets/addresses */
|
* 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 eth = EthernetPacket::new(&pkt.data).expect("error parsing Ethernet packet");
|
||||||
let payload = eth.payload();
|
let payload = eth.payload();
|
||||||
let ip = match eth.get_ethertype() {
|
let ip = match eth.get_ethertype() {
|
||||||
|
@ -206,13 +206,13 @@ impl IpAddrParser for PcapReader<std::fs::File> {
|
||||||
/* Extract IP addresses (v4 and v6) from a capture and count occurrences of
|
/* Extract IP addresses (v4 and v6) from a capture and count occurrences of
|
||||||
* each. */
|
* each. */
|
||||||
fn extract_ip_addresses_with_count(
|
fn extract_ip_addresses_with_count(
|
||||||
self: PcapReader<std::fs::File>,
|
mut self: PcapReader<std::fs::File>,
|
||||||
blacklist: Option<HashSet<IpAddr>>,
|
blacklist: Option<HashSet<IpAddr>>,
|
||||||
) -> HashMap<IpAddr, u32> {
|
) -> HashMap<IpAddr, u32> {
|
||||||
let mut ip_addresses = HashMap::new();
|
let mut ip_addresses = HashMap::new();
|
||||||
// pcap.map(fn) , map_Ok
|
// pcap.map(fn) , map_Ok
|
||||||
// .iter, into_iter
|
// .iter, into_iter
|
||||||
for pkt in self {
|
while let Some(pkt) = self.next_packet() {
|
||||||
match pkt {
|
match pkt {
|
||||||
Ok(pkt) => {
|
Ok(pkt) => {
|
||||||
// map_Some map_None
|
// map_Some map_None
|
||||||
|
@ -246,13 +246,13 @@ impl IpAddrParser for PcapReader<std::fs::File> {
|
||||||
ip_addresses
|
ip_addresses
|
||||||
}
|
}
|
||||||
fn extract_ip_addresses_only(
|
fn extract_ip_addresses_only(
|
||||||
self: PcapReader<std::fs::File>,
|
mut self: PcapReader<std::fs::File>,
|
||||||
blacklist: Option<HashSet<IpAddr>>,
|
blacklist: Option<HashSet<IpAddr>>,
|
||||||
) -> HashSet<IpAddr> {
|
) -> HashSet<IpAddr> {
|
||||||
let mut ip_addresses = HashSet::new();
|
let mut ip_addresses = HashSet::new();
|
||||||
// pcap.map(fn) , map_Ok
|
// pcap.map(fn) , map_Ok
|
||||||
// .iter, into_iter
|
// .iter, into_iter
|
||||||
for pkt in self {
|
while let Some(pkt) = self.next_packet() {
|
||||||
match pkt {
|
match pkt {
|
||||||
Ok(pkt) => {
|
Ok(pkt) => {
|
||||||
// map_Some map_None
|
// map_Some map_None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue