pcap_async/
config.rs

1use std;
2
3#[derive(Clone, Debug)]
4pub struct Config {
5    max_packets_read: usize,
6    snaplen: u32,
7    buffer_size: u32,
8    bpf: Option<String>,
9    buffer_for: std::time::Duration,
10    blocking: bool,
11}
12
13impl Config {
14    pub fn max_packets_read(&self) -> usize {
15        self.max_packets_read
16    }
17
18    pub fn with_max_packets_read(&mut self, amt: usize) -> &mut Self {
19        self.max_packets_read = amt;
20        self
21    }
22
23    pub fn snaplen(&self) -> u32 {
24        self.snaplen
25    }
26
27    pub fn with_snaplen(&mut self, amt: u32) -> &mut Self {
28        self.snaplen = amt;
29        self
30    }
31
32    pub fn buffer_size(&self) -> u32 {
33        self.buffer_size
34    }
35
36    pub fn with_buffer_size(&mut self, amt: u32) -> &mut Self {
37        self.buffer_size = amt;
38        self
39    }
40
41    pub fn bpf(&self) -> &Option<String> {
42        &self.bpf
43    }
44
45    pub fn with_bpf(&mut self, amt: String) -> &mut Self {
46        self.bpf = Some(amt);
47        self
48    }
49
50    pub fn buffer_for(&self) -> &std::time::Duration {
51        &self.buffer_for
52    }
53
54    pub fn with_buffer_for(&mut self, amt: std::time::Duration) -> &mut Self {
55        self.buffer_for = amt;
56        self
57    }
58
59    pub fn blocking(&self) -> bool {
60        self.blocking
61    }
62
63    pub fn with_blocking(&mut self, blocking: bool) -> &mut Self {
64        self.blocking = blocking;
65        self
66    }
67
68    pub fn new(
69        max_packets_read: usize,
70        snaplen: u32,
71        buffer_size: u32,
72        bpf: Option<String>,
73        buffer_for: std::time::Duration,
74        blocking: bool,
75    ) -> Config {
76        Config {
77            max_packets_read,
78            snaplen,
79            buffer_size,
80            bpf,
81            buffer_for,
82            blocking,
83        }
84    }
85}
86
87impl Default for Config {
88    fn default() -> Config {
89        Config {
90            max_packets_read: 1000,
91            snaplen: 65535,
92            buffer_size: 16777216,
93            bpf: None,
94            buffer_for: std::time::Duration::from_millis(100),
95            blocking: false,
96        }
97    }
98}