1mod capture;
2pub mod listener;
3
4use crate::packet::ethernet::EtherType;
5use crate::packet::ip::IpNextLevelProtocol;
6use std::collections::HashSet;
7use std::net::IpAddr;
8use std::time::Duration;
9
10#[derive(Clone, Debug)]
12pub struct PacketCaptureOptions {
13 pub interface_index: u32,
15 pub interface_name: String,
17 pub src_ips: HashSet<IpAddr>,
19 pub dst_ips: HashSet<IpAddr>,
21 pub src_ports: HashSet<u16>,
23 pub dst_ports: HashSet<u16>,
25 pub ether_types: HashSet<EtherType>,
27 pub ip_protocols: HashSet<IpNextLevelProtocol>,
29 pub duration: Duration,
31 pub read_timeout: Duration,
33 pub promiscuous: bool,
35 pub store: bool,
37 pub store_limit: u32,
39 pub receive_undefined: bool,
41 pub use_tun: bool,
43 pub loopback: bool,
45}
46
47impl PacketCaptureOptions {
48 pub fn new() -> PacketCaptureOptions {
50 PacketCaptureOptions {
51 interface_index: 0,
52 interface_name: String::new(),
53 src_ips: HashSet::new(),
54 dst_ips: HashSet::new(),
55 src_ports: HashSet::new(),
56 dst_ports: HashSet::new(),
57 ether_types: HashSet::new(),
58 ip_protocols: HashSet::new(),
59 duration: Duration::from_secs(30),
60 read_timeout: Duration::from_secs(2),
61 promiscuous: false,
62 store: false,
63 store_limit: u32::MAX,
64 receive_undefined: false,
65 use_tun: false,
66 loopback: false,
67 }
68 }
69 pub fn with_interface_index(mut self, interface_index: u32) -> PacketCaptureOptions {
71 self.interface_index = interface_index;
72 self
73 }
74 pub fn set_src_ips(&mut self, ips: Vec<IpAddr>) {
76 for ip in ips {
77 self.src_ips.insert(ip);
78 }
79 }
80 pub fn set_dst_ips(&mut self, ips: Vec<IpAddr>) {
82 for ip in ips {
83 self.dst_ips.insert(ip);
84 }
85 }
86 pub fn set_src_ports(&mut self, ports: Vec<u16>) {
88 for port in ports {
89 self.src_ports.insert(port);
90 }
91 }
92 pub fn set_dst_ports(&mut self, ports: Vec<u16>) {
94 for port in ports {
95 self.dst_ports.insert(port);
96 }
97 }
98 pub fn set_ether_types(&mut self, ether_types: Vec<EtherType>) {
100 for ether_type in ether_types {
101 self.ether_types.insert(ether_type);
102 }
103 }
104 pub fn set_ip_protocols(&mut self, ip_protocols: Vec<IpNextLevelProtocol>) {
106 for ip_protocol in ip_protocols {
107 self.ip_protocols.insert(ip_protocol);
108 }
109 }
110}